Skip to content
This repository was archived by the owner on Jul 6, 2018. It is now read-only.

added env vars as parameters #14 #15

Merged
merged 2 commits into from
Dec 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ machine 'wario' do
:tag => '14.04'
},
:command => '/usr/sbin/sshd -p 8022 -D',

#ENV (Environment Variables)
#Set any env var in the container by using one or more -e flags, even overriding those already defined by the developer with a Dockerfile ENV
:arg => {
"deep"=>'purple',
"led"=>'zeppelin'
}

# Ports can be one of two forms:
# src_port (string or integer) is a pass-through, i.e 8022 or "9933"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DockerContainerMachine < Chef::Provisioning::Machine::UnixMachine
# :ports => a list of port numbers to listen on
def initialize(machine_spec, transport, convergence_strategy, opts = {})
super(machine_spec, transport, convergence_strategy)
@env = opts[:env]
@command = opts[:command]
@ports = opts[:ports]
@keep_stdin_open = opts[:keep_stdin_open]
Expand All @@ -26,7 +27,7 @@ def converge(action_handler)
super action_handler
if @command
Chef::Log.debug("DockerContainerMachine converge complete, executing #{@command} in #{@container_name}")
@transport.execute(@command, :detached => true, :read_only => true, :ports => @ports, :keep_stdin_open => @keep_stdin_open)
@transport.execute(@command, :env=>@env ,:detached => true, :read_only => true, :ports => @ports, :keep_stdin_open => @keep_stdin_open)
end
end

Expand Down
8 changes: 8 additions & 0 deletions lib/chef/provisioning/docker_driver/docker_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def initialize(container_name, base_image_name, credentials, connection, tunnel_

# Execute the specified command inside the container, returns a Mixlib::Shellout object
# Options contains the optional keys:
# :env => env vars
# :read_only => Do not commit this execute operation, just execute it
# :ports => ports to listen on (-p command-line options)
# :detached => true/false, execute this command in detached mode (for final program to run)
Expand Down Expand Up @@ -62,6 +63,13 @@ def execute(command, options={})

args = ['docker', 'run', '--name', container_name]

if options[:env]
options[:env].each do |key, value|
args << '-e'
args << "#{key}=#{value}"
end
end

if options[:detached]
args << '--detach'
end
Expand Down
1 change: 1 addition & 0 deletions lib/chef/provisioning/docker_driver/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def machine_for(machine_spec, machine_options, base_image_name)
transport,
convergence_strategy,
:command => docker_options[:command],
:env => docker_options[:env],
:ports => [].push(docker_options[:ports]).flatten,
:keep_stdin_open => docker_options[:keep_stdin_open]
)
Expand Down