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.
- 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 +2 -3
- 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 -30
- data/kitchen.windows.yml +2 -4
- data/kitchen.yml +58 -26
- 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 +33 -33
- data/lib/kitchen/docker/helpers/container_helper.rb +30 -28
- 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/cinc/inspec/cinc_spec.rb +21 -0
- data/test/integration/default/disabled/default_spec.rb +6 -6
- data/test/integration/inspec/inspec_spec.rb +3 -3
- metadata +26 -211
- data/.cane +0 -0
- data/.github/dependabot.yml +0 -7
- data/.github/workflows/ci.yml +0 -124
- data/.tailor +0 -4
- data/lib/docker/version.rb +0 -25
- data/lib/train/docker.rb +0 -125
- data/test/spec/docker_spec.rb +0 -64
|
@@ -11,38 +11,40 @@
|
|
|
11
11
|
# See the License for the specific language governing permissions and
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
|
|
14
|
-
require
|
|
15
|
-
require
|
|
14
|
+
require "kitchen"
|
|
15
|
+
require "kitchen/configurable"
|
|
16
16
|
|
|
17
17
|
module Kitchen
|
|
18
18
|
module Docker
|
|
19
19
|
module Helpers
|
|
20
|
-
module DockerfileHelper
|
|
20
|
+
module DockerfileHelper
|
|
21
21
|
include Configurable
|
|
22
22
|
|
|
23
23
|
def dockerfile_platform
|
|
24
24
|
case config[:platform]
|
|
25
|
-
when
|
|
25
|
+
when "arch"
|
|
26
26
|
arch_platform
|
|
27
|
-
when
|
|
27
|
+
when "debian", "ubuntu"
|
|
28
28
|
debian_platform
|
|
29
|
-
when
|
|
29
|
+
when "fedora"
|
|
30
30
|
fedora_platform
|
|
31
|
-
when
|
|
31
|
+
when "gentoo"
|
|
32
32
|
gentoo_platform
|
|
33
|
-
when
|
|
33
|
+
when "gentoo-paludis"
|
|
34
34
|
gentoo_paludis_platform
|
|
35
|
-
when
|
|
35
|
+
when "opensuse/tumbleweed", "opensuse/leap", "opensuse", "sles"
|
|
36
36
|
opensuse_platform
|
|
37
|
-
when
|
|
37
|
+
when "rhel", "centos", "oraclelinux"
|
|
38
38
|
rhel_platform
|
|
39
|
-
when
|
|
39
|
+
when "amazonlinux"
|
|
40
|
+
amazonlinux_platform
|
|
41
|
+
when "centosstream"
|
|
40
42
|
centosstream_platform
|
|
41
|
-
when
|
|
43
|
+
when "almalinux"
|
|
42
44
|
almalinux_platform
|
|
43
|
-
when
|
|
45
|
+
when "rockylinux"
|
|
44
46
|
rockylinux_platform
|
|
45
|
-
when
|
|
47
|
+
when "photon"
|
|
46
48
|
photonos_platform
|
|
47
49
|
else
|
|
48
50
|
raise ActionFailed, "Unknown platform '#{config[:platform]}'"
|
|
@@ -50,15 +52,11 @@ module Kitchen
|
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
def arch_platform
|
|
53
|
-
# See https://bugs.archlinux.org/task/47052 for why we
|
|
54
|
-
# blank out limits.conf.
|
|
55
55
|
<<-CODE
|
|
56
56
|
RUN pacman --noconfirm -Sy archlinux-keyring
|
|
57
57
|
RUN pacman-db-upgrade
|
|
58
58
|
RUN pacman --noconfirm -Syu openssl openssh sudo curl
|
|
59
59
|
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key
|
|
60
|
-
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
|
|
61
|
-
RUN echo >/etc/security/limits.conf
|
|
62
60
|
CODE
|
|
63
61
|
end
|
|
64
62
|
|
|
@@ -68,8 +66,8 @@ module Kitchen
|
|
|
68
66
|
&& ln -sf /bin/true /sbin/initctl
|
|
69
67
|
CODE
|
|
70
68
|
packages = <<-CODE
|
|
71
|
-
ENV DEBIAN_FRONTEND
|
|
72
|
-
ENV container
|
|
69
|
+
ENV DEBIAN_FRONTEND=noninteractive
|
|
70
|
+
ENV container=docker
|
|
73
71
|
RUN apt-get update
|
|
74
72
|
RUN apt-get install -y sudo openssh-server curl lsb-release
|
|
75
73
|
CODE
|
|
@@ -78,11 +76,10 @@ module Kitchen
|
|
|
78
76
|
|
|
79
77
|
def fedora_platform
|
|
80
78
|
<<-CODE
|
|
81
|
-
ENV container
|
|
79
|
+
ENV container=docker
|
|
82
80
|
RUN dnf clean all
|
|
83
81
|
RUN dnf install -y sudo openssh-server openssh-clients which curl
|
|
84
82
|
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
|
|
85
|
-
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
|
|
86
83
|
CODE
|
|
87
84
|
end
|
|
88
85
|
|
|
@@ -91,7 +88,6 @@ module Kitchen
|
|
|
91
88
|
RUN emerge-webrsync
|
|
92
89
|
RUN emerge --quiet --noreplace net-misc/openssh app-admin/sudo
|
|
93
90
|
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key
|
|
94
|
-
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
|
|
95
91
|
CODE
|
|
96
92
|
end
|
|
97
93
|
|
|
@@ -100,13 +96,12 @@ module Kitchen
|
|
|
100
96
|
RUN cave sync
|
|
101
97
|
RUN cave resolve -zx net-misc/openssh app-admin/sudo
|
|
102
98
|
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key
|
|
103
|
-
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
|
|
104
99
|
CODE
|
|
105
100
|
end
|
|
106
101
|
|
|
107
102
|
def opensuse_platform
|
|
108
103
|
<<-CODE
|
|
109
|
-
ENV container
|
|
104
|
+
ENV container=docker
|
|
110
105
|
RUN zypper install -y sudo openssh which curl gawk
|
|
111
106
|
RUN /usr/sbin/sshd-gen-keys-start
|
|
112
107
|
CODE
|
|
@@ -114,47 +109,52 @@ module Kitchen
|
|
|
114
109
|
|
|
115
110
|
def rhel_platform
|
|
116
111
|
<<-CODE
|
|
117
|
-
ENV container
|
|
112
|
+
ENV container=docker
|
|
118
113
|
RUN yum clean all
|
|
119
114
|
RUN yum install -y sudo openssh-server openssh-clients which curl
|
|
120
115
|
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
|
|
121
|
-
|
|
116
|
+
CODE
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def amazonlinux_platform
|
|
120
|
+
<<-CODE
|
|
121
|
+
ENV container=docker
|
|
122
|
+
RUN yum clean all
|
|
123
|
+
RUN yum install -y --allowerasing sudo openssh-server openssh-clients which curl
|
|
124
|
+
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
|
|
122
125
|
CODE
|
|
123
126
|
end
|
|
124
127
|
|
|
125
128
|
def centosstream_platform
|
|
126
129
|
<<-CODE
|
|
127
|
-
ENV container
|
|
130
|
+
ENV container=docker
|
|
128
131
|
RUN yum clean all
|
|
129
132
|
RUN yum install -y sudo openssh-server openssh-clients which
|
|
130
133
|
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
|
|
131
|
-
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
|
|
132
134
|
CODE
|
|
133
135
|
end
|
|
134
136
|
|
|
135
137
|
def almalinux_platform
|
|
136
138
|
<<-CODE
|
|
137
|
-
ENV container
|
|
139
|
+
ENV container=docker
|
|
138
140
|
RUN yum clean all
|
|
139
141
|
RUN yum install -y sudo openssh-server openssh-clients which
|
|
140
142
|
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
|
|
141
|
-
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
|
|
142
143
|
CODE
|
|
143
144
|
end
|
|
144
145
|
|
|
145
146
|
def rockylinux_platform
|
|
146
147
|
<<-CODE
|
|
147
|
-
ENV container
|
|
148
|
+
ENV container=docker
|
|
148
149
|
RUN yum clean all
|
|
149
150
|
RUN yum install -y sudo openssh-server openssh-clients which
|
|
150
151
|
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
|
|
151
|
-
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
|
|
152
152
|
CODE
|
|
153
153
|
end
|
|
154
154
|
|
|
155
155
|
def photonos_platform
|
|
156
156
|
<<-CODE
|
|
157
|
-
ENV container
|
|
157
|
+
ENV container=docker
|
|
158
158
|
RUN tdnf clean all
|
|
159
159
|
RUN tdnf install -y sudo openssh-server openssh-clients which curl
|
|
160
160
|
RUN [ -f "/etc/ssh/ssh_host_ecdsa_key" ] || ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
# See the License for the specific language governing permissions and
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
|
|
14
|
-
require
|
|
14
|
+
require "fileutils" unless defined?(FileUtils)
|
|
15
15
|
|
|
16
16
|
module Kitchen
|
|
17
17
|
module Docker
|
|
@@ -19,14 +19,14 @@ module Kitchen
|
|
|
19
19
|
module FileHelper
|
|
20
20
|
def create_temp_file(file, contents)
|
|
21
21
|
debug("[Docker] Creating temp file #{file}")
|
|
22
|
-
debug(
|
|
22
|
+
debug("[Docker] --- Start Temp File Contents ---")
|
|
23
23
|
debug(contents)
|
|
24
|
-
debug(
|
|
24
|
+
debug("[Docker] --- End Temp File Contents ---")
|
|
25
25
|
|
|
26
26
|
begin
|
|
27
27
|
path = ::File.dirname(file)
|
|
28
28
|
::FileUtils.mkdir_p(path) unless ::Dir.exist?(path)
|
|
29
|
-
file = ::File.open(file,
|
|
29
|
+
file = ::File.open(file, "w")
|
|
30
30
|
file.write(contents)
|
|
31
31
|
rescue IOError => e
|
|
32
32
|
raise "Failed to write temp file. Error Details: #{e}"
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
# See the License for the specific language governing permissions and
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
|
|
14
|
-
require
|
|
15
|
-
require
|
|
16
|
-
require
|
|
17
|
-
require_relative
|
|
18
|
-
require_relative
|
|
14
|
+
require "kitchen"
|
|
15
|
+
require "kitchen/configurable"
|
|
16
|
+
require "pathname" unless defined?(Pathname)
|
|
17
|
+
require_relative "cli_helper"
|
|
18
|
+
require_relative "container_helper"
|
|
19
19
|
|
|
20
20
|
module Kitchen
|
|
21
21
|
module Docker
|
|
@@ -28,38 +28,52 @@ module Kitchen
|
|
|
28
28
|
def parse_image_id(output)
|
|
29
29
|
output.split("\n").reverse_each do |line|
|
|
30
30
|
if line =~ /writing image (sha256:[[:xdigit:]]{64})(?: \d*\.\ds)? done/i
|
|
31
|
-
img_id = line[/writing image (sha256:[[:xdigit:]]{64})(?: \d*\.\ds)? done/i,1]
|
|
31
|
+
img_id = line[/writing image (sha256:[[:xdigit:]]{64})(?: \d*\.\ds)? done/i, 1]
|
|
32
32
|
return img_id
|
|
33
33
|
end
|
|
34
34
|
if line =~ /image id|build successful|successfully built/i
|
|
35
35
|
img_id = line.split(/\s+/).last
|
|
36
36
|
return img_id
|
|
37
37
|
end
|
|
38
|
+
# Docker ~v4.31 support
|
|
39
|
+
if line =~ /naming to moby-dangling@(sha256:[[:xdigit:]]{64})(?: \d*\.\ds)? done/i
|
|
40
|
+
img_id = line[/naming to moby-dangling@(sha256:[[:xdigit:]]{64})(?: \d*\.\ds)? done/i, 1]
|
|
41
|
+
return img_id
|
|
42
|
+
end
|
|
38
43
|
end
|
|
39
|
-
raise ActionFailed,
|
|
44
|
+
raise ActionFailed, "Could not parse Docker build output for image ID"
|
|
40
45
|
end
|
|
41
46
|
|
|
42
47
|
def remove_image(state)
|
|
43
48
|
image_id = state[:image_id]
|
|
44
|
-
|
|
49
|
+
if image_in_use?(state)
|
|
50
|
+
info("[Docker] Image ID #{image_id} is in use. Skipping removal")
|
|
51
|
+
else
|
|
52
|
+
info("[Docker] Removing image with Image ID #{image_id}.")
|
|
53
|
+
docker_command("rmi #{image_id}")
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def image_in_use?(state)
|
|
58
|
+
docker_command("ps -a", suppress_output: !logger.debug?).include?(state[:image_id])
|
|
45
59
|
end
|
|
46
60
|
|
|
47
61
|
def build_image(state, dockerfile)
|
|
48
|
-
cmd =
|
|
49
|
-
cmd <<
|
|
62
|
+
cmd = "build"
|
|
63
|
+
cmd << " --no-cache" unless config[:use_cache]
|
|
50
64
|
cmd << " --platform=#{config[:docker_platform]}" if config[:docker_platform]
|
|
51
65
|
extra_build_options = config_to_options(config[:build_options])
|
|
52
66
|
cmd << " #{extra_build_options}" unless extra_build_options.empty?
|
|
53
67
|
dockerfile_contents = dockerfile
|
|
54
|
-
file = Tempfile.new(
|
|
68
|
+
file = Tempfile.new("Dockerfile-kitchen", Pathname.pwd + config[:build_tempdir])
|
|
55
69
|
cmd << " -f #{Shellwords.escape(dockerfile_path(file))}" if config[:build_context]
|
|
56
|
-
build_context = config[:build_context] ?
|
|
70
|
+
build_context = config[:build_context] ? "." : "-"
|
|
57
71
|
output = begin
|
|
58
72
|
file.write(dockerfile)
|
|
59
73
|
file.close
|
|
60
74
|
docker_command("#{cmd} #{build_context}",
|
|
61
|
-
|
|
62
|
-
|
|
75
|
+
input: dockerfile_contents,
|
|
76
|
+
environment: { BUILDKIT_PROGRESS: "plain" })
|
|
63
77
|
ensure
|
|
64
78
|
file.close unless file.closed?
|
|
65
79
|
file.unlink
|
|
@@ -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
|
+
}
|