kitchen-docker 2.6.0 → 2.11.0
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 +5 -5
- data/.github/dependabot.yml +7 -0
- data/.gitignore +2 -0
- data/.kitchen.windows.yml +33 -0
- data/.kitchen.yml +21 -9
- data/.travis.yml +54 -19
- data/CHANGELOG.md +41 -0
- data/README.md +138 -18
- data/docker.ps1 +9 -0
- data/kitchen-docker.gemspec +5 -6
- data/lib/docker/version.rb +25 -0
- data/lib/kitchen/docker/container.rb +75 -0
- data/lib/kitchen/docker/container/linux.rb +136 -0
- data/lib/kitchen/docker/container/windows.rb +85 -0
- data/lib/kitchen/{driver → docker}/docker_version.rb +2 -5
- data/lib/kitchen/{driver/docker/erb.rb → docker/erb_context.rb} +2 -5
- data/lib/kitchen/docker/helpers/cli_helper.rb +151 -0
- data/lib/kitchen/docker/helpers/container_helper.rb +172 -0
- data/lib/kitchen/docker/helpers/dockerfile_helper.rb +136 -0
- data/lib/kitchen/docker/helpers/file_helper.rb +40 -0
- data/lib/kitchen/docker/helpers/image_helper.rb +70 -0
- data/lib/kitchen/docker/helpers/inspec_helper.rb +40 -0
- data/lib/kitchen/driver/docker.rb +77 -327
- data/lib/kitchen/transport/docker.rb +111 -0
- data/lib/train/docker.rb +125 -0
- data/test/integration/default/serverspec/default_spec.rb +1 -1
- data/test/integration/default/serverspec/spec_helper.rb +21 -0
- data/test/integration/inspec/inspec_spec.rb +8 -2
- metadata +48 -12
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
require 'kitchen'
|
|
15
|
+
|
|
16
|
+
require_relative '../docker/container/linux'
|
|
17
|
+
require_relative '../docker/container/windows'
|
|
18
|
+
|
|
19
|
+
require_relative '../docker/helpers/inspec_helper'
|
|
20
|
+
|
|
21
|
+
require_relative '../../docker/version.rb'
|
|
22
|
+
require_relative '../../train/docker.rb'
|
|
23
|
+
|
|
24
|
+
module Kitchen
|
|
25
|
+
module Transport
|
|
26
|
+
class Docker < Kitchen::Transport::Base
|
|
27
|
+
class DockerFailed < TransportFailed; end
|
|
28
|
+
|
|
29
|
+
kitchen_transport_api_version 1
|
|
30
|
+
plugin_version Kitchen::VERSION
|
|
31
|
+
|
|
32
|
+
default_config :binary, 'docker'
|
|
33
|
+
default_config :env_variables, nil
|
|
34
|
+
default_config :interactive, false
|
|
35
|
+
default_config :privileged, false
|
|
36
|
+
default_config :tls, false
|
|
37
|
+
default_config :tls_cacert, nil
|
|
38
|
+
default_config :tls_cert, nil
|
|
39
|
+
default_config :tls_key, nil
|
|
40
|
+
default_config :tls_verify, false
|
|
41
|
+
default_config :tty, false
|
|
42
|
+
default_config :working_dir, nil
|
|
43
|
+
|
|
44
|
+
default_config :socket do |transport|
|
|
45
|
+
socket = 'unix:///var/run/docker.sock'
|
|
46
|
+
socket = 'npipe:////./pipe/docker_engine' if transport.windows_os?
|
|
47
|
+
ENV['DOCKER_HOST'] || socket
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
default_config :temp_dir do |transport|
|
|
51
|
+
if transport.windows_os?
|
|
52
|
+
'$env:TEMP'
|
|
53
|
+
else
|
|
54
|
+
'/tmp'
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
default_config :username do |transport|
|
|
59
|
+
# Return an empty string to prevent username from being added to Docker
|
|
60
|
+
# command line args for Windows if a username was not specified
|
|
61
|
+
if transport.windows_os?
|
|
62
|
+
nil
|
|
63
|
+
else
|
|
64
|
+
'kitchen'
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def connection(state, &block)
|
|
69
|
+
options = config.to_hash.merge(state)
|
|
70
|
+
options[:platform] = instance.platform.name
|
|
71
|
+
|
|
72
|
+
# Set value for DOCKER_HOST environment variable for the docker-api gem
|
|
73
|
+
# This allows Windows systems to use the TCP socket for the InSpec verifier
|
|
74
|
+
# See the lib/docker.rb file here: https://github.com/swipely/docker-api/blob/master/lib/docker.rb
|
|
75
|
+
# default_socket_url is set to a Unix socket and env_url requires an environment variable to be set
|
|
76
|
+
ENV['DOCKER_HOST'] = options[:socket] if !options[:socket].nil? && ENV['DOCKER_HOST'].nil?
|
|
77
|
+
|
|
78
|
+
Kitchen::Transport::Docker::Connection.new(options, &block)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
class Connection < Kitchen::Transport::Docker::Connection
|
|
82
|
+
# Include the InSpec patches to be able to execute tests on Windows containers
|
|
83
|
+
include Kitchen::Docker::Helpers::InspecHelper
|
|
84
|
+
|
|
85
|
+
def execute(command)
|
|
86
|
+
return if command.nil?
|
|
87
|
+
|
|
88
|
+
debug("[Docker] Executing command: #{command}")
|
|
89
|
+
info("[Docker] Executing command on container")
|
|
90
|
+
|
|
91
|
+
container.execute(command)
|
|
92
|
+
rescue => e
|
|
93
|
+
raise DockerFailed, "Docker failed to execute command on container. Error Details: #{e}"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def upload(locals, remote)
|
|
97
|
+
container.upload(locals, remote)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def container
|
|
101
|
+
@container ||= if @options[:platform].include?('windows')
|
|
102
|
+
Kitchen::Docker::Container::Windows.new(@options)
|
|
103
|
+
else
|
|
104
|
+
Kitchen::Docker::Container::Linux.new(@options)
|
|
105
|
+
end
|
|
106
|
+
@container
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
data/lib/train/docker.rb
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
# Monkey patched Docker train transport to support running the InSpec verifier on Windows
|
|
15
|
+
begin
|
|
16
|
+
# Requires train gem with a minimum version of 2.1.0
|
|
17
|
+
require 'train'
|
|
18
|
+
|
|
19
|
+
module Train::Transports
|
|
20
|
+
# Patched train transport with Windows support for InSpec verifier
|
|
21
|
+
class Docker < Train.plugin(1)
|
|
22
|
+
name 'docker'
|
|
23
|
+
|
|
24
|
+
include_options Train::Extras::CommandWrapper
|
|
25
|
+
option :host, required: true
|
|
26
|
+
|
|
27
|
+
def connection(state = {}, &block)
|
|
28
|
+
opts = merge_options(options, state || {})
|
|
29
|
+
validate_options(opts)
|
|
30
|
+
|
|
31
|
+
if @connection && @connection_options == opts
|
|
32
|
+
reuse_connection(&block)
|
|
33
|
+
else
|
|
34
|
+
create_new_connection(opts, &block)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
# Creates a new Docker connection instance and save it for potential future
|
|
41
|
+
# reuse.
|
|
42
|
+
#
|
|
43
|
+
# @param options [Hash] connection options
|
|
44
|
+
# @return [Docker::Connection] a Docker connection instance
|
|
45
|
+
# @api private
|
|
46
|
+
def create_new_connection(options, &block)
|
|
47
|
+
if @connection
|
|
48
|
+
logger.debug("[Docker] shutting previous connection #{@connection}")
|
|
49
|
+
@connection.close
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
@connection_options = options
|
|
53
|
+
@connection = Connection.new(options, &block)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Return the last saved Docker connection instance.
|
|
57
|
+
#
|
|
58
|
+
# @return [Docker::Connection] a Docker connection instance
|
|
59
|
+
# @api private
|
|
60
|
+
def reuse_connection
|
|
61
|
+
logger.debug("[Docker] reusing existing connection #{@connection}")
|
|
62
|
+
yield @connection if block_given?
|
|
63
|
+
@connection
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
class Train::Transports::Docker
|
|
69
|
+
class Connection < BaseConnection
|
|
70
|
+
def initialize(conf)
|
|
71
|
+
super(conf)
|
|
72
|
+
@id = options[:host]
|
|
73
|
+
@container = ::Docker::Container.get(@id) ||
|
|
74
|
+
fail("Can't find Docker container #{@id}")
|
|
75
|
+
@cmd_wrapper = nil
|
|
76
|
+
@cmd_wrapper = CommandWrapper.load(self, @options)
|
|
77
|
+
self
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def uri
|
|
81
|
+
if @container.nil?
|
|
82
|
+
"docker://#{@id}"
|
|
83
|
+
else
|
|
84
|
+
"docker://#{@container.id}"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
private
|
|
89
|
+
|
|
90
|
+
def file_via_connection(path)
|
|
91
|
+
if os.aix?
|
|
92
|
+
Train::File::Remote::Aix.new(self, path)
|
|
93
|
+
elsif os.solaris?
|
|
94
|
+
Train::File::Remote::Unix.new(self, path)
|
|
95
|
+
elsif os.windows?
|
|
96
|
+
Train::File::Remote::Windows.new(self, path)
|
|
97
|
+
else
|
|
98
|
+
Train::File::Remote::Linux.new(self, path)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def platform_specific_cmd(cmd)
|
|
103
|
+
return cmd if @container.info.nil?
|
|
104
|
+
if @container.info['Platform'] == 'windows'
|
|
105
|
+
return ['cmd.exe', '/c', cmd]
|
|
106
|
+
else
|
|
107
|
+
return ['/bin/sh', '-c', cmd]
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def run_command_via_connection(cmd, &_data_handler)
|
|
112
|
+
cmd = @cmd_wrapper.run(cmd) unless @cmd_wrapper.nil?
|
|
113
|
+
stdout, stderr, exit_status = @container.exec(platform_specific_cmd(cmd))
|
|
114
|
+
CommandResult.new(stdout.join, stderr.join, exit_status)
|
|
115
|
+
rescue ::Docker::Error::DockerError => _
|
|
116
|
+
raise
|
|
117
|
+
rescue => _
|
|
118
|
+
# @TODO: differentiate any other error
|
|
119
|
+
raise
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
rescue LoadError => e
|
|
124
|
+
logger.debug("[Docker] train gem not found for InSpec verifier. #{e}")
|
|
125
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
case RbConfig::CONFIG['host_os']
|
|
16
|
+
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
|
17
|
+
set :backend, :cmd
|
|
18
|
+
set :os, :family => 'windows'
|
|
19
|
+
else
|
|
20
|
+
set :backend, :exec
|
|
21
|
+
end
|
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
#
|
|
16
16
|
|
|
17
17
|
# Just make sure the image launched and is reachable.
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
if os[:family] == 'windows'
|
|
19
|
+
describe command('echo 1') do
|
|
20
|
+
its(:exit_status) { is_expected.to eq 0 }
|
|
21
|
+
end
|
|
22
|
+
else
|
|
23
|
+
describe command('true') do
|
|
24
|
+
its(:exit_status) { is_expected.to eq 0 }
|
|
25
|
+
end
|
|
20
26
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kitchen-docker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.11.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sean Porter
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-07-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: test-kitchen
|
|
@@ -176,14 +176,34 @@ dependencies:
|
|
|
176
176
|
requirements:
|
|
177
177
|
- - "~>"
|
|
178
178
|
- !ruby/object:Gem::Version
|
|
179
|
-
version: '0
|
|
179
|
+
version: '2.0'
|
|
180
180
|
type: :development
|
|
181
181
|
prerelease: false
|
|
182
182
|
version_requirements: !ruby/object:Gem::Requirement
|
|
183
183
|
requirements:
|
|
184
184
|
- - "~>"
|
|
185
185
|
- !ruby/object:Gem::Version
|
|
186
|
-
version: '0
|
|
186
|
+
version: '2.0'
|
|
187
|
+
- !ruby/object:Gem::Dependency
|
|
188
|
+
name: train
|
|
189
|
+
requirement: !ruby/object:Gem::Requirement
|
|
190
|
+
requirements:
|
|
191
|
+
- - ">="
|
|
192
|
+
- !ruby/object:Gem::Version
|
|
193
|
+
version: '2.1'
|
|
194
|
+
- - "<"
|
|
195
|
+
- !ruby/object:Gem::Version
|
|
196
|
+
version: '4.0'
|
|
197
|
+
type: :development
|
|
198
|
+
prerelease: false
|
|
199
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
200
|
+
requirements:
|
|
201
|
+
- - ">="
|
|
202
|
+
- !ruby/object:Gem::Version
|
|
203
|
+
version: '2.1'
|
|
204
|
+
- - "<"
|
|
205
|
+
- !ruby/object:Gem::Version
|
|
206
|
+
version: '4.0'
|
|
187
207
|
description: A Docker Driver for Test Kitchen
|
|
188
208
|
email:
|
|
189
209
|
- portertech@gmail.com
|
|
@@ -192,7 +212,9 @@ extensions: []
|
|
|
192
212
|
extra_rdoc_files: []
|
|
193
213
|
files:
|
|
194
214
|
- ".cane"
|
|
215
|
+
- ".github/dependabot.yml"
|
|
195
216
|
- ".gitignore"
|
|
217
|
+
- ".kitchen.windows.yml"
|
|
196
218
|
- ".kitchen.yml"
|
|
197
219
|
- ".tailor"
|
|
198
220
|
- ".travis.yml"
|
|
@@ -201,21 +223,35 @@ files:
|
|
|
201
223
|
- LICENSE
|
|
202
224
|
- README.md
|
|
203
225
|
- Rakefile
|
|
226
|
+
- docker.ps1
|
|
204
227
|
- kitchen-docker.gemspec
|
|
228
|
+
- lib/docker/version.rb
|
|
229
|
+
- lib/kitchen/docker/container.rb
|
|
230
|
+
- lib/kitchen/docker/container/linux.rb
|
|
231
|
+
- lib/kitchen/docker/container/windows.rb
|
|
232
|
+
- lib/kitchen/docker/docker_version.rb
|
|
233
|
+
- lib/kitchen/docker/erb_context.rb
|
|
234
|
+
- lib/kitchen/docker/helpers/cli_helper.rb
|
|
235
|
+
- lib/kitchen/docker/helpers/container_helper.rb
|
|
236
|
+
- lib/kitchen/docker/helpers/dockerfile_helper.rb
|
|
237
|
+
- lib/kitchen/docker/helpers/file_helper.rb
|
|
238
|
+
- lib/kitchen/docker/helpers/image_helper.rb
|
|
239
|
+
- lib/kitchen/docker/helpers/inspec_helper.rb
|
|
205
240
|
- lib/kitchen/driver/docker.rb
|
|
206
|
-
- lib/kitchen/
|
|
207
|
-
- lib/
|
|
241
|
+
- lib/kitchen/transport/docker.rb
|
|
242
|
+
- lib/train/docker.rb
|
|
208
243
|
- test/Dockerfile
|
|
209
244
|
- test/integration/capabilities/serverspec/capabilities_drop_spec.rb
|
|
210
245
|
- test/integration/default/serverspec/default_spec.rb
|
|
246
|
+
- test/integration/default/serverspec/spec_helper.rb
|
|
211
247
|
- test/integration/inspec/inspec_spec.rb
|
|
212
248
|
- test/spec/docker_spec.rb
|
|
213
249
|
- test/spec/spec_helper.rb
|
|
214
|
-
homepage: https://github.com/
|
|
250
|
+
homepage: https://github.com/test-kitchen/kitchen-docker
|
|
215
251
|
licenses:
|
|
216
252
|
- Apache 2.0
|
|
217
253
|
metadata: {}
|
|
218
|
-
post_install_message:
|
|
254
|
+
post_install_message:
|
|
219
255
|
rdoc_options: []
|
|
220
256
|
require_paths:
|
|
221
257
|
- lib
|
|
@@ -230,15 +266,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
230
266
|
- !ruby/object:Gem::Version
|
|
231
267
|
version: '0'
|
|
232
268
|
requirements: []
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
signing_key:
|
|
269
|
+
rubygems_version: 3.2.15
|
|
270
|
+
signing_key:
|
|
236
271
|
specification_version: 4
|
|
237
272
|
summary: A Docker Driver for Test Kitchen
|
|
238
273
|
test_files:
|
|
239
274
|
- test/Dockerfile
|
|
240
275
|
- test/integration/capabilities/serverspec/capabilities_drop_spec.rb
|
|
241
276
|
- test/integration/default/serverspec/default_spec.rb
|
|
277
|
+
- test/integration/default/serverspec/spec_helper.rb
|
|
242
278
|
- test/integration/inspec/inspec_spec.rb
|
|
243
279
|
- test/spec/docker_spec.rb
|
|
244
280
|
- test/spec/spec_helper.rb
|