kitchen-docker 3.0.0 → 3.2.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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -0
  3. data/.github/workflows/lint.yml +99 -0
  4. data/.github/workflows/publish.yaml +32 -0
  5. data/.gitignore +1 -0
  6. data/.markdownlint.yaml +6 -0
  7. data/.release-please-manifest.json +3 -0
  8. data/.rubocop.yml +2 -3
  9. data/CHANGELOG.md +40 -0
  10. data/Gemfile +20 -1
  11. data/README.md +16 -9
  12. data/Rakefile +13 -36
  13. data/cookbooks +1 -0
  14. data/kitchen-docker.gemspec +9 -30
  15. data/kitchen.windows.yml +2 -4
  16. data/kitchen.yml +58 -26
  17. data/lib/kitchen/docker/container/linux.rb +17 -17
  18. data/lib/kitchen/docker/container/windows.rb +11 -11
  19. data/lib/kitchen/docker/container.rb +7 -7
  20. data/lib/kitchen/docker/docker_version.rb +1 -1
  21. data/lib/kitchen/docker/erb_context.rb +3 -3
  22. data/lib/kitchen/docker/helpers/cli_helper.rb +33 -33
  23. data/lib/kitchen/docker/helpers/container_helper.rb +30 -28
  24. data/lib/kitchen/docker/helpers/dockerfile_helper.rb +34 -34
  25. data/lib/kitchen/docker/helpers/file_helper.rb +4 -4
  26. data/lib/kitchen/docker/helpers/image_helper.rb +28 -14
  27. data/lib/kitchen/docker/helpers/inspec_helper.rb +62 -40
  28. data/lib/kitchen/driver/docker.rb +34 -40
  29. data/lib/kitchen/transport/docker.rb +15 -16
  30. data/release-please-config.json +12 -0
  31. data/renovate.json +8 -0
  32. data/spec/docker_spec.rb +108 -0
  33. data/spec/dockerfile_helper_spec.rb +109 -0
  34. data/spec/inspec_helper_spec.rb +58 -0
  35. data/{test/spec → spec}/spec_helper.rb +5 -26
  36. data/test/Dockerfile +4 -5
  37. data/test/cookbooks/cinc_test/metadata.rb +2 -0
  38. data/test/cookbooks/cinc_test/recipes/default.rb +10 -0
  39. data/test/cookbooks/docker_test/attributes/default.rb +1 -0
  40. data/test/cookbooks/docker_test/metadata.rb +3 -0
  41. data/test/cookbooks/docker_test/recipes/default.rb +94 -0
  42. data/test/integration/cinc/inspec/cinc_spec.rb +21 -0
  43. data/test/integration/default/disabled/default_spec.rb +6 -6
  44. data/test/integration/inspec/inspec_spec.rb +3 -3
  45. metadata +26 -211
  46. data/.cane +0 -0
  47. data/.github/dependabot.yml +0 -7
  48. data/.github/workflows/ci.yml +0 -124
  49. data/.tailor +0 -4
  50. data/lib/docker/version.rb +0 -25
  51. data/lib/train/docker.rb +0 -125
  52. data/test/spec/docker_spec.rb +0 -64
