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,13 +11,13 @@
|
|
|
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
|
|
14
|
+
require "base64" unless defined?(Base64)
|
|
15
|
+
require "openssl" unless defined?(OpenSSL)
|
|
16
|
+
require "securerandom" unless defined?(SecureRandom)
|
|
17
|
+
require "shellwords" unless defined?(Shellwords)
|
|
18
18
|
|
|
19
|
-
require_relative
|
|
20
|
-
require_relative
|
|
19
|
+
require_relative "../container"
|
|
20
|
+
require_relative "../helpers/dockerfile_helper"
|
|
21
21
|
|
|
22
22
|
module Kitchen
|
|
23
23
|
module Docker
|
|
@@ -34,7 +34,7 @@ module Kitchen
|
|
|
34
34
|
def create(state)
|
|
35
35
|
super
|
|
36
36
|
|
|
37
|
-
debug(
|
|
37
|
+
debug("Creating Linux container")
|
|
38
38
|
generate_keys
|
|
39
39
|
|
|
40
40
|
state[:ssh_key] = @config[:private_key]
|
|
@@ -58,7 +58,7 @@ module Kitchen
|
|
|
58
58
|
debug("Uploading temp file #{temp_file} to #{remote_path} on container")
|
|
59
59
|
upload(temp_file, remote_path)
|
|
60
60
|
|
|
61
|
-
debug(
|
|
61
|
+
debug("Deleting temp file from local filesystem")
|
|
62
62
|
::File.delete(temp_file)
|
|
63
63
|
|
|
64
64
|
# Replace any environment variables used in the path and execute script file
|
|
@@ -76,13 +76,13 @@ module Kitchen
|
|
|
76
76
|
MUTEX_FOR_SSH_KEYS.synchronize do
|
|
77
77
|
if !File.exist?(@config[:public_key]) || !File.exist?(@config[:private_key])
|
|
78
78
|
private_key = OpenSSL::PKey::RSA.new(2048)
|
|
79
|
-
blobbed_key = Base64.encode64(private_key.to_blob).gsub("\n",
|
|
79
|
+
blobbed_key = Base64.encode64(private_key.to_blob).gsub("\n", "")
|
|
80
80
|
public_key = "ssh-rsa #{blobbed_key} kitchen_docker_key"
|
|
81
|
-
File.open(@config[:private_key],
|
|
81
|
+
File.open(@config[:private_key], "w") do |file|
|
|
82
82
|
file.write(private_key)
|
|
83
83
|
file.chmod(0600)
|
|
84
84
|
end
|
|
85
|
-
File.open(@config[:public_key],
|
|
85
|
+
File.open(@config[:public_key], "w") do |file|
|
|
86
86
|
file.write(public_key)
|
|
87
87
|
file.chmod(0600)
|
|
88
88
|
end
|
|
@@ -91,7 +91,7 @@ module Kitchen
|
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
def parse_container_ssh_port(output)
|
|
94
|
-
_host, port = output.split(
|
|
94
|
+
_host, port = output.split(":")
|
|
95
95
|
port.to_i
|
|
96
96
|
rescue => e
|
|
97
97
|
raise ActionFailed, "Could not parse Docker port output for container SSH port. #{e}"
|
|
@@ -113,10 +113,10 @@ module Kitchen
|
|
|
113
113
|
platform = dockerfile_platform
|
|
114
114
|
username = @config[:username]
|
|
115
115
|
public_key = IO.read(@config[:public_key]).strip
|
|
116
|
-
homedir = username ==
|
|
116
|
+
homedir = username == "root" ? "/root" : "/home/#{username}"
|
|
117
117
|
base = dockerfile_base_linux(username, homedir)
|
|
118
118
|
|
|
119
|
-
custom =
|
|
119
|
+
custom = ""
|
|
120
120
|
Array(@config[:provision_command]).each do |cmd|
|
|
121
121
|
custom << "RUN #{cmd}\n"
|
|
122
122
|
end
|
|
@@ -124,10 +124,10 @@ module Kitchen
|
|
|
124
124
|
ssh_key = "RUN echo #{Shellwords.escape(public_key)} >> #{homedir}/.ssh/authorized_keys"
|
|
125
125
|
|
|
126
126
|
# Empty string to ensure the file ends with a newline.
|
|
127
|
-
output = [from, dockerfile_proxy_config, platform, base, custom, ssh_key,
|
|
128
|
-
debug(
|
|
127
|
+
output = [from, dockerfile_proxy_config, platform, base, custom, ssh_key, ""].join("\n")
|
|
128
|
+
debug("--- Start Dockerfile ---")
|
|
129
129
|
debug(output.strip)
|
|
130
|
-
debug(
|
|
130
|
+
debug("--- End Dockerfile ---")
|
|
131
131
|
output
|
|
132
132
|
end
|
|
133
133
|
end
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
# See the License for the specific language governing permissions and
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
|
|
14
|
-
require
|
|
14
|
+
require "securerandom" unless defined?(SecureRandom)
|
|
15
15
|
|
|
16
|
-
require_relative
|
|
16
|
+
require_relative "../container"
|
|
17
17
|
|
|
18
18
|
module Kitchen
|
|
19
19
|
module Docker
|
|
@@ -26,7 +26,7 @@ module Kitchen
|
|
|
26
26
|
def create(state)
|
|
27
27
|
super
|
|
28
28
|
|
|
29
|
-
debug(
|
|
29
|
+
debug("Creating Windows container")
|
|
30
30
|
state[:username] = @config[:username]
|
|
31
31
|
state[:image_id] = build_image(state, dockerfile) unless state[:image_id]
|
|
32
32
|
state[:container_id] = run_container(state) unless state[:container_id]
|
|
@@ -35,19 +35,19 @@ module Kitchen
|
|
|
35
35
|
|
|
36
36
|
def execute(command)
|
|
37
37
|
# Create temp script file and upload files to container
|
|
38
|
-
debug(
|
|
38
|
+
debug("Executing command on Windows container")
|
|
39
39
|
filename = "docker-#{::SecureRandom.uuid}.ps1"
|
|
40
40
|
temp_file = ".\\.kitchen\\temp\\#{filename}"
|
|
41
41
|
create_temp_file(temp_file, command)
|
|
42
42
|
|
|
43
|
-
remote_path = @config[:temp_dir].tr(
|
|
43
|
+
remote_path = @config[:temp_dir].tr("/", "\\")
|
|
44
44
|
debug("Creating directory #{remote_path} on container")
|
|
45
45
|
create_dir_on_container(@config, remote_path)
|
|
46
46
|
|
|
47
47
|
debug("Uploading temp file #{temp_file} to #{remote_path} on container")
|
|
48
48
|
upload(temp_file, remote_path)
|
|
49
49
|
|
|
50
|
-
debug(
|
|
50
|
+
debug("Deleting temp file from local filesystem")
|
|
51
51
|
::File.delete(temp_file)
|
|
52
52
|
|
|
53
53
|
# Replace any environment variables used in the path and execute script file
|
|
@@ -63,20 +63,20 @@ module Kitchen
|
|
|
63
63
|
protected
|
|
64
64
|
|
|
65
65
|
def dockerfile
|
|
66
|
-
raise ActionFailed, "Unknown platform '#{@config[:platform]}'" unless @config[:platform] ==
|
|
66
|
+
raise ActionFailed, "Unknown platform '#{@config[:platform]}'" unless @config[:platform] == "windows"
|
|
67
67
|
return dockerfile_template if @config[:dockerfile]
|
|
68
68
|
|
|
69
69
|
from = "FROM #{@config[:image]}"
|
|
70
70
|
|
|
71
|
-
custom =
|
|
71
|
+
custom = ""
|
|
72
72
|
Array(@config[:provision_command]).each do |cmd|
|
|
73
73
|
custom << "RUN #{cmd}\n"
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
output = [from, dockerfile_proxy_config, custom,
|
|
77
|
-
debug(
|
|
76
|
+
output = [from, dockerfile_proxy_config, custom, ""].join("\n")
|
|
77
|
+
debug("--- Start Dockerfile ---")
|
|
78
78
|
debug(output.strip)
|
|
79
|
-
debug(
|
|
79
|
+
debug("--- End Dockerfile ---")
|
|
80
80
|
output
|
|
81
81
|
end
|
|
82
82
|
end
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
# See the License for the specific language governing permissions and
|
|
12
12
|
# limitations under the License.
|
|
13
13
|
|
|
14
|
-
require_relative
|
|
15
|
-
require_relative
|
|
16
|
-
require_relative
|
|
17
|
-
require_relative
|
|
14
|
+
require_relative "helpers/cli_helper"
|
|
15
|
+
require_relative "helpers/container_helper"
|
|
16
|
+
require_relative "helpers/file_helper"
|
|
17
|
+
require_relative "helpers/image_helper"
|
|
18
18
|
|
|
19
19
|
module Kitchen
|
|
20
20
|
module Docker
|
|
@@ -32,8 +32,8 @@ module Kitchen
|
|
|
32
32
|
if container_exists?(state)
|
|
33
33
|
info("Container ID #{state[:container_id]} already exists.")
|
|
34
34
|
elsif !container_exists?(state) && state[:container_id]
|
|
35
|
-
raise ActionFailed, "Container ID #{state[:container_id]} was found in the kitchen state data, "\
|
|
36
|
-
|
|
35
|
+
raise ActionFailed, "Container ID #{state[:container_id]} was found in the kitchen state data, " \
|
|
36
|
+
"but the container does not exist."
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
state[:username] = @config[:username]
|
|
@@ -49,7 +49,7 @@ module Kitchen
|
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def hostname(state)
|
|
52
|
-
hostname =
|
|
52
|
+
hostname = "localhost"
|
|
53
53
|
|
|
54
54
|
if remote_socket?
|
|
55
55
|
hostname = socket_uri.host
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
# See the License for the specific language governing permissions and
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
|
|
16
|
-
require
|
|
16
|
+
require "erb" unless defined?(Erb)
|
|
17
17
|
|
|
18
18
|
module Kitchen
|
|
19
19
|
module Docker
|
|
20
20
|
class ERBContext
|
|
21
|
-
def initialize(config={})
|
|
21
|
+
def initialize(config = {})
|
|
22
22
|
config.each do |key, value|
|
|
23
|
-
instance_variable_set(
|
|
23
|
+
instance_variable_set("@" + key.to_s, value)
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -11,10 +11,10 @@
|
|
|
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
|
|
14
|
+
require "kitchen"
|
|
15
|
+
require "kitchen/configurable"
|
|
16
|
+
require "kitchen/logging"
|
|
17
|
+
require "kitchen/shell_out"
|
|
18
18
|
|
|
19
19
|
module Kitchen
|
|
20
20
|
module Docker
|
|
@@ -26,11 +26,11 @@ module Kitchen
|
|
|
26
26
|
include ShellOut
|
|
27
27
|
|
|
28
28
|
# rubocop:disable Metrics/AbcSize
|
|
29
|
-
def docker_command(cmd, options={})
|
|
29
|
+
def docker_command(cmd, options = {})
|
|
30
30
|
docker = config[:binary].dup
|
|
31
31
|
docker << " -H #{config[:socket]}" if config[:socket]
|
|
32
|
-
docker <<
|
|
33
|
-
docker <<
|
|
32
|
+
docker << " --tls" if config[:tls]
|
|
33
|
+
docker << " --tlsverify" if config[:tls_verify]
|
|
34
34
|
docker << " --tlscacert=#{config[:tls_cacert]}" if config[:tls_cacert]
|
|
35
35
|
docker << " --tlscert=#{config[:tls_cert]}" if config[:tls_cert]
|
|
36
36
|
docker << " --tlskey=#{config[:tls_key]}" if config[:tls_key]
|
|
@@ -63,9 +63,9 @@ module Kitchen
|
|
|
63
63
|
|
|
64
64
|
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/AbcSize
|
|
65
65
|
def build_run_command(image_id, transport_port = nil)
|
|
66
|
-
cmd =
|
|
67
|
-
cmd <<
|
|
68
|
-
cmd <<
|
|
66
|
+
cmd = "run -d"
|
|
67
|
+
cmd << " -i" if config[:interactive]
|
|
68
|
+
cmd << " -t" if config[:tty]
|
|
69
69
|
cmd << build_env_variable_args(config[:env_variables]) if config[:env_variables]
|
|
70
70
|
cmd << " -p #{transport_port}" unless transport_port.nil?
|
|
71
71
|
Array(config[:forward]).each { |port| cmd << " -p #{port}" }
|
|
@@ -75,21 +75,21 @@ module Kitchen
|
|
|
75
75
|
Array(config[:volumes_from]).each { |container| cmd << " --volumes-from #{container}" }
|
|
76
76
|
Array(config[:links]).each { |link| cmd << " --link #{link}" }
|
|
77
77
|
Array(config[:devices]).each { |device| cmd << " --device #{device}" }
|
|
78
|
-
Array(config[:mount]).each {|mount| cmd << " --mount #{mount}"}
|
|
79
|
-
Array(config[:tmpfs]).each {|tmpfs| cmd << " --tmpfs #{tmpfs}"}
|
|
78
|
+
Array(config[:mount]).each { |mount| cmd << " --mount #{mount}" }
|
|
79
|
+
Array(config[:tmpfs]).each { |tmpfs| cmd << " --tmpfs #{tmpfs}" }
|
|
80
80
|
cmd << " --name #{config[:instance_name]}" if config[:instance_name]
|
|
81
|
-
cmd <<
|
|
81
|
+
cmd << " -P" if config[:publish_all]
|
|
82
82
|
cmd << " -h #{config[:hostname]}" if config[:hostname]
|
|
83
83
|
cmd << " -m #{config[:memory]}" if config[:memory]
|
|
84
84
|
cmd << " -c #{config[:cpu]}" if config[:cpu]
|
|
85
85
|
cmd << " --gpus #{config[:gpus]}" if config[:gpus]
|
|
86
86
|
cmd << " -e http_proxy=#{config[:http_proxy]}" if config[:http_proxy]
|
|
87
87
|
cmd << " -e https_proxy=#{config[:https_proxy]}" if config[:https_proxy]
|
|
88
|
-
cmd <<
|
|
88
|
+
cmd << " --privileged" if config[:privileged]
|
|
89
89
|
cmd << " --isolation #{config[:isolation]}" if config[:isolation]
|
|
90
|
-
Array(config[:cap_add]).each { |cap| cmd << " --cap-add=#{cap}"} if config[:cap_add]
|
|
91
|
-
Array(config[:cap_drop]).each { |cap| cmd << " --cap-drop=#{cap}"} if config[:cap_drop]
|
|
92
|
-
Array(config[:security_opt]).each { |opt| cmd << " --security-opt=#{opt}"} if config[:security_opt]
|
|
90
|
+
Array(config[:cap_add]).each { |cap| cmd << " --cap-add=#{cap}" } if config[:cap_add]
|
|
91
|
+
Array(config[:cap_drop]).each { |cap| cmd << " --cap-drop=#{cap}" } if config[:cap_drop]
|
|
92
|
+
Array(config[:security_opt]).each { |opt| cmd << " --security-opt=#{opt}" } if config[:security_opt]
|
|
93
93
|
cmd << " --platform=#{config[:docker_platform]}" if config[:docker_platform]
|
|
94
94
|
extra_run_options = config_to_options(config[:run_options])
|
|
95
95
|
cmd << " #{extra_run_options}" unless extra_run_options.empty?
|
|
@@ -101,12 +101,12 @@ module Kitchen
|
|
|
101
101
|
|
|
102
102
|
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/AbcSize
|
|
103
103
|
def build_exec_command(state, command)
|
|
104
|
-
cmd =
|
|
105
|
-
cmd <<
|
|
104
|
+
cmd = "exec"
|
|
105
|
+
cmd << " -d" if config[:detach]
|
|
106
106
|
cmd << build_env_variable_args(config[:env_variables]) if config[:env_variables]
|
|
107
|
-
cmd <<
|
|
108
|
-
cmd <<
|
|
109
|
-
cmd <<
|
|
107
|
+
cmd << " --privileged" if config[:privileged]
|
|
108
|
+
cmd << " -t" if config[:tty]
|
|
109
|
+
cmd << " -i" if config[:interactive]
|
|
110
110
|
cmd << " -u #{config[:username]}" if config[:username]
|
|
111
111
|
cmd << " -w #{config[:working_dir]}" if config[:working_dir]
|
|
112
112
|
cmd << " #{state[:container_id]}"
|
|
@@ -117,23 +117,23 @@ module Kitchen
|
|
|
117
117
|
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/AbcSize
|
|
118
118
|
|
|
119
119
|
def build_copy_command(local_file, remote_file, opts = {})
|
|
120
|
-
cmd =
|
|
121
|
-
cmd <<
|
|
120
|
+
cmd = "cp"
|
|
121
|
+
cmd << " -a" if opts[:archive]
|
|
122
122
|
cmd << " #{local_file} #{remote_file}"
|
|
123
123
|
cmd
|
|
124
124
|
end
|
|
125
125
|
|
|
126
126
|
def build_powershell_command(args)
|
|
127
|
-
cmd =
|
|
127
|
+
cmd = "powershell -ExecutionPolicy Bypass -NoLogo "
|
|
128
128
|
cmd << args
|
|
129
129
|
logger.debug("build_powershell_command: #{cmd}")
|
|
130
130
|
cmd
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
def build_env_variable_args(vars)
|
|
134
|
-
raise ActionFailed,
|
|
134
|
+
raise ActionFailed, "Environment variables are not of a Hash type" unless vars.is_a?(Hash)
|
|
135
135
|
|
|
136
|
-
args =
|
|
136
|
+
args = ""
|
|
137
137
|
vars.each do |k, v|
|
|
138
138
|
args << " -e #{k.to_s.strip}=\"#{v.to_s.strip}\""
|
|
139
139
|
end
|
|
@@ -142,11 +142,11 @@ module Kitchen
|
|
|
142
142
|
end
|
|
143
143
|
|
|
144
144
|
def dev_null
|
|
145
|
-
case RbConfig::CONFIG[
|
|
145
|
+
case RbConfig::CONFIG["host_os"]
|
|
146
146
|
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
|
147
|
-
|
|
147
|
+
"NUL"
|
|
148
148
|
else
|
|
149
|
-
|
|
149
|
+
"/dev/null"
|
|
150
150
|
end
|
|
151
151
|
end
|
|
152
152
|
|
|
@@ -167,13 +167,13 @@ module Kitchen
|
|
|
167
167
|
def config_to_options(config)
|
|
168
168
|
case config
|
|
169
169
|
when nil
|
|
170
|
-
|
|
170
|
+
""
|
|
171
171
|
when String
|
|
172
172
|
config
|
|
173
173
|
when Array
|
|
174
|
-
config.map { |c| config_to_options(c) }.join(
|
|
174
|
+
config.map { |c| config_to_options(c) }.join(" ")
|
|
175
175
|
when Hash
|
|
176
|
-
config.map { |k, v| Array(v).map { |c| "--#{k}=#{Shellwords.escape(c)}" }.join(
|
|
176
|
+
config.map { |k, v| Array(v).map { |c| "--#{k}=#{Shellwords.escape(c)}" }.join(" ") }.join(" ")
|
|
177
177
|
end
|
|
178
178
|
end
|
|
179
179
|
# rubocop:enable Metrics/CyclomaticComplexity
|
|
@@ -11,16 +11,16 @@
|
|
|
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
|
|
18
|
-
require
|
|
14
|
+
require "erb" unless defined?(Erb)
|
|
15
|
+
require "json" unless defined?(JSON)
|
|
16
|
+
require "shellwords" unless defined?(Shellwords)
|
|
17
|
+
require "tempfile" unless defined?(Tempfile)
|
|
18
|
+
require "uri" unless defined?(URI)
|
|
19
19
|
|
|
20
|
-
require
|
|
21
|
-
require
|
|
22
|
-
require_relative
|
|
23
|
-
require_relative
|
|
20
|
+
require "kitchen"
|
|
21
|
+
require "kitchen/configurable"
|
|
22
|
+
require_relative "../erb_context"
|
|
23
|
+
require_relative "cli_helper"
|
|
24
24
|
|
|
25
25
|
module Kitchen
|
|
26
26
|
module Docker
|
|
@@ -34,7 +34,7 @@ module Kitchen
|
|
|
34
34
|
container_id = output.chomp
|
|
35
35
|
|
|
36
36
|
unless [12, 64].include?(container_id.size)
|
|
37
|
-
raise ActionFailed,
|
|
37
|
+
raise ActionFailed, "Could not parse Docker run output for container ID"
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
container_id
|
|
@@ -47,7 +47,7 @@ module Kitchen
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def remote_socket?
|
|
50
|
-
config[:socket] ? socket_uri.scheme ==
|
|
50
|
+
config[:socket] ? socket_uri.scheme == "tcp" : false
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def socket_uri
|
|
@@ -73,8 +73,8 @@ module Kitchen
|
|
|
73
73
|
path = replace_env_variables(state, path)
|
|
74
74
|
cmd = "mkdir -p #{path}"
|
|
75
75
|
|
|
76
|
-
if state[:platform].include?(
|
|
77
|
-
psh = "-Command if(-not (Test-Path
|
|
76
|
+
if state[:platform].include?("windows")
|
|
77
|
+
psh = "-Command if(-not (Test-Path '#{path}')) { New-Item -Path '#{path}' -Force }"
|
|
78
78
|
cmd = build_powershell_command(psh)
|
|
79
79
|
end
|
|
80
80
|
|
|
@@ -101,15 +101,15 @@ module Kitchen
|
|
|
101
101
|
# Retrieves all environment variables from inside container
|
|
102
102
|
vars = {}
|
|
103
103
|
|
|
104
|
-
if state[:platform].include?(
|
|
105
|
-
cmd = build_powershell_command(
|
|
104
|
+
if state[:platform].include?("windows")
|
|
105
|
+
cmd = build_powershell_command("-Command [System.Environment]::GetEnvironmentVariables() ^| ConvertTo-Json")
|
|
106
106
|
cmd = build_exec_command(state, cmd)
|
|
107
107
|
stdout = docker_command(cmd, suppress_output: !logger.debug?).strip
|
|
108
108
|
vars = ::JSON.parse(stdout)
|
|
109
109
|
else
|
|
110
|
-
cmd = build_exec_command(state,
|
|
110
|
+
cmd = build_exec_command(state, "printenv")
|
|
111
111
|
stdout = docker_command(cmd, suppress_output: !logger.debug?).strip
|
|
112
|
-
stdout.split("\n").each { |line| vars[line.split(
|
|
112
|
+
stdout.split("\n").each { |line| vars[line.split("=")[0]] = line.split("=")[1] }
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
vars
|
|
@@ -117,12 +117,12 @@ module Kitchen
|
|
|
117
117
|
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
118
118
|
|
|
119
119
|
def replace_env_variables(state, str)
|
|
120
|
-
if str.include?(
|
|
120
|
+
if str.include?("$env:")
|
|
121
121
|
key = str[/\$env:(.*?)(\\|$)/, 1]
|
|
122
122
|
value = container_env_variables(state)[key].to_s.strip
|
|
123
123
|
str = str.gsub("$env:#{key}", value)
|
|
124
|
-
elsif str.include?(
|
|
125
|
-
key = str[
|
|
124
|
+
elsif str.include?("$")
|
|
125
|
+
key = str[%r{\$(.*?)(/|$)}, 1]
|
|
126
126
|
value = container_env_variables(state)[key].to_s.strip
|
|
127
127
|
str = str.gsub("$#{key}", value)
|
|
128
128
|
end
|
|
@@ -141,7 +141,7 @@ module Kitchen
|
|
|
141
141
|
cmd << " #{state[:container_id]}"
|
|
142
142
|
docker_command(cmd).strip
|
|
143
143
|
rescue
|
|
144
|
-
raise ActionFailed,
|
|
144
|
+
raise ActionFailed, "Error getting internal IP of Docker container"
|
|
145
145
|
end
|
|
146
146
|
|
|
147
147
|
def remove_container(state)
|
|
@@ -150,25 +150,27 @@ module Kitchen
|
|
|
150
150
|
docker_command("rm #{container_id}")
|
|
151
151
|
end
|
|
152
152
|
|
|
153
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
153
154
|
def dockerfile_proxy_config
|
|
154
|
-
env_variables =
|
|
155
|
+
env_variables = ""
|
|
155
156
|
if config[:http_proxy]
|
|
156
|
-
env_variables << "ENV http_proxy
|
|
157
|
-
env_variables << "ENV HTTP_PROXY
|
|
157
|
+
env_variables << "ENV http_proxy=#{config[:http_proxy]}\n"
|
|
158
|
+
env_variables << "ENV HTTP_PROXY=#{config[:http_proxy]}\n"
|
|
158
159
|
end
|
|
159
160
|
|
|
160
161
|
if config[:https_proxy]
|
|
161
|
-
env_variables << "ENV https_proxy
|
|
162
|
-
env_variables << "ENV HTTPS_PROXY
|
|
162
|
+
env_variables << "ENV https_proxy=#{config[:https_proxy]}\n"
|
|
163
|
+
env_variables << "ENV HTTPS_PROXY=#{config[:https_proxy]}\n"
|
|
163
164
|
end
|
|
164
165
|
|
|
165
166
|
if config[:no_proxy]
|
|
166
|
-
env_variables << "ENV no_proxy
|
|
167
|
-
env_variables << "ENV NO_PROXY
|
|
167
|
+
env_variables << "ENV no_proxy=#{config[:no_proxy]}\n"
|
|
168
|
+
env_variables << "ENV NO_PROXY=#{config[:no_proxy]}\n"
|
|
168
169
|
end
|
|
169
170
|
|
|
170
171
|
env_variables
|
|
171
172
|
end
|
|
173
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
|
172
174
|
end
|
|
173
175
|
# rubocop:enable Metrics/ModuleLength, Style/Documentation
|
|
174
176
|
end
|