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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -0
  3. data/.github/workflows/lint.yml +99 -0
  4. data/.github/workflows/publish.yaml +32 -0
  5. data/.gitignore +1 -0
  6. data/.markdownlint.yaml +6 -0
  7. data/.release-please-manifest.json +3 -0
  8. data/.rubocop.yml +9 -0
  9. data/.yamllint +15 -0
  10. data/CHANGELOG.md +40 -0
  11. data/Gemfile +20 -1
  12. data/README.md +16 -9
  13. data/Rakefile +13 -36
  14. data/cookbooks +1 -0
  15. data/kitchen-docker.gemspec +9 -29
  16. data/kitchen.windows.yml +31 -0
  17. data/kitchen.yml +94 -0
  18. data/lib/kitchen/docker/container/linux.rb +17 -17
  19. data/lib/kitchen/docker/container/windows.rb +11 -11
  20. data/lib/kitchen/docker/container.rb +7 -7
  21. data/lib/kitchen/docker/docker_version.rb +1 -1
  22. data/lib/kitchen/docker/erb_context.rb +3 -3
  23. data/lib/kitchen/docker/helpers/cli_helper.rb +184 -172
  24. data/lib/kitchen/docker/helpers/container_helper.rb +178 -172
  25. data/lib/kitchen/docker/helpers/dockerfile_helper.rb +34 -34
  26. data/lib/kitchen/docker/helpers/file_helper.rb +4 -4
  27. data/lib/kitchen/docker/helpers/image_helper.rb +28 -14
  28. data/lib/kitchen/docker/helpers/inspec_helper.rb +62 -40
  29. data/lib/kitchen/driver/docker.rb +34 -40
  30. data/lib/kitchen/transport/docker.rb +15 -16
  31. data/release-please-config.json +12 -0
  32. data/renovate.json +8 -0
  33. data/spec/docker_spec.rb +108 -0
  34. data/spec/dockerfile_helper_spec.rb +109 -0
  35. data/spec/inspec_helper_spec.rb +58 -0
  36. data/{test/spec → spec}/spec_helper.rb +5 -26
  37. data/test/Dockerfile +4 -5
  38. data/test/cookbooks/cinc_test/metadata.rb +2 -0
  39. data/test/cookbooks/cinc_test/recipes/default.rb +10 -0
  40. data/test/cookbooks/docker_test/attributes/default.rb +1 -0
  41. data/test/cookbooks/docker_test/metadata.rb +3 -0
  42. data/test/cookbooks/docker_test/recipes/default.rb +94 -0
  43. data/test/integration/capabilities/{serverspec → disabled}/capabilities_drop_spec.rb +7 -6
  44. data/test/integration/cinc/inspec/cinc_spec.rb +21 -0
  45. data/test/integration/default/{serverspec → disabled}/default_spec.rb +7 -6
  46. data/test/integration/default/{serverspec → disabled}/spec_helper.rb +7 -7
  47. data/test/integration/inspec/inspec_spec.rb +3 -3
  48. metadata +33 -202
  49. data/.cane +0 -0
  50. data/.github/dependabot.yml +0 -7
  51. data/.kitchen.windows.yml +0 -33
  52. data/.kitchen.yml +0 -65
  53. data/.tailor +0 -4
  54. data/.travis.yml +0 -57
  55. data/lib/docker/version.rb +0 -25
  56. data/lib/train/docker.rb +0 -125
  57. data/test/spec/docker_spec.rb +0 -64
data/.travis.yml DELETED
@@ -1,57 +0,0 @@
1
- matrix:
2
- include:
3
- - os: linux
4
- rvm: 2.4.9
5
- dist: xenial
6
- language: ruby
7
- cache: bundler
8
- script:
9
- - bundle exec docker version
10
- - bundle exec kitchen --version
11
- - bundle exec rake spec
12
- - bundle exec kitchen test -d always
13
- - os: linux
14
- rvm: 2.5.7
15
- dist: xenial
16
- language: ruby
17
- cache: bundler
18
- script:
19
- - bundle exec docker version
20
- - bundle exec kitchen --version
21
- - bundle exec rake spec
22
- - bundle exec kitchen test -d always
23
- - os: linux
24
- rvm: 2.6.5
25
- dist: xenial
26
- language: ruby
27
- cache: bundler
28
- script:
29
- - bundle exec docker version
30
- - bundle exec kitchen --version
31
- - bundle exec rake spec
32
- - bundle exec kitchen test -d always
33
- - os: windows
34
- language: bash
35
- install:
36
- - choco uninstall ruby
37
- - choco install ruby --version=2.6.5.1
38
- - export PATH=$(echo "$PATH" | sed -e 's/:\/c\/tools\/ruby27\/bin//')
39
- - export PATH=$PATH:/c/tools/ruby26/bin
40
- - choco install mingw
41
- - choco install msys2
42
- - ridk.cmd exec pacman -S --noconfirm --needed base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-libxslt
43
- script:
44
- - if [[ $(tasklist | grep "gpg-agent") ]]; then taskkill -IM "gpg-agent.exe" -F; else echo "Process gpg-agent not found. Skipping."; fi
45
- - powershell -ExecutionPolicy Bypass -NoLogo -File docker.ps1
46
- - export KITCHEN_YAML=.kitchen.windows.yml
47
- - ruby -v
48
- - gem install bundler
49
- - bundle config build.nokogiri --use-system-libraries
50
- - bundle install
51
- - bundle exec docker version
52
- - bundle exec kitchen --version
53
- - bundle exec rake spec
54
- - bundle exec kitchen test -d always
55
-
56
- services:
57
- - docker
@@ -1,25 +0,0 @@
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
- begin
15
- require 'docker'
16
-
17
- # Override API_VERSION constant in docker-api gem to use version 1.24 of the Docker API
18
- # This override is for the docker-api gem to communicate to the Docker engine on Windows
19
- module Docker
20
- VERSION = '0.0.0'
21
- API_VERSION = '1.24'
22
- end
23
- rescue LoadError => e
24
- logger.debug("[Docker] docker-api gem not found for InSpec verifier. #{e}")
25
- end
data/lib/train/docker.rb DELETED
@@ -1,125 +0,0 @@
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
@@ -1,64 +0,0 @@
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
- end