kitchen-dokken 2.12.0 → 2.15.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
  SHA256:
3
- metadata.gz: 6e00103fefe2a49fd2630337f2a8d0bb0932484b770704b69c1fb31d9ddd0b42
4
- data.tar.gz: 0acea78f249845712be9d1f97094f190369a1e15707ac559de27be5fc6c29e31
3
+ metadata.gz: d549607487cae2cf1d58c9fadfed6e5c0649d085b27dc0841abf32d4a23670df
4
+ data.tar.gz: 4be3556b19ae6795d6c70d196913ed79f7d14971dc386f539a0321683ecdf49b
5
5
  SHA512:
6
- metadata.gz: 0d84bd393b040ef4bc771a5d5c4448dff1860a9244d0818341f06c834e8133cbd9a77b0b7a4f697c8873be24b567083556f4feb47a57723782fe6575ad7b2a1a
7
- data.tar.gz: b628d6bce7009efa94713c5c6032ec81e3258686c84f22ebd430e1710a1817cfaf3cb82420a8109e21f1506ff0e661c08da1e6fb2d5baedd6adbb216a0dedaa8
6
+ metadata.gz: ee6f97ad4f722b828f9d0508a69224ef7ae4514b39280a3c84ae14351626939e04d7fdae779c4280efcc4d88210a37fad02dab74ad638432d8aa1e929e40e1e7
7
+ data.tar.gz: 5035e7f732b10ed7f9407555d612441c509985acd6d33d577d23c02c0529cd80be0f93c2c668fc0355135ed765e9844d075adfaf417de441a501858588042e2a
@@ -48,7 +48,10 @@ module Kitchen
48
48
  default_config :entrypoint, nil
49
49
  default_config :env, nil
50
50
  default_config :hostname, "dokken"
51
+ default_config :hostname_aliases, nil
51
52
  default_config :image_prefix, nil
53
+ default_config :ipv6, false
54
+ default_config :ipv6_subnet, "2001:db8:1::/64" # "2001:db8::/32 Range reserved for documentation"
52
55
  default_config :links, nil
53
56
  default_config :memory_limit, 0
54
57
  default_config :network_mode, "dokken"
@@ -169,8 +172,10 @@ module Kitchen
169
172
  end
170
173
 
171
174
  def work_image_dockerfile
175
+ from = registry_image_path(platform_image)
176
+ debug("driver - Building work image from #{from}")
172
177
  dockerfile_contents = [
173
- "FROM #{platform_image}",
178
+ "FROM #{from}",
174
179
  "LABEL X-Built-By=kitchen-dokken X-Built-From=#{platform_image}",
175
180
  ]
176
181
  Array(config[:intermediate_instructions]).each do |c|
