kitchen-dokken 1.0.10 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f110f9d52d458fff35dd7f3d0c515ca5b3128fa7
4
- data.tar.gz: 67fbebd7410fffc444180312308cda484f027512
3
+ metadata.gz: 707daf8c414917ae605188884d923058053f9f4b
4
+ data.tar.gz: ea40c4ea169ff72a5bcf34f067e52d3a4df32728
5
5
  SHA512:
6
- metadata.gz: 59c1c136f059c9cd39fe37a56e4773fb2b1f9978f0aed49db075c2431383d847ec6c1ddec8d77a00af4d9c1d8eb2c5bd97778d3dcdee6acc6e4c941c4817e575
7
- data.tar.gz: a113e255970de1a1f4d0bf0a182e7c90652d1737bfb35d4446d9ae00a7220c2e4039e50ce42180c339bb91ecba732b4d198d719663b9a2128779038aba175922
6
+ metadata.gz: d486fddd26b5ffc192155f8b5202992fd2b7b39c3a4fcc4cfa5d5dd76d02ad61d969a38c59446f217cc33fe8948ee9c07b687639b6553e452b1ee68751fa6c82
7
+ data.tar.gz: 3c967d89c1e5b4829bf3d46e3e649cdce5be514e373b5522e8518cc8ef556cf8ad0aabb4f46be3345fb2d45dee01fdb1c1007a8599253f5025176346357370b9
@@ -37,7 +37,7 @@ module Kitchen
37
37
  default_config :chef_image, 'chef/chef'
38
38
  default_config :chef_version, 'latest'
39
39
  default_config :data_image, 'someara/kitchen-cache:latest'
40
- default_config :docker_host_url, ENV['DOCKER_HOST'] || 'unix:///var/run/docker.sock'
40
+ default_config :docker_host_url, default_docker_host
41
41
  default_config :dns, nil
42
42
  default_config :dns_search, nil
43
43
  default_config :read_timeout, 3600
@@ -99,8 +99,8 @@ module Kitchen
99
99
  end
100
100
 
101
101
  def delete_work_image
102
- return unless ::Docker::Image.exist?(work_image, docker_connection)
103
- with_retries { @work_image = ::Docker::Image.get(work_image, docker_connection) }
102
+ return unless ::Docker::Image.exist?(work_image, {}, docker_connection)
103
+ with_retries { @work_image = ::Docker::Image.get(work_image, {}, docker_connection) }
104
104
 
105
105
  begin
106
106
  with_retries { @work_image.remove(force: true) }
@@ -112,28 +112,24 @@ module Kitchen
112
112
  def build_work_image(state)
113
113
  # require 'pry' ; binding.pry
114
114
 
115
- return if ::Docker::Image.exist?(work_image, docker_connection)
116
-
117
- Dir.mktmpdir do |context_root|
118
- File.write("#{context_root}/Dockerfile", work_image_dockerfile)
119
- begin
120
- with_retries do
121
- @intermediate_image = ::Docker::Image.build_from_dir(
122
- context_root,
123
- {
124
- # 'nocache' => true,
125
- # 'forcerm' => true,
126
- # 'q' => true,
127
- 't' => work_image
128
- },
129
- docker_connection
130
- )
131
- end
132
- rescue Exception => e
133
- raise "work_image build failed: #{e}"
134
- end
135
- state[:work_image] = work_image
115
+ return if ::Docker::Image.exist?(work_image, {}, docker_connection)
116
+
117
+ begin
118
+ @intermediate_image = ::Docker::Image.build(
119
+ work_image_dockerfile,
120
+ {
121
+ # 'nocache' => true,
122
+ # 'forcerm' => true,
123
+ # 'q' => true,
124
+ 't' => work_image
125
+ },
126
+ docker_connection
127
+ )
128
+ rescue Exception => e
129
+ raise "work_image build failed: #{e}"
136
130
  end
131
+
132
+ state[:work_image] = work_image
137
133
  end
138
134
 
139
135
  def work_image_dockerfile
@@ -223,8 +219,10 @@ module Kitchen
223
219
  data_container = run_container(
224
220
  'name' => data_container_name,
225
221
  'Image' => "#{repo(data_image)}:#{tag(data_image)}",
226
- 'PortBindings' => port_forwards({}, '22'),
227
- 'PublishAllPorts' => true
222
+ 'HostConfig' => {
223
+ 'PortBindings' => port_forwards({}, '22'),
224
+ 'PublishAllPorts' => true
225
+ }
228
226
  )
229
227
  # require 'pry' ; binding.pry
230
228
  state[:data_container] = data_container.json
@@ -239,7 +237,7 @@ module Kitchen
239
237
  end
240
238
 
241
239
  def create_chef_container(state)
242
- c = ::Docker::Container.get(chef_container_name)
240
+ c = ::Docker::Container.get(chef_container_name, {}, docker_connection)
243
241
  rescue ::Docker::Error::NotFoundError
