chef-metal-docker 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9f887c370b4d9532f2b54d32bf4f83ba3007185
4
- data.tar.gz: 27e57e757b0a975d2e2878dcc621d62bdd0b8339
3
+ metadata.gz: 4b983e22ca453eba535c0495dcb470afa90542ac
4
+ data.tar.gz: ee1a76530f5ca78bc6c658d652870e28eacf0e6b
5
5
  SHA512:
6
- metadata.gz: cab7c6159f5d8e0a18084c0e99481d2047bc534b0f992e64fbc22e01c36867891528fac32322aa753b8f4da855511e8c359c8bbb416cc0a4d5cbe2de31b5c6cc
7
- data.tar.gz: 718f8274204319a35cbd98c6db40ecb72e22262bbde99d4fd797618421ff2cae9e62c9dadca50c0b5ccdde9a24fbe77e2c80cbb94f53542a6d31474c921520fc
6
+ metadata.gz: d69ce866e7dbc2ce028e08a54f285d775bef06a37fd1ead888437bd2bdc880a9648eca262357b2000e4fb98639558848e05d08c38a21f15b1c009ab3214a784d
7
+ data.tar.gz: ddaf05a36de3aa025b439ff32fda70d2e34ee1edccf6bb6ef1eddadc477071175cb907420bc77b651774ca407c650118b90fa8eba7ac74b1eaff0896dd06effe
data/README.md CHANGED
@@ -18,7 +18,7 @@ Using this driver, you can then define a machine similar to the following exampl
18
18
  require 'chef_metal_docker'
19
19
 
20
20
  machine 'wario' do
21
- recipe 'apache'
21
+ recipe 'openssh::default'
22
22
 
23
23
  machine_options :docker_options => {
24
24
  :base_image => {
@@ -26,7 +26,22 @@ machine 'wario' do
26
26
  :repository => 'ubuntu',
27
27
  :tag => '14.04'
28
28
  },
29
- :command => '/usr/sbin/httpd'
29
+ :command => '/usr/sbin/sshd -p 8022 -D',
30
+
31
+ # Ports can be one of two forms:
32
+ # src_port (string or integer) is a pass-through, i.e 8022 or "9933"
33
+ # src:dst (string) is a map from src to dst, i.e "8022:8023" maps 8022 externally to 8023 in the container
34
+
35
+ # Example (multiple):
36
+ :ports => [8022, "8023:9000", "9500"]
37
+
38
+ # Examples (single):
39
+ :ports => 1234
40
+ :ports => "2345:6789"
41
+
42
+ # if you need to keep stdin open (i.e docker run -i)
43
+ # :keep_stdin_open => true
44
+
30
45
  }
31
46
  end
