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, connection, command = nil) ⇒ 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


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

def initialize(machine_spec, transport, convergence_strategy, connection, command = nil)
  super(machine_spec, transport, convergence_strategy)
  @command = command
  @transport = transport
  @connection = connection
end

Instance Method Details

#converge(action_handler) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/chef/provisioning/docker_driver/docker_container_machine.rb', line 34

def converge(action_handler)
  # First, grab and start the converge container if it's there ...
  transport.container = converge_container_for(machine_spec)
  if !transport.container
    raise "No converge container found! Did you run `:converge` without first running `:setup`?"
  end
  unless transport.container.info['State']['Running']
    action_handler.perform_action "start converge container chef-converge.#{machine_spec.name}" do
      transport.container.start!
    end
  end

  # Then, converge ...
  super(action_handler)

  # Save the converged image ...
  converged_image = commit_converged_image(action_handler, machine_spec, transport.container)

  # Build the new container
  transport.container = create_container(action_handler, machine_spec, converged_image)

  # Finally, start it!
  action_handler.perform_action "start container #{machine_spec.name}" do
    transport.container.start!
  end
end

#setup_convergence(action_handler) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/chef/provisioning/docker_driver/docker_container_machine.rb', line 20

def setup_convergence(action_handler)
  # Build a converge container to converge in
  transport.container = build_converge_container(action_handler)
  unless transport.container.info['State']['Running']
    action_handler.perform_action "start converge container chef-converge.#{machine_spec.name}" do
      transport.container.start!
    end
  end
  super(action_handler)
  # Commit after convergence setup (such as the install of Chef)
  # to break up the cost of the commit and avoid read timeouts
  transport.container.commit
end