kitchen-docker 2.8.0 → 2.12.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.
@@ -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
data/test/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM centos:6
1
+ FROM centos:7
2
2
  RUN yum clean all
3
3
  RUN yum install -y sudo openssh-server openssh-clients which curl htop
4
4
  RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
@@ -15,7 +15,7 @@
15
15
  #
16
16
 
17
17
  require 'serverspec'
18
- set :backend, :exec
18
+ require 'spec_helper'
19
19
 
20
20
  # Just make sure the image launched and is reachable.
21
21
  describe command('true') do
@@ -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
- describe command('true') do
19
- its(:exit_status) { is_expected.to eq 0 }
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.8.0
4
+ version: 2.12.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: 2019-01-18 00:00:00.000000000 Z
11
+ date: 2021-12-22 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.14'
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.14'
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,13 +223,27 @@ 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/driver/docker/erb.rb
207
- - lib/kitchen/driver/docker_version.rb
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
@@ -215,7 +251,7 @@ 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,14 +266,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
266
  - !ruby/object:Gem::Version
231
267
  version: '0'
232
268
  requirements: []
233
- rubygems_version: 3.0.1
234
- signing_key:
269
+ rubygems_version: 3.2.32
270
+ signing_key:
235
271
  specification_version: 4
236
272
  summary: A Docker Driver for Test Kitchen
237
273
  test_files:
238
274
  - test/Dockerfile
239
275
  - test/integration/capabilities/serverspec/capabilities_drop_spec.rb
240
276
  - test/integration/default/serverspec/default_spec.rb
277
+ - test/integration/default/serverspec/spec_helper.rb
241
278
  - test/integration/inspec/inspec_spec.rb
242
279
  - test/spec/docker_spec.rb
243
280
  - test/spec/spec_helper.rb