32
47
  ```
@@ -3,9 +3,15 @@ require 'chef_metal/machine/unix_machine'
3
3
  module ChefMetalDocker
4
4
  class DockerContainerMachine < ChefMetal::Machine::UnixMachine
5
5
 
6
- def initialize(machine_spec, transport, convergence_strategy, command)
6
+ # Expects a machine specification, a usable transport and convergence strategy
7
+ # Options is expected to contain the optional keys
8
+ # :command => the final command to execute
9
+ # :ports => a list of port numbers to listen on
10
+ def initialize(machine_spec, transport, convergence_strategy, opts = {})
7
11
  super(machine_spec, transport, convergence_strategy)
8
- @command = command
12
+ @command = opts[:command]
13
+ @ports = opts[:ports]
14
+ @keep_stdin_open = opts[:keep_stdin_open]
9
15
  @container_name = machine_spec.location['container_name']
10
16
  @transport = transport
11
17
  end
@@ -18,7 +24,7 @@ module ChefMetalDocker
18
24
  super action_handler
19
25
  if @command
20
26
  Chef::Log.debug("DockerContainerMachine converge complete, executing #{@command} in #{@container_name}")
21
- @transport.execute(@command, :detached => true, :read_only => true)
27
+ @transport.execute(@command, :detached => true, :read_only => true, :ports => @ports, :keep_stdin_open => @keep_stdin_open)
22
28
  end
23
29
  end
24
30
 
@@ -223,7 +223,9 @@ module ChefMetalDocker
223
223
  machine_spec,
224
224
  transport,
225
225
  convergence_strategy,
226
- docker_options[:command]
226
+ :command => docker_options[:command],
227
+ :ports => [].push(docker_options[:ports]).flatten,
228
+ :keep_stdin_open => docker_options[:keep_stdin_open]
227
229
  )
228
230
  end
229
231
 
@@ -4,7 +4,6 @@ require 'archive/tar/minitar'
4
4
  require 'shellwords'
5
5
  require 'uri'
6
6
  require 'socket'
7
- require 'em-proxy'
8
7
  require 'mixlib/shellout'
9
8
  require 'sys/proctable'
10
9
  require 'chef_metal_docker/chef_zero_http_proxy'
@@ -29,6 +28,11 @@ module ChefMetalDocker
29
28
  attr_reader :connection
30
29
  attr_reader :tunnel_transport
31
30
 
31
+ # Execute the specified command inside the container, returns a Mixlib::Shellout object
32
+ # Options contains the optional keys:
33
+ # :read_only => Do not commit this execute operation, just execute it
34
+ # :ports => ports to listen on (-p command-line options)
35
+ # :detached => true/false, execute this command in detached mode (for final program to run)
32
36
  def execute(command, options={})
33
37
  Chef::Log.debug("execute '#{command}' with options #{options}")
34
38
 
@@ -39,6 +43,7 @@ module ChefMetalDocker
39
43
  Chef::Log.debug("Already stopped #{container_name}")
40
44
  rescue Docker::Error::NotFoundError
41
45
  end
46
+
42
47
  begin
43
48
  # Delete the container if it exists and is dormant
44
49
  connection.delete("/containers/#{container_name}?v=true&force=true")
@@ -54,19 +59,37 @@ module ChefMetalDocker
54
59
  live_stream = options[:stream_stdout] if options[:stream_stdout]
55
60
 
56
61
  args = ['docker', 'run', '--name', container_name]
57
- if options[:detached]
62
+
63
+ if options[:detached]
58
64
  args << '--detach'
59
65
  end
66
+
67
+ if options[:ports]
68
+ options[:ports].each do |portnum|
69
+ args << '-p'
70
+ args << "#{portnum}"
71
+ end
72
+ end
73
+
74
+ if options[:keep_stdin_open]
75
+ args << '-i'
76
+ end
77
+
60
78
  args << @image.id
61
79
  args += command
62
- cmdstr = Shellwords.join(args)
80
+
81
+ cmdstr = Shellwords.join(args)
63
82
  Chef::Log.debug("Executing #{cmdstr}")
64
83
 
84
+ # Remove this when https://github.com/opscode/chef/pull/2100 gets merged and released
85
+ # nullify live_stream because at the moment EventsOutputStream doesn't understand <<, which
86
+ # ShellOut uses
87
+ live_stream = nil unless live_stream.respond_to? :<<
88
+
65
89
  cmd = Mixlib::ShellOut.new(cmdstr, :live_stream => live_stream, :timeout => execute_timeout(options))
66
90
 
67
91
  cmd.run_command
68
92
 
69
-
70
93
  unless options[:read_only]
71
94
  Chef::Log.debug("Committing #{container_name} as #{repository_name}:#{container_name}")
72
95
  container = Docker::Container.get(container_name)
@@ -74,6 +97,7 @@ module ChefMetalDocker
74
97
  end
75
98
 
76
99
  Chef::Log.debug("Execute complete: status #{cmd.exitstatus}")
100
+
77
101
  cmd
78
102
  end
79
103
 
@@ -212,10 +236,6 @@ module ChefMetalDocker
212
236
  )
213
237
  end
214
238
 
215
- def wait_for_attach(excon, datum)
216
- Excon::Response.new(excon.send(:response, datum)[:response])
217
- end
218
-
219
239
  # Method that takes chunks and calls the attached block for each mux'd message
220
240
  def attach_for(block, msg_stack)
221
241
  messages = Docker::Messages.new
@@ -1,3 +1,3 @@
1
1
  module ChefMetalDocker
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-metal-docker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Duffield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-23 00:00:00.000000000 Z
11
+ date: 2014-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: em-proxy
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: sys-proctable
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -116,16 +102,16 @@ extra_rdoc_files:
116
102
  - README.md
117
103
  - LICENSE
118
104
  files:
119
- - Rakefile
120
105
  - LICENSE
121
106
  - README.md
107
+ - Rakefile
122
108
  - lib/chef_metal/driver_init/docker.rb
109
+ - lib/chef_metal_docker.rb
123
110
  - lib/chef_metal_docker/chef_zero_http_proxy.rb
124
111
  - lib/chef_metal_docker/docker_container_machine.rb
125
112
  - lib/chef_metal_docker/docker_driver.rb
126
113
  - lib/chef_metal_docker/docker_transport.rb
127
114
  - lib/chef_metal_docker/version.rb
128
- - lib/chef_metal_docker.rb
129
115
  homepage: https://github.com/opscode/chef-metal-docker
130
116
  licenses: []
131
117
  metadata: {}
@@ -145,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
131
  version: '0'
146
132
  requirements: []
147
133
  rubyforge_project:
148
- rubygems_version: 2.0.14
134
+ rubygems_version: 2.2.2
149
135
  signing_key:
150
136
  specification_version: 4
151
137
  summary: Provisioner for creating Docker containers in Chef Metal.