@@ -287,7 +292,8 @@ module Kitchen
287
292
  config = {
288
293
  "name" => runner_container_name,
289
294
  "Cmd" => Shellwords.shellwords(self[:pid_one_command]),
290
- "Image" => "#{repo(work_image)}:#{tag(work_image)}",
295
+ # locally built image, must use short-name
296
+ "Image" => short_image_path(work_image),
291
297
  "Hostname" => self[:hostname],
292
298
  "Env" => self[:env],
293
299
  "ExposedPorts" => exposed_ports,
@@ -310,7 +316,7 @@ module Kitchen
310
316
  "NetworkingConfig" => {
311
317
  "EndpointsConfig" => {
312
318
  self[:network_mode] => {
313
- "Aliases" => Array(self[:hostname]),
319
+ "Aliases" => Array(self[:hostname]).concat(Array(self[:hostname_aliases])),
314
320
  },
315
321
  },
316
322
  },
@@ -329,7 +335,8 @@ module Kitchen
329
335
  debug "driver - creating #{data_container_name}"
330
336
  config = {
331
337
  "name" => data_container_name,
332
- "Image" => "#{repo(data_image)}:#{tag(data_image)}",
338
+ # locally built image, must use short-name
339
+ "Image" => short_image_path(data_image),
333
340
  "HostConfig" => {
334
341
  "PortBindings" => port_bindings,
335
342
  "PublishAllPorts" => true,
@@ -352,9 +359,9 @@ module Kitchen
352
359
  begin
353
360
  lockfile.lock
354
361
  with_retries { ::Docker::Network.get("dokken", {}, docker_connection) }
355
- rescue
362
+ rescue ::Docker::Error::NotFoundError
356
363
  begin
357
- with_retries { ::Docker::Network.create("dokken", {}) }
364
+ with_retries { ::Docker::Network.create("dokken", network_settings) }
358
365
  rescue ::Docker::Error => e
359
366
  debug "driver - error :#{e}:"
360
367
  end
@@ -388,14 +395,14 @@ module Kitchen
388
395
  config = {
389
396
  "name" => chef_container_name,
390
397
  "Cmd" => "true",
391
- "Image" => "#{repo(chef_image)}:#{tag(chef_image)}",
398
+ "Image" => registry_image_path(chef_image),
392
399
  "HostConfig" => {
393
400
  "NetworkMode" => self[:network_mode],
394
401
  },
395
402
  }
396
403
  chef_container = create_container(config)
397
404
  state[:chef_container] = chef_container.json
398
- rescue ::Docker::Error => e
405
+ rescue ::Docker::Error, StandardError => e
399
406
  raise "driver - #{chef_container_name} failed to create #{e}"
400
407
  end
401
408
  ensure
@@ -404,12 +411,12 @@ module Kitchen
404
411
  end
405
412
 
406
413
  def pull_platform_image
407
- debug "driver - pulling #{chef_image} #{repo(platform_image)} #{tag(platform_image)}"
414
+ debug "driver - pulling #{short_image_path(platform_image)}"
408
415
  config[:pull_platform_image] ? pull_image(platform_image) : pull_if_missing(platform_image)
409
416
  end
410
417
 
411
418
  def pull_chef_image
412
- debug "driver - pulling #{chef_image} #{repo(chef_image)} #{tag(chef_image)}"
419
+ debug "driver - pulling #{short_image_path(chef_image)}"
413
420
  config[:pull_chef_image] ? pull_image(chef_image) : pull_if_missing(chef_image)
414
421
  end
415
422
 
@@ -422,7 +429,7 @@ module Kitchen
422
429
 
423
430
  def container_exist?(name)
424
431
  return true if ::Docker::Container.get(name, {}, docker_connection)
425
- rescue
432
+ rescue StandardError, ::Docker::Error::NotFoundError
426
433
  false
427
434
  end
428
435
 
@@ -440,10 +447,45 @@ module Kitchen
440
447
  [repo, tag]
441
448
  end
442
449
 
450
+ # Return the 'repo' half of a docker image path. Agnostic about if a
451
+ # registry is included, this effectively is just "before the colon"
452
+ #
453
+ # @param image [String] the docker image path to parse
454
+ # @return [String] the repo portion of `image`
443
455
  def repo(image)
444
456
  parse_image_name(image)[0]
445
457
  end
446
458
 
459
+ # Return the 'tag' of a docker image path. Will be `latest` if there
460
+ # is no explicit tag in the image path.
461
+ #
462
+ # @param image [String] the docker image path to parse
463
+ # @return [String] the tag of `image`
464
+ def tag(image)
465
+ parse_image_name(image)[1]
466
+ end
467
+
468
+ # Ensures an explicit tag on an image path.
469
+ #
470
+ # @param image [String] the docker image path to parse
471
+ # @return [String] `repo`:`tag`
472
+ def short_image_path(image)
473
+ "#{repo(image)}:#{tag(image)}"
474
+ end
475
+
476
+ # Qualifies the results of `short_image_path` with any registry the
477
+ # user has requested
478
+ #
479
+ # @param image [String] the docker image path to parse
480
+ # @return [String] The most fully-qualified registry path we cn make
481
+ def registry_image_path(image)
482
+ if config[:docker_registry]
483
+ "#{config[:docker_registry]}/#{short_image_path(image)}"
484
+ else
485
+ short_image_path(image)
486
+ end
487
+ end
488
+
447
489
  def create_container(args)
448
490
  with_retries { @container = ::Docker::Container.get(args["name"], {}, docker_connection) }
449
491
  rescue
@@ -511,10 +553,6 @@ module Kitchen
511
553
  end
512
554
  end
513
555
 
514
- def tag(image)
515
- parse_image_name(image)[1]
516
- end
517
-
518
556
  def chef_container_name
519
557
  "chef-#{chef_version}"
520
558
  end
@@ -547,7 +585,7 @@ module Kitchen
547
585
  end
548
586
 
549
587
  def pull_if_missing(image)
550
- return if ::Docker::Image.exist?("#{repo(image)}:#{tag(image)}", {}, docker_connection)
588
+ return if ::Docker::Image.exist?(registry_image_path(image), {}, docker_connection)
551
589
 
552
590
  pull_image image
553
591
  end
@@ -557,21 +595,14 @@ module Kitchen
557
595
  val.sub(%r{https?://}, "").split("/").first
558
596
  end
559
597
 
560
- def image_path(image)
561
- fqimage = "#{repo(image)}:#{tag(image)}"
562
- if config[:docker_registry]
563
- fqimage = "#{config[:docker_registry]}/#{fqimage}"
564
- end
565
- fqimage
566
- end
567
-
568
598
  def pull_image(image)
599
+ path = registry_image_path(image)
569
600
  with_retries do
570
- if Docker::Image.exist?(image_path(image), {}, docker_connection)
571
- original_image = Docker::Image.get(image_path(image), {}, docker_connection)
601
+ if Docker::Image.exist?(path, {}, docker_connection)
602
+ original_image = Docker::Image.get(path, {}, docker_connection)
572
603
  end
573
604
 
574
- new_image = Docker::Image.create({ "fromImage" => "#{repo(image)}:#{tag(image)}" }, docker_connection)
605
+ new_image = Docker::Image.create({ "fromImage" => path }, {}, docker_connection)
575
606
 
576
607
  !(original_image && original_image.id.start_with?(new_image.id))
577
608
  end
@@ -18,6 +18,6 @@
18
18
  module Kitchen
19
19
  module Driver
20
20
  # Version string for Dokken Kitchen driver
21
- DOKKEN_VERSION = "2.12.0".freeze
21
+ DOKKEN_VERSION = "2.15.0".freeze
22
22
  end
23
23
  end
@@ -117,6 +117,8 @@ VOLUME /opt/verifier
117
117
  end
118
118
 
119
119
  def docker_info
120
+ ::Docker.url = default_docker_host
121
+
120
122
  @docker_info ||= ::Docker.info
121
123
  rescue Excon::Error::Socket
122
124
  puts "kitchen-dokken could not connect to the docker host at #{default_docker_host}. Is docker running?"
@@ -175,6 +177,21 @@ VOLUME /opt/verifier
175
177
  coerce_exposed_ports(config[:ports])
176
178
  end
177
179
 
180
+ def network_settings
181
+ if self[:ipv6]
182
+ {
183
+ "EnableIPv6" => true,
184
+ "IPAM" => {
185
+ "Config" => [{
186
+ "Subnet" => self[:ipv6_subnet],
187
+ }],
188
+ },
189
+ }
190
+ else
191
+ {}
192
+ end
193
+ end
194
+
178
195
  def port_bindings
179
196
  coerce_port_bindings(config[:ports])
180
197
  end
@@ -244,6 +261,7 @@ VOLUME /opt/verifier
244
261
  end
245
262
 
246
263
  def remote_docker_host?
264
+ return false if config[:docker_info]["OperatingSystem"].include?("Docker Desktop")
247
265
  return false if config[:docker_info]["OperatingSystem"].include?("Boot2Docker")
248
266
  return true if /^tcp:/.match?(config[:docker_host_url])
249
267
 
@@ -109,12 +109,13 @@ module Kitchen
109
109
  cmd << " -c /opt/kitchen/client.rb"
110
110
  cmd << " -j /opt/kitchen/dna.json"
111
111
  cmd << "--profile-ruby" if config[:profile_ruby]
112
+ cmd << "--slow-report" if config[:slow_resource_report]
112
113
 
113
114
  chef_cmd(cmd)
114
115
  end
115
116
 
116
117
  def write_run_command(command)
117
- File.write("#{dokken_kitchen_sandbox}/run_command", command)
118
+ File.write("#{dokken_kitchen_sandbox}/run_command", command, mode: "wb")
118
119
  end
119
120
 
120
121
  def runner_container_name
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: 2.12.0
4
+ version: 2.15.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: 2021-02-24 00:00:00.000000000 Z
11
+ date: 2021-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api
@@ -53,7 +53,7 @@ dependencies:
53
53
  version: '1.15'
54
54
  - - "<"
55
55
  - !ruby/object:Gem::Version
56
- version: '3'
56
+ version: '4'
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
@@ -63,7 +63,7 @@ dependencies:
63
63
  version: '1.15'
64
64
  - - "<"
65
65
  - !ruby/object:Gem::Version
66
- version: '3'
66
+ version: '4'
67
67
  description: A Test Kitchen Driver for Docker & Chef Infra optimized for rapid testing
68
68
  using Chef Infra docker images
69
69
  email:
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  requirements: []
100
- rubygems_version: 3.1.4
100
+ rubygems_version: 3.2.22
101
101
  signing_key:
102
102
  specification_version: 4
103
103
  summary: A Test Kitchen Driver for Docker & Chef Infra optimized for rapid testing