@@ -0,0 +1,108 @@
1
+ #
2
+ # Copyright 2016, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require "spec_helper"
18
+
19
+ describe Kitchen::Driver::Docker do
20
+ describe "#config_to_options" do
21
+ let(:config) {}
22
+ subject { described_class.new.send(:config_to_options, config) }
23
+
24
+ context "with nil" do
25
+ let(:config) { nil }
26
+ it { is_expected.to eq "" }
27
+ end # /context with nil
28
+
29
+ context "with a string" do
30
+ let(:config) { "--foo" }
31
+ it { is_expected.to eq "--foo" }
32
+ end # /context with a string
33
+
34
+ context "with a string with spaces" do
35
+ let(:config) { "--foo bar" }
36
+ it { is_expected.to eq "--foo bar" }
37
+ end # /context with a string with spaces
38
+
39
+ context "with an array of strings" do
40
+ let(:config) { %w{--foo --bar} }
41
+ it { is_expected.to eq "--foo --bar" }
42
+ end # /context with an array of strings
43
+
44
+ context "with an array of hashes" do
45
+ let(:config) { [{ foo: "bar" }, { other: "baz" }] }
46
+ it { is_expected.to eq "--foo=bar --other=baz" }
47
+ end # /context with an array of hashes
48
+
49
+ context "with a hash of strings" do
50
+ let(:config) { { foo: "bar", other: "baz" } }
51
+ it { is_expected.to eq "--foo=bar --other=baz" }
52
+ end # /context with a hash of strings
53
+
54
+ context "with a hash of arrays" do
55
+ let(:config) { { foo: %w{bar baz} } }
56
+ it { is_expected.to eq "--foo=bar --foo=baz" }
57
+ end # /context with a hash of arrays
58
+
59
+ context "with a hash of strings with spaces" do
60
+ let(:config) { { foo: "bar two", other: "baz" } }
61
+ it { is_expected.to eq '--foo=bar\\ two --other=baz' }
62
+ end # /context with a hash of strings with spaces
63
+ end # /describe #config_to_options
64
+
65
+ describe "socket default config logic" do
66
+ def resolve_socket
67
+ socket = "unix:///var/run/docker.sock"
68
+ socket = "npipe:////./pipe/docker_engine" if Gem.win_platform?
69
+ ENV["DOCKER_HOST"] || socket
70
+ end
71
+
72
+ context "on a non-Windows host without DOCKER_HOST set" do
73
+ before do
74
+ allow(Gem).to receive(:win_platform?).and_return(false)
75
+ allow(ENV).to receive(:[]).and_call_original
76
+ allow(ENV).to receive(:[]).with("DOCKER_HOST").and_return(nil)
77
+ end
78
+
79
+ it "uses the Unix socket" do
80
+ expect(resolve_socket).to eq("unix:///var/run/docker.sock")
81
+ end
82
+ end
83
+
84
+ context "on a Windows host without DOCKER_HOST set" do
85
+ before do
86
+ allow(Gem).to receive(:win_platform?).and_return(true)
87
+ allow(ENV).to receive(:[]).and_call_original
88
+ allow(ENV).to receive(:[]).with("DOCKER_HOST").and_return(nil)
89
+ end
90
+
91
+ it "uses the Windows named pipe" do
92
+ expect(resolve_socket).to eq("npipe:////./pipe/docker_engine")
93
+ end
94
+ end
95
+
96
+ context "when DOCKER_HOST env var is set" do
97
+ before do
98
+ allow(Gem).to receive(:win_platform?).and_return(false)
99
+ allow(ENV).to receive(:[]).and_call_original
100
+ allow(ENV).to receive(:[]).with("DOCKER_HOST").and_return("tcp://192.168.1.1:2375")
101
+ end
102
+
103
+ it "uses DOCKER_HOST over the default socket" do
104
+ expect(resolve_socket).to eq("tcp://192.168.1.1:2375")
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,109 @@
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ #
14
+
15
+ require "spec_helper"
16
+ require "kitchen/docker/helpers/dockerfile_helper"
17
+
18
+ describe Kitchen::Docker::Helpers::DockerfileHelper do
19
+ let(:helper_class) do
20
+ Class.new do
21
+ include Kitchen::Docker::Helpers::DockerfileHelper
22
+ attr_accessor :config
23
+
24
+ def initialize(config = {})
25
+ @config = config
26
+ end
27
+ end
28
+ end
29
+
30
+ let(:helper) { helper_class.new(platform:) }
31
+
32
+ describe "#amazonlinux_platform" do
33
+ let(:platform) { "amazonlinux" }
34
+
35
+ it "includes --allowerasing flag for yum install" do
36
+ result = helper.amazonlinux_platform
37
+ expect(result).to include("yum install -y --allowerasing")
38
+ end
39
+
40
+ it "installs required packages including curl" do
41
+ result = helper.amazonlinux_platform
42
+ expect(result).to include("sudo openssh-server openssh-clients which curl")
43
+ end
44
+
45
+ it "sets container environment variable" do
46
+ result = helper.amazonlinux_platform
47
+ expect(result).to include("ENV container=docker")
48
+ end
49
+
50
+ it "generates SSH host key if missing" do
51
+ result = helper.amazonlinux_platform
52
+ expect(result).to include("ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key")
53
+ end
54
+ end
55
+
56
+ describe "#rhel_platform" do
57
+ let(:platform) { "rhel" }
58
+
59
+ it "does not include --allowerasing flag" do
60
+ result = helper.rhel_platform
61
+ expect(result).not_to include("--allowerasing")
62
+ end
63
+
64
+ it "installs required packages including curl" do
65
+ result = helper.rhel_platform
66
+ expect(result).to include("sudo openssh-server openssh-clients which curl")
67
+ end
68
+ end
69
+
70
+ describe "#dockerfile_platform" do
71
+ context "when platform is amazonlinux" do
72
+ let(:platform) { "amazonlinux" }
73
+
74
+ it "calls amazonlinux_platform method" do
75
+ expect(helper).to receive(:amazonlinux_platform).and_call_original
76
+ result = helper.dockerfile_platform
77
+ expect(result).to include("--allowerasing")
78
+ end
79
+ end
80
+
81
+ context "when platform is rhel" do
82
+ let(:platform) { "rhel" }
83
+
84
+ it "calls rhel_platform method" do
85
+ expect(helper).to receive(:rhel_platform).and_call_original
86
+ result = helper.dockerfile_platform
87
+ expect(result).not_to include("--allowerasing")
88
+ end
89
+ end
90
+
91
+ context "when platform is centos" do
92
+ let(:platform) { "centos" }
93
+
94
+ it "calls rhel_platform method" do
95
+ expect(helper).to receive(:rhel_platform).and_call_original
96
+ helper.dockerfile_platform
97
+ end
98
+ end
99
+
100
+ context "when platform is oraclelinux" do
101
+ let(:platform) { "oraclelinux" }
102
+
103
+ it "calls rhel_platform method" do
104
+ expect(helper).to receive(:rhel_platform).and_call_original
105
+ helper.dockerfile_platform
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,58 @@
1
+ require "spec_helper"
2
+ require "logger"
3
+
4
+ RSpec.describe "inspec_helper patches" do
5
+ let(:helper_path) { File.expand_path("../lib/kitchen/docker/helpers/inspec_helper.rb", __dir__) }
6
+
7
+ describe "kitchen-inspec patch" do
8
+ # Test actual post-load state rather than trying to stub Kernel.require,
9
+ # which does not intercept require calls made inside a load'd file in Ruby 3.4.
10
+ if defined?(Kitchen::Verifier::Inspec)
11
+ it "adds runner_options_for_docker to Kitchen::Verifier::Inspec" do
12
+ expect(Kitchen::Verifier::Inspec.method_defined?(:runner_options_for_docker)).to be true
13
+ end
14
+ else
15
+ it "Kitchen::Verifier::Inspec not available — patch correctly skipped" do
16
+ expect(defined?(Kitchen::Verifier::Inspec)).to be_falsy
17
+ end
18
+ end
19
+
20
+ context "when kitchen-inspec is not available" do
21
+ before do
22
+ allow(Kernel).to receive(:require).and_call_original
23
+ allow(Kernel).to receive(:require).with("kitchen/verifier/inspec").and_raise(LoadError)
24
+ allow(Kernel).to receive(:require).with("kitchen/verifier/cinc_auditor").and_raise(LoadError)
25
+ end
26
+
27
+ it "does not raise when loading the helper" do
28
+ expect { load helper_path }.not_to raise_error
29
+ end
30
+ end
31
+ end
32
+
33
+ describe "kitchen-cinc-auditor patch" do
34
+ # Test actual post-load state rather than trying to stub Kernel.require.
35
+ if defined?(Kitchen::Verifier::CincAuditor) &&
36
+ defined?(Kitchen::Verifier::CincAuditor::TransportOptions)
37
+ it "adds build_docker to Kitchen::Verifier::CincAuditor::TransportOptions" do
38
+ expect(Kitchen::Verifier::CincAuditor::TransportOptions.method_defined?(:build_docker)).to be true
39
+ end
40
+ else
41
+ it "Kitchen::Verifier::CincAuditor not available — patch correctly skipped" do
42
+ expect(defined?(Kitchen::Verifier::CincAuditor)).to be_falsy
43
+ end
44
+ end
45
+
46
+ context "when kitchen-cinc-auditor is not available" do
47
+ before do
48
+ allow(Kernel).to receive(:require).and_call_original
49
+ allow(Kernel).to receive(:require).with("kitchen/verifier/inspec").and_raise(LoadError)
50
+ allow(Kernel).to receive(:require).with("kitchen/verifier/cinc_auditor").and_raise(LoadError)
51
+ end
52
+
53
+ it "does not raise when loading the helper" do
54
+ expect { load helper_path }.not_to raise_error
55
+ end
56
+ end
57
+ end
58
+ end
@@ -14,32 +14,11 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
- require 'rake'
18
- require 'rspec'
19
- require 'rspec/its'
20
- require 'simplecov'
17
+ require "rake"
18
+ require "rspec"
19
+ require "rspec/its"
21
20
 
