kitchen-docker 2.15.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.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +1 -0
- data/.github/workflows/lint.yml +99 -0
- data/.github/workflows/publish.yaml +32 -0
- data/.gitignore +1 -0
- data/.markdownlint.yaml +6 -0
- data/.release-please-manifest.json +3 -0
- data/.rubocop.yml +9 -0
- data/.yamllint +15 -0
- data/CHANGELOG.md +40 -0
- data/Gemfile +20 -1
- data/README.md +16 -9
- data/Rakefile +13 -36
- data/cookbooks +1 -0
- data/kitchen-docker.gemspec +9 -29
- data/kitchen.windows.yml +31 -0
- data/kitchen.yml +94 -0
- data/lib/kitchen/docker/container/linux.rb +17 -17
- data/lib/kitchen/docker/container/windows.rb +11 -11
- data/lib/kitchen/docker/container.rb +7 -7
- data/lib/kitchen/docker/docker_version.rb +1 -1
- data/lib/kitchen/docker/erb_context.rb +3 -3
- data/lib/kitchen/docker/helpers/cli_helper.rb +184 -172
- data/lib/kitchen/docker/helpers/container_helper.rb +178 -172
- data/lib/kitchen/docker/helpers/dockerfile_helper.rb +34 -34
- data/lib/kitchen/docker/helpers/file_helper.rb +4 -4
- data/lib/kitchen/docker/helpers/image_helper.rb +28 -14
- data/lib/kitchen/docker/helpers/inspec_helper.rb +62 -40
- data/lib/kitchen/driver/docker.rb +34 -40
- data/lib/kitchen/transport/docker.rb +15 -16
- data/release-please-config.json +12 -0
- data/renovate.json +8 -0
- data/spec/docker_spec.rb +108 -0
- data/spec/dockerfile_helper_spec.rb +109 -0
- data/spec/inspec_helper_spec.rb +58 -0
- data/{test/spec → spec}/spec_helper.rb +5 -26
- data/test/Dockerfile +4 -5
- data/test/cookbooks/cinc_test/metadata.rb +2 -0
- data/test/cookbooks/cinc_test/recipes/default.rb +10 -0
- data/test/cookbooks/docker_test/attributes/default.rb +1 -0
- data/test/cookbooks/docker_test/metadata.rb +3 -0
- data/test/cookbooks/docker_test/recipes/default.rb +94 -0
- data/test/integration/capabilities/{serverspec → disabled}/capabilities_drop_spec.rb +7 -6
- data/test/integration/cinc/inspec/cinc_spec.rb +21 -0
- data/test/integration/default/{serverspec → disabled}/default_spec.rb +7 -6
- data/test/integration/default/{serverspec → disabled}/spec_helper.rb +7 -7
- data/test/integration/inspec/inspec_spec.rb +3 -3
- metadata +33 -202
- data/.cane +0 -0
- data/.github/dependabot.yml +0 -7
- data/.kitchen.windows.yml +0 -33
- data/.kitchen.yml +0 -65
- data/.tailor +0 -4
- data/.travis.yml +0 -57
- data/lib/docker/version.rb +0 -25
- data/lib/train/docker.rb +0 -125
- data/test/spec/docker_spec.rb +0 -64
|
@@ -1,40 +1,62 @@
|
|
|
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
|
-
# This helper
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
# This helper patches kitchen-inspec and/or kitchen-cinc-auditor to add Docker
|
|
15
|
+
# transport support. Remove once upstream gems include this natively.
|
|
16
|
+
|
|
17
|
+
# Patch kitchen-inspec if available
|
|
18
|
+
begin
|
|
19
|
+
require "kitchen/verifier/inspec"
|
|
20
|
+
Kitchen::Verifier::Inspec.class_eval do
|
|
21
|
+
def runner_options_for_docker(config_data)
|
|
22
|
+
opts = {
|
|
23
|
+
"backend" => "docker",
|
|
24
|
+
"logger" => logger,
|
|
25
|
+
"host" => config_data[:container_id],
|
|
26
|
+
}
|
|
27
|
+
logger.debug "Connect to Container: #{opts["host"]}"
|
|
28
|
+
opts
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
rescue LoadError
|
|
32
|
+
# kitchen-inspec not available; skipping patch
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Patch kitchen-cinc-auditor if available
|
|
36
|
+
begin
|
|
37
|
+
require "kitchen/verifier/cinc_auditor"
|
|
38
|
+
Kitchen::Verifier::CincAuditor::TransportOptions.class_eval do
|
|
39
|
+
def build_docker(state)
|
|
40
|
+
options = {
|
|
41
|
+
"backend" => "docker",
|
|
42
|
+
"logger" => logger,
|
|
43
|
+
"host" => state[:container_id],
|
|
44
|
+
}
|
|
45
|
+
logger.debug("Connect to Container: #{options["host"]}")
|
|
46
|
+
options
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
rescue LoadError
|
|
50
|
+
# kitchen-cinc-auditor not available; skipping patch
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
module Kitchen
|
|
54
|
+
module Docker
|
|
55
|
+
module Helpers
|
|
56
|
+
# Marker module included by the Docker transport Connection class.
|
|
57
|
+
# Actual verifier patches are applied directly to verifier classes above.
|
|
58
|
+
module InspecHelper
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -13,17 +13,17 @@
|
|
|
13
13
|
# See the License for the specific language governing permissions and
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
|
|
16
|
-
require
|
|
17
|
-
require
|
|
18
|
-
require
|
|
19
|
-
require
|
|
16
|
+
require "kitchen"
|
|
17
|
+
require "json" unless defined?(JSON)
|
|
18
|
+
require "securerandom" unless defined?(SecureRandom)
|
|
19
|
+
require "net/ssh" unless defined?(Net::SSH)
|
|
20
20
|
|
|
21
|
-
require
|
|
21
|
+
require "kitchen/driver/base"
|
|
22
22
|
|
|
23
|
-
require_relative
|
|
24
|
-
require_relative
|
|
25
|
-
require_relative
|
|
26
|
-
require_relative
|
|
23
|
+
require_relative "../docker/container/linux"
|
|
24
|
+
require_relative "../docker/container/windows"
|
|
25
|
+
require_relative "../docker/helpers/cli_helper"
|
|
26
|
+
require_relative "../docker/helpers/container_helper"
|
|
27
27
|
|
|
28
28
|
module Kitchen
|
|
29
29
|
module Driver
|
|
@@ -35,7 +35,7 @@ module Kitchen
|
|
|
35
35
|
include Kitchen::Docker::Helpers::ContainerHelper
|
|
36
36
|
include ShellOut
|
|
37
37
|
|
|
38
|
-
default_config :binary,
|
|
38
|
+
default_config :binary, "docker"
|
|
39
39
|
default_config :build_options, nil
|
|
40
40
|
default_config :build_tempdir, Dir.pwd
|
|
41
41
|
default_config :cap_add, nil
|
|
@@ -44,9 +44,9 @@ module Kitchen
|
|
|
44
44
|
default_config :env_variables, nil
|
|
45
45
|
default_config :isolation, nil
|
|
46
46
|
default_config :interactive, false
|
|
47
|
-
default_config :private_key, File.join(Dir.pwd,
|
|
47
|
+
default_config :private_key, File.join(Dir.pwd, ".kitchen", "docker_id_rsa")
|
|
48
48
|
default_config :privileged, false
|
|
49
|
-
default_config :public_key, File.join(Dir.pwd,
|
|
49
|
+
default_config :public_key, File.join(Dir.pwd, ".kitchen", "docker_id_rsa.pub")
|
|
50
50
|
default_config :publish_all, false
|
|
51
51
|
default_config :remove_images, false
|
|
52
52
|
default_config :run_options, nil
|
|
@@ -66,43 +66,39 @@ module Kitchen
|
|
|
66
66
|
!driver.remote_socket?
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
default_config :image
|
|
70
|
-
driver.default_image
|
|
71
|
-
end
|
|
69
|
+
default_config :image, &:default_image
|
|
72
70
|
|
|
73
71
|
default_config :instance_name do |driver|
|
|
74
72
|
# Borrowed from kitchen-rackspace
|
|
75
73
|
[
|
|
76
|
-
driver.instance.name.gsub(/\W/,
|
|
77
|
-
(Etc.getlogin ||
|
|
78
|
-
Socket.gethostname.gsub(/\W/,
|
|
79
|
-
Array.new(8) { rand(36).to_s(36) }.join
|
|
80
|
-
].join(
|
|
74
|
+
driver.instance.name.gsub(/\W/, ""),
|
|
75
|
+
(Etc.getlogin || "nologin").gsub(/\W/, ""),
|
|
76
|
+
Socket.gethostname.gsub(/\W/, "")[0..20],
|
|
77
|
+
Array.new(8) { rand(36).to_s(36) }.join,
|
|
78
|
+
].join("-").downcase
|
|
81
79
|
end
|
|
82
80
|
|
|
83
|
-
default_config :platform
|
|
84
|
-
driver.default_platform
|
|
85
|
-
end
|
|
81
|
+
default_config :platform, &:default_platform
|
|
86
82
|
|
|
87
83
|
default_config :run_command do |driver|
|
|
88
84
|
if driver.windows_os?
|
|
89
85
|
# Launch arbitrary process to keep the Windows container alive
|
|
90
86
|
# If running in interactive mode, launch powershell.exe instead
|
|
91
87
|
if driver[:interactive]
|
|
92
|
-
|
|
88
|
+
"powershell.exe"
|
|
93
89
|
else
|
|
94
|
-
|
|
90
|
+
"ping -t localhost"
|
|
95
91
|
end
|
|
96
92
|
else
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
"/usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no -o PasswordAuthentication=yes " \
|
|
94
|
+
"-o UsePrivilegeSeparation=no -o PidFile=/tmp/sshd.pid"
|
|
99
95
|
end
|
|
100
96
|
end
|
|
101
97
|
|
|
102
98
|
default_config :socket do |driver|
|
|
103
|
-
socket =
|
|
104
|
-
socket =
|
|
105
|
-
ENV[
|
|
99
|
+
socket = "unix:///var/run/docker.sock"
|
|
100
|
+
socket = "npipe:////./pipe/docker_engine" if Gem.win_platform?
|
|
101
|
+
ENV["DOCKER_HOST"] || socket
|
|
106
102
|
end
|
|
107
103
|
|
|
108
104
|
default_config :username do |driver|
|
|
@@ -111,14 +107,14 @@ module Kitchen
|
|
|
111
107
|
if driver.windows_os?
|
|
112
108
|
nil
|
|
113
109
|
else
|
|
114
|
-
|
|
110
|
+
"kitchen"
|
|
115
111
|
end
|
|
116
112
|
end
|
|
117
113
|
|
|
118
114
|
def verify_dependencies
|
|
119
115
|
run_command("#{config[:binary]} >> #{dev_null} 2>&1", quiet: true, use_sudo: config[:use_sudo])
|
|
120
116
|
rescue
|
|
121
|
-
raise UserError,
|
|
117
|
+
raise UserError, "You must first install the Docker CLI tool https://www.docker.com/get-started"
|
|
122
118
|
end
|
|
123
119
|
|
|
124
120
|
def create(state)
|
|
@@ -133,22 +129,20 @@ module Kitchen
|
|
|
133
129
|
|
|
134
130
|
def wait_for_transport(state)
|
|
135
131
|
if config[:wait_for_transport]
|
|
136
|
-
instance.transport.connection(state)
|
|
137
|
-
conn.wait_until_ready
|
|
138
|
-
end
|
|
132
|
+
instance.transport.connection(state, &:wait_until_ready)
|
|
139
133
|
end
|
|
140
134
|
end
|
|
141
135
|
|
|
142
136
|
def default_image
|
|
143
|
-
platform, release = instance.platform.name.split(
|
|
144
|
-
if platform ==
|
|
145
|
-
release =
|
|
137
|
+
platform, release = instance.platform.name.split("-")
|
|
138
|
+
if platform == "centos" && release
|
|
139
|
+
release = "centos" + release.split(".").first
|
|
146
140
|
end
|
|
147
|
-
release ? [platform, release].join(
|
|
141
|
+
release ? [platform, release].join(":") : platform
|
|
148
142
|
end
|
|
149
143
|
|
|
150
144
|
def default_platform
|
|
151
|
-
instance.platform.name.split(
|
|
145
|
+
instance.platform.name.split("-").first
|
|
152
146
|
end
|
|
153
147
|
|
|
154
148
|
protected
|
|
@@ -11,25 +11,24 @@
|
|
|
11
11
|
# See the License for the specific language governing permissions and
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
|
|
14
|
-
require
|
|
14
|
+
require "kitchen"
|
|
15
15
|
|
|
16
|
-
require_relative
|
|
17
|
-
require_relative
|
|
16
|
+
require_relative "../docker/container/linux"
|
|
17
|
+
require_relative "../docker/container/windows"
|
|
18
18
|
|
|
19
|
-
require_relative
|
|
19
|
+
require_relative "../docker/helpers/inspec_helper"
|
|
20
20
|
|
|
21
|
-
require_relative
|
|
22
|
-
require_relative '../../train/docker.rb'
|
|
21
|
+
# require_relative "../../docker/version"
|
|
23
22
|
|
|
24
23
|
module Kitchen
|
|
25
24
|
module Transport
|
|
26
25
|
class Docker < Kitchen::Transport::Base
|
|
27
26
|
class DockerFailed < TransportFailed; end
|
|
28
27
|
|
|
29
|
-
kitchen_transport_api_version 1
|
|
28
|
+
# kitchen_transport_api_version 1
|
|
30
29
|
plugin_version Kitchen::VERSION
|
|
31
30
|
|
|
32
|
-
default_config :binary,
|
|
31
|
+
default_config :binary, "docker"
|
|
33
32
|
default_config :env_variables, nil
|
|
34
33
|
default_config :interactive, false
|
|
35
34
|
default_config :privileged, false
|
|
@@ -42,16 +41,16 @@ module Kitchen
|
|
|
42
41
|
default_config :working_dir, nil
|
|
43
42
|
|
|
44
43
|
default_config :socket do |transport|
|
|
45
|
-
socket =
|
|
46
|
-
socket =
|
|
47
|
-
ENV[
|
|
44
|
+
socket = "unix:///var/run/docker.sock"
|
|
45
|
+
socket = "npipe:////./pipe/docker_engine" if Gem.win_platform?
|
|
46
|
+
ENV["DOCKER_HOST"] || socket
|
|
48
47
|
end
|
|
49
48
|
|
|
50
49
|
default_config :temp_dir do |transport|
|
|
51
50
|
if transport.windows_os?
|
|
52
|
-
|
|
51
|
+
"$env:TEMP"
|
|
53
52
|
else
|
|
54
|
-
|
|
53
|
+
"/tmp"
|
|
55
54
|
end
|
|
56
55
|
end
|
|
57
56
|
|
|
@@ -61,7 +60,7 @@ module Kitchen
|
|
|
61
60
|
if transport.windows_os?
|
|
62
61
|
nil
|
|
63
62
|
else
|
|
64
|
-
|
|
63
|
+
"kitchen"
|
|
65
64
|
end
|
|
66
65
|
end
|
|
67
66
|
|
|
@@ -73,7 +72,7 @@ module Kitchen
|
|
|
73
72
|
# This allows Windows systems to use the TCP socket for the InSpec verifier
|
|
74
73
|
# See the lib/docker.rb file here: https://github.com/swipely/docker-api/blob/master/lib/docker.rb
|
|
75
74
|
# default_socket_url is set to a Unix socket and env_url requires an environment variable to be set
|
|
76
|
-
ENV[
|
|
75
|
+
ENV["DOCKER_HOST"] = options[:socket] if !options[:socket].nil? && ENV["DOCKER_HOST"].nil?
|
|
77
76
|
|
|
78
77
|
Kitchen::Transport::Docker::Connection.new(options, &block)
|
|
79
78
|
end
|
|
@@ -98,7 +97,7 @@ module Kitchen
|
|
|
98
97
|
end
|
|
99
98
|
|
|
100
99
|
def container
|
|
101
|
-
@container ||= if @options[:platform].include?(
|
|
100
|
+
@container ||= if @options[:platform].include?("windows")
|
|
102
101
|
Kitchen::Docker::Container::Windows.new(@options)
|
|
103
102
|
else
|
|
104
103
|
Kitchen::Docker::Container::Linux.new(@options)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"packages": {
|
|
3
|
+
".": {
|
|
4
|
+
"package-name": "kitchen-docker",
|
|
5
|
+
"changelog-path": "CHANGELOG.md",
|
|
6
|
+
"release-type": "ruby",
|
|
7
|
+
"include-component-in-tag": false,
|
|
8
|
+
"version-file": "lib/kitchen/docker/docker_version.rb"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
|
|
12
|
+
}
|
data/renovate.json
ADDED
data/spec/docker_spec.rb
ADDED
|
@@ -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
|