Class: Chef::Provisioning::DockerDriver::DockerContainerMachine

Inherits:
Machine::UnixMachine
  • Object
show all
Defined in:
lib/chef/provisioning/docker_driver/docker_container_machine.rb

Instance Method Summary collapse

Constructor Details

#initialize(machine_spec, transport, convergence_strategy, opts = {}) ⇒ DockerContainerMachine

Expects a machine specification, a usable transport and convergence strategy Options is expected to contain the optional keys

:command => the final command to execute
:ports => a list of port numbers to listen on


12
13
14
15
16
17
18
19
20
21
# File 'lib/chef/provisioning/docker_driver/docker_container_machine.rb', line 12

def initialize(machine_spec, transport, convergence_strategy, opts = {})
  super(machine_spec, transport, convergence_strategy)
  @env = opts[:env]
  @command = opts[:command]
  @ports = opts[:ports]
  @volumes = opts[:volumes]
  @keep_stdin_open = opts[:keep_stdin_open]
  @container_name = machine_spec.location['container_name']
  @transport = transport
end

Instance Method Details

#converge(action_handler) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/chef/provisioning/docker_driver/docker_container_machine.rb', line 27

def converge(action_handler)
  super action_handler
  if @command
    Chef::Log.debug("DockerContainerMachine converge complete, executing #{@command} in #{@container_name}")
    @transport.execute(@command, :env => @env ,:detached => true, :read_only => true, :ports => @ports, :volumes => @volumes, :keep_stdin_open => @keep_stdin_open)
  end
end

#execute_always(command, options = {}) ⇒ Object



23
24
25
# File 'lib/chef/provisioning/docker_driver/docker_container_machine.rb', line 23

def execute_always(command, options = {})
  transport.execute(command, { :read_only => true }.merge(options))
end