22
- # Check for coverage stuffs
23
- formatters = []
24
-
25
- if ENV['CODECOV_TOKEN'] || ENV['CI']
26
- require 'codecov'
27
- formatters << SimpleCov::Formatter::Codecov
28
- end
29
-
30
- unless formatters.empty?
31
- SimpleCov.formatters = formatters
32
- end
33
-
34
- SimpleCov.start do
35
- # Don't get coverage on the test cases themselves.
36
- add_filter '/spec/'
37
- add_filter '/test/'
38
- # Codecov doesn't automatically ignore vendored files.
39
- add_filter '/vendor/'
40
- end
41
-
42
- require 'kitchen/driver/docker'
21
+ require "kitchen/driver/docker"
43
22
 
44
23
  RSpec.configure do |config|
45
24
  # Basic configuraiton
@@ -50,5 +29,5 @@ RSpec.configure do |config|
50
29
  # order dependency and want to debug it, you can fix the order by providing
51
30
  # the seed, which is printed after each run.
52
31
  # --seed 1234
53
- config.order = 'random'
32
+ config.order = "random"
54
33
  end
data/test/Dockerfile CHANGED
@@ -1,8 +1,7 @@
1
- FROM centos:7
2
- RUN yum clean all
3
- RUN yum install -y sudo openssh-server openssh-clients which curl htop
1
+ FROM almalinux:latest
2
+ RUN dnf clean all
3
+ RUN dnf install -y sudo openssh-server openssh-clients which curl
4
4
  RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
