Class: VagrantPlugins::DockerProvider::Action::Create
- Inherits:
-
Object
- Object
- VagrantPlugins::DockerProvider::Action::Create
- Defined in:
- lib/docker-provider/action/create.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #create_params ⇒ Object
- #forwarded_ports ⇒ Object
-
#initialize(app, env) ⇒ Create
constructor
A new instance of Create.
- #synced_folders ⇒ Object
Constructor Details
#initialize(app, env) ⇒ Create
Returns a new instance of Create.
5 6 7 8 |
# File 'lib/docker-provider/action/create.rb', line 5 def initialize(app, env) @app = app @@mutex ||= Mutex.new end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/docker-provider/action/create.rb', line 10 def call(env) @env = env @machine = env[:machine] @provider_config = @machine.provider_config @machine_config = @machine.config @driver = @machine.provider.driver cid = '' @@mutex.synchronize do cid = @driver.create(create_params) end @machine.id = cid @app.call(env) end |
#create_params ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/docker-provider/action/create.rb', line 26 def create_params container_name = "#{@env[:root_path].basename.to_s}_#{@machine.name}" container_name.gsub!(/[^-a-z0-9_]/i, "") container_name << "_#{Time.now.to_i}" { image: @provider_config.image, cmd: @provider_config.cmd, ports: forwarded_ports, name: container_name, hostname: @machine_config.vm.hostname, volumes: synced_folders } end |
#forwarded_ports ⇒ Object
41 42 43 44 45 46 |
# File 'lib/docker-provider/action/create.rb', line 41 def forwarded_ports @env[:forwarded_ports].map do |fp| # TODO: Support for the protocol argument "#{fp[:host]}:#{fp[:guest]}" end.compact end |
#synced_folders ⇒ Object
48 49 50 51 52 |
# File 'lib/docker-provider/action/create.rb', line 48 def synced_folders @env[:synced_folders].map do |sf| "#{sf[:hostpath]}:#{sf[:guestpath]}" end.compact end |