244
242
  begin
245
243
  debug "driver - creating volume container #{chef_container_name} from #{chef_image}"
@@ -265,14 +263,14 @@ module Kitchen
265
263
  end
266
264
 
267
265
  def delete_image(name)
268
- with_retries { @image = ::Docker::Image.get(name, docker_connection) }
266
+ with_retries { @image = ::Docker::Image.get(name, {}, docker_connection) }
269
267
  with_retries { @image.remove(force: true) }
270
268
  rescue ::Docker::Error => e
271
269
  puts "Image #{name} not found. Nothing to delete."
272
270
  end
273
271
 
274
272
  def container_exist?(name)
275
- return true if ::Docker::Container.get(name)
273
+ return true if ::Docker::Container.get(name, {}, docker_connection)
276
274
  rescue
277
275
  false
278
276
  end
@@ -284,17 +282,17 @@ module Kitchen
284
282
  def create_container(args)
285
283
  with_retries do
286
284
  @container = ::Docker::Container.create(args.clone, docker_connection)
287
- @container = ::Docker::Container.get(args['name'])
285
+ @container = ::Docker::Container.get(args['name'], {}, docker_connection)
288
286
  end
289
287
  rescue ::Docker::Error::ConflictError
290
- with_retries { @container = ::Docker::Container.get(args['name']) }
288
+ with_retries { @container = ::Docker::Container.get(args['name'], {}, docker_connection) }
291
289
  end
292
290
 
293
291
  def run_container(args)
294
292
  create_container(args)
295
293
  with_retries do
296
294
  @container.start
297
- @container = ::Docker::Container.get(args['name'])
295
+ @container = ::Docker::Container.get(args['name'], {}, docker_connection)
298
296
  wait_running_state(args['name'], true)
299
297
  end
300
298
  @container
@@ -305,7 +303,7 @@ module Kitchen
305
303
  end
306
304
 
307
305
  def stop_container(name)
308
- with_retries { @container = ::Docker::Container.get(name, docker_connection) }
306
+ with_retries { @container = ::Docker::Container.get(name, {}, docker_connection) }
309
307
  with_retries do
310
308
  @container.stop(force: true)
311
309
  wait_running_state(name, false)
@@ -315,21 +313,21 @@ module Kitchen
315
313
  end
316
314
 
317
315
  def delete_container(name)
318
- with_retries { @container = ::Docker::Container.get(name, docker_connection) }
316
+ with_retries { @container = ::Docker::Container.get(name, {}, docker_connection) }
319
317
  with_retries { @container.delete(force: true, v: true) }
320
318
  rescue ::Docker::Error::NotFoundError
321
319
  debug "Container #{name} not found. Nothing to delete."
322
320
  end
323
321
 
324
322
  def wait_running_state(name, v)
325
- @container = ::Docker::Container.get(name)
323
+ @container = ::Docker::Container.get(name, {}, docker_connection)
326
324
  i = 0
327
325
  tries = 20
328
326
  until container_state['Running'] == v || container_state['FinishedAt'] != '0001-01-01T00:00:00Z'
329
327
  i += 1
330
328
  break if i == tries
331
329
  sleep 0.1
332
- @container = ::Docker::Container.get(name)
330
+ @container = ::Docker::Container.get(name, {}, docker_connection)
333
331
  end
334
332
  end
335
333
 
@@ -380,13 +378,13 @@ module Kitchen
380
378
  end
381
379
 
382
380
  def pull_if_missing(image)
383
- return if ::Docker::Image.exist?("#{repo(image)}:#{tag(image)}", docker_connection)
381
+ return if ::Docker::Image.exist?("#{repo(image)}:#{tag(image)}", {}, docker_connection)
384
382
  pull_image image
385
383
  end
386
384
 
387
385
  def pull_image(image)
388
386
  with_retries do
389
- ::Docker::Image.create({ 'fromImage' => "#{repo(image)}:#{tag(image)}" }, docker_connection)
387
+ ::Docker::Image.create({ 'fromImage' => "#{repo(image)}:#{tag(image)}" }, nil, docker_connection)
390
388
  end
391
389
  end
392
390
 
@@ -57,6 +57,19 @@ EOF
57
57
  i = ::Docker::Image.build_from_dir("#{tmpdir}/dokken", 'nocache' => true, 'rm' => true)
58
58
  i.tag('repo' => repo(data_image), 'tag' => tag(data_image), 'force' => true)
59
59
  end
60
+
61
+ def default_docker_host
62
+ if ENV['DOCKER_HOST']
63
+ ENV['DOCKER_HOST']
64
+ elsif File.exist?('/var/run/docker.sock')
65
+ 'unix:///var/run/docker.sock'
66
+ # TODO: Docker for Windows also operates over a named pipe at
67
+ # //./pipe/docker_engine that can be used if named pipe support is
68
+ # added to the docker-api gem.
69
+ else
70
+ 'tcp://127.0.0.1:2375'
71
+ end
72
+ end
60
73
  end