5
- RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
6
5
  RUN mkdir -p /var/run/sshd
7
6
  RUN useradd -d /home/<%= @username %> -m -s /bin/bash <%= @username %>
8
7
  RUN echo <%= "#{@username}:#{@password}" %> | chpasswd
@@ -13,5 +12,5 @@ RUN chmod 0700 /home/<%= @username %>/.ssh
13
12
  RUN touch /home/<%= @username %>/.ssh/authorized_keys
14
13
  RUN chown <%= @username %> /home/<%= @username %>/.ssh/authorized_keys
15
14
  RUN chmod 0600 /home/<%= @username %>/.ssh/authorized_keys
16
- RUN curl -L https://www.chef.io/chef/install.sh | bash
15
+ RUN curl -L https://omnitruck.cinc.sh/install.sh | bash
17
16
  RUN echo '<%= IO.read(@public_key).strip %>' >> /home/<%= @username %>/.ssh/authorized_keys
@@ -0,0 +1,2 @@
1
+ name "cinc_test"
2
+ version "0.0.1"
@@ -0,0 +1,10 @@
1
+ file_path = if windows?
2
+ "C:/cinc-converged"
3
+ else
4
+ "/tmp/cinc-converged"
5
+ end
6
+
7
+ file file_path do
8
+ content "ok\n"
9
+ mode "0644"
10
+ end
@@ -0,0 +1 @@
1
+ default["docker_test"]["revision"] = "main"
@@ -0,0 +1,3 @@
1
+ name "dokken_test"
2
+ version "0.0.1"
3
+ depends "docker"
@@ -0,0 +1,94 @@
1
+ user "notroot" do
2
+ home "/home/notroot"
3
+ manage_home true
4
+ action :create
5
+ end
6
+
7
+ package %w{
8
+ gcc-c++
9
+ gcc
10
+ git
11
+ iputils
12
+ libffi
13
+ libffi-devel
14
+ make
15
+ net-tools
16
+ nmap
17
+ procps-ng
18
+ redhat-rpm-config
19
+ ruby
20
+ ruby-devel
21
+ rubygem-bundler
22
+ rubygem-io-console
23
+ rubygem-rake
24
+ telnet
25
+ which
26
+ }
27
+
28
+ docker_service "default" do
29
+ host ["tcp://127.0.0.1"]
30
+ action %i{create start}
31
+ end
32
+
33
+ git "/home/notroot/kitchen-docker" do
34
+ repository "/opt/kitchen-docker/.git"
35
+ revision node["docker_test"]["revision"]
36
+ user "notroot"
37
+ action :sync
38
+ end
39
+
40
+ execute "install gem bundle" do
41
+ command "/usr/bin/bundle install --without development --path vendor/bundle"
42
+ cwd "/home/notroot/kitchen-docker"
43
+ user "notroot"
44
+ live_stream false
45
+ creates "/home/notroot/kitchen-docker/Gemfile.lock"
46
+ environment "HOME" => "/home/notroot"
47
+ action :run
48
+ end
49
+
50
+ execute "Test Kitchen verify hello" do
51
+ command <<-EOH.gsub(/^\s{4}/, "").chomp
52
+ /usr/bin/bundle exec kitchen create hello -l debug
53
+ /usr/bin/bundle exec kitchen converge hello -l debug
54
+ /usr/bin/bundle exec kitchen verify hello -l debug
55
+ EOH
56
+ cwd "/home/notroot/kitchen-docker"
57
+ user "notroot"
58
+ live_stream true
59
+ environment "PATH" => "/usr/bin:/usr/local/bin:/home/notroot/bin",
60
+ "HOME" => "/home/notroot",
61
+ "DOCKER_HOST" => "tcp://127.0.0.1:2375",
62
+ "CHEF_LICENSE" => "accept-no-persist"
63
+ action :run
64
+ end
65
+
66
+ execute "destroy hello again suite" do
67
+ command "/usr/bin/bundle exec kitchen destroy helloagain"
68
+ cwd "/home/notroot/kitchen-docker"
69
+ user "notroot"
70
+ live_stream true
71
+ environment "PATH" => "/usr/bin:/usr/local/bin:/home/notroot/bin",
72
+ "HOME" => "/home/notroot",
73
+ "DOCKER_HOST" => "tcp://127.0.0.1:2375"
74
+ action :run
75
+ end
76
+
77
+ docker_tag "local-example" do
78
+ target_repo "fedora"
79
+ target_tag "latest"
80
+ to_repo "local-example"
81
+ to_tag "latest"
82
+ end
83
+
84
+ execute "Test Kitchen verify without image pull" do
85
+ command "/usr/bin/bundle exec kitchen test local_image -l debug"
86
+ cwd "/home/notroot/kitchen-docker"
87
+ user "notroot"
88
+ live_stream true
89
+ environment "PATH" => "/usr/bin:/usr/local/bin:/home/notroot/bin",
90
+ "HOME" => "/home/notroot",
91
+ "DOCKER_HOST" => "tcp://127.0.0.1:2375",
92
+ "CHEF_LICENSE" => "accept-no-persist"
93
+ action :run
94
+ end
@@ -0,0 +1,21 @@
1
+ file_path = if os.windows?
2
+ "C:/cinc-converged"
3
+ else
4
+ "/tmp/cinc-converged"
5
+ end
6
+
7
+ describe file(file_path) do
8
+ it { should exist }
9
+ its(:content) { should eq "ok\n" }
10
+ end
11
+
12
+ cinc_cmd = if os.windows?
13
+ 'C:\cinc-project\cinc\bin\cinc-client --version'
14
+ else
15
+ "/opt/cinc/bin/cinc-client --version"
16
+ end
17
+
18
+ describe command(cinc_cmd) do
19
+ its(:exit_status) { should eq 0 }
20
+ its(:stdout) { should match(/Cinc Client/) }
21
+ end
@@ -14,11 +14,11 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
- # Disable now busser-serever is gone.
18
- # require 'serverspec'
19
- # require 'spec_helper'
20
-
21
- # # Just make sure the image launched and is reachable.
22
- # describe command('true') do
17
+ # Disable now busser-server is gone.
18
+ # require "serverspec"
19
+ # require "spec_helper"
20
+ #
21
+ # Just make sure the image launched and is reachable.
22
+ # describe command("true") do
23
23
  # its(:exit_status) { is_expected.to eq 0 }
24
24
  # end
@@ -15,12 +15,12 @@
15
15
  #
16
16
 
17
17
  # Just make sure the image launched and is reachable.
18
- if os[:family] == 'windows'
19
- describe command('echo 1') do
18
+ if os[:family] == "windows"
19
+ describe command("echo 1") do
20
20
  its(:exit_status) { is_expected.to eq 0 }
21
21
  end
22
22
  else
23
- describe command('true') do
23
+ describe command("true") do
24
24
  its(:exit_status) { is_expected.to eq 0 }
25
25
  end
26
26
  end