61
74
  end
62
75
  end
@@ -19,6 +19,6 @@
19
19
  module Kitchen
20
20
  module Driver
21
21
  # Version string for Dokken Kitchen driver
22
- DOKKEN_VERSION = '1.0.10'.freeze
22
+ DOKKEN_VERSION = '1.1.0'.freeze
23
23
  end
24
24
  end
@@ -16,6 +16,7 @@
16
16
  # limitations under the License.
17
17
 
18
18
  require 'kitchen'
19
+ require 'net/scp'
19
20
  require 'tmpdir'
20
21
  require 'digest/sha1'
21
22
  require_relative 'dokken/helpers'
@@ -38,11 +39,11 @@ module Kitchen
38
39
 
39
40
  plugin_version Kitchen::VERSION
40
41
 
41
- default_config :docker_host_url, ENV['DOCKER_HOST'] || 'unix:///var/run/docker.sock'
42
+ default_config :docker_host_url, default_docker_host
42
43
  default_config :read_timeout, 3600
43
44
  default_config :write_timeout, 3600
44
45
  default_config :host_ip_override do |transport|
45
- transport.docker_for_mac? ? "localhost" : false
46
+ transport.docker_for_mac_or_win? ? "localhost" : false
46
47
  end
47
48
 
48
49
  # (see Base#connection)
@@ -110,20 +111,32 @@ module Kitchen
110
111
  File.write("#{tmpdir}/dokken/id_rsa", insecure_ssh_private_key)
111
112
  FileUtils.chmod(0600, "#{tmpdir}/dokken/id_rsa")
112
113
 
113
- rsync_cmd = '/usr/bin/rsync -a -e'
114
- rsync_cmd << ' \''
115
- rsync_cmd << 'ssh -2'
116
- rsync_cmd << " -i #{tmpdir}/dokken/id_rsa"
117
- rsync_cmd << ' -o CheckHostIP=no'
118
- rsync_cmd << ' -o Compression=no'
119
- rsync_cmd << ' -o PasswordAuthentication=no'
120
- rsync_cmd << ' -o StrictHostKeyChecking=no'
121
- rsync_cmd << ' -o UserKnownHostsFile=/dev/null'
122
- rsync_cmd << ' -o LogLevel=ERROR'
123
- rsync_cmd << " -p #{port}"
124
- rsync_cmd << '\''
125
- rsync_cmd << " #{locals.join(' ')} root@#{ip}:#{remote}"
126
- system(rsync_cmd)
114
+ begin
115
+ rsync_cmd = '/usr/bin/rsync -a -e'
116
+ rsync_cmd << ' \''
117
+ rsync_cmd << 'ssh -2'
118
+ rsync_cmd << " -i #{tmpdir}/dokken/id_rsa"
119
+ rsync_cmd << ' -o CheckHostIP=no'
120
+ rsync_cmd << ' -o Compression=no'
121
+ rsync_cmd << ' -o PasswordAuthentication=no'
122
+ rsync_cmd << ' -o StrictHostKeyChecking=no'
123
+ rsync_cmd << ' -o UserKnownHostsFile=/dev/null'
124
+ rsync_cmd << ' -o LogLevel=ERROR'
125
+ rsync_cmd << " -p #{port}"
126
+ rsync_cmd << '\''
127
+ rsync_cmd << " #{locals.join(' ')} root@#{ip}:#{remote}"
128
+ %x(#{rsync_cmd})
129
+ rescue Errno::ENOENT
130
+ debug 'Rsync is not installed. Falling back to SCP.'
131
+ locals.each do |local|
132
+ Net::SCP.upload!(ip,
133
+ 'root',
134
+ local,
135
+ remote,
136
+ recursive: true,
137
+ ssh: { port: port, keys: ["#{tmpdir}/dokken/id_rsa"] })
138
+ end
139
+ end
127
140
  end
128
141
 
129
142
  def login_command
@@ -163,11 +176,11 @@ module Kitchen
163
176
  end
164
177
  end
165
178
 
166
- # Detect whether or not we are running in Docker for Mac
179
+ # Detect whether or not we are running in Docker for Mac or Windows
167
180
  #
168
181
  # @return [TrueClass,FalseClass]
169
- def docker_for_mac?
170
- Docker.info["Name"] == "moby"
182
+ def docker_for_mac_or_win?
183
+ ::Docker.info(::Docker::Connection.new(config[:docker_host_url], {}))['Name'] == "moby"
171
184
  end
172
185
 
173
186
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-dokken
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean OMeara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-19 00:00:00.000000000 Z
11
+ date: 2016-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen