kitchen-docker 2.10.0 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +7 -0
- data/.gitignore +1 -1
- data/.kitchen.windows.yml +1 -1
- data/.kitchen.yml +16 -19
- data/.travis.yml +7 -2
- data/CHANGELOG.md +75 -65
- data/README.md +67 -5
- data/kitchen-docker.gemspec +1 -1
- data/lib/kitchen/docker/container/linux.rb +6 -81
- data/lib/kitchen/docker/container/windows.rb +1 -0
- data/lib/kitchen/docker/container.rb +18 -13
- data/lib/kitchen/docker/docker_version.rb +1 -1
- data/lib/kitchen/docker/helpers/cli_helper.rb +25 -0
- data/lib/kitchen/docker/helpers/dockerfile_helper.rb +160 -0
- data/lib/kitchen/docker/helpers/image_helper.rb +12 -4
- data/lib/kitchen/driver/docker.rb +165 -164
- data/test/Dockerfile +1 -1
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b1291ba7bef7b5a17771a1187a34829acac0b0a78e4185119ecb0e5e23728da
|
4
|
+
data.tar.gz: f1f3b39dc87295717756beab914c0ea5d945c68e318f581717e55b6a65ffbaea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6bcc821a798f066815e2b9da4ef82389b29e53da4dd66bfbb0a228cb2a9b185289621f496d60bea06c5fb54aab388201f4f0c287e4743d2bd809bce4ed264ff
|
7
|
+
data.tar.gz: 6bdc6f960565040e5f8161dd6f64d81059fb9d83c42bf71287cf95c6e31ab50056f8e1ce5d065b1be53008bd79195bd93d36a1e661a0de297ac816676eae85f2
|
data/.gitignore
CHANGED
data/.kitchen.windows.yml
CHANGED
data/.kitchen.yml
CHANGED
@@ -14,31 +14,21 @@ provisioner:
|
|
14
14
|
|
15
15
|
platforms:
|
16
16
|
- name: amazonlinux-2
|
17
|
-
- name: ubuntu-16.04
|
18
17
|
- name: ubuntu-18.04
|
18
|
+
- name: ubuntu-20.04
|
19
19
|
- name: fedora-latest
|
20
20
|
driver:
|
21
21
|
provision_command:
|
22
|
-
- yum install libxcrypt-compat
|
22
|
+
- yum install libxcrypt-compat -y
|
23
23
|
- curl -L https://www.chef.io/chef/install.sh | bash
|
24
|
-
- name: centos-6
|
25
24
|
- name: centos-7
|
26
|
-
- name: oraclelinux-6
|
27
25
|
- name: oraclelinux-7
|
28
|
-
- name:
|
26
|
+
- name: rockylinux-8
|
29
27
|
- name: debian-9
|
30
|
-
- name:
|
28
|
+
- name: debian-10
|
29
|
+
- name: opensuse-15
|
31
30
|
driver:
|
32
|
-
image: opensuse/leap:
|
33
|
-
- name: opensuse/leap-42
|
34
|
-
# - name: arch
|
35
|
-
# driver:
|
36
|
-
# image: base/archlinux
|
37
|
-
# provision_command: true
|
38
|
-
- name: unknown
|
39
|
-
driver:
|
40
|
-
image: ubuntu:16.04
|
41
|
-
platform: ubuntu
|
31
|
+
image: opensuse/leap:15
|
42
32
|
- name: dockerfile
|
43
33
|
driver:
|
44
34
|
username: dockerfile
|
@@ -48,19 +38,26 @@ platforms:
|
|
48
38
|
|
49
39
|
suites:
|
50
40
|
- name: default
|
51
|
-
excludes: [arch]
|
41
|
+
excludes: [arch, debian-9]
|
52
42
|
- name: context
|
53
|
-
excludes: [arch]
|
43
|
+
excludes: [arch, debian-9]
|
54
44
|
driver:
|
55
45
|
build_context: false
|
56
46
|
- name: capabilities
|
57
|
-
includes: [debian-
|
47
|
+
includes: [debian-10,ubuntu-18.04,ubuntu-20.04]
|
58
48
|
driver:
|
59
49
|
provision_command:
|
60
50
|
- curl -L https://www.chef.io/chef/install.sh | bash
|
61
51
|
- apt-get install -y net-tools
|
62
52
|
cap_drop:
|
63
53
|
- NET_ADMIN
|
54
|
+
- name: arm64
|
55
|
+
excludes: [debian-9]
|
56
|
+
driver:
|
57
|
+
docker_platform: linux/arm64
|
58
|
+
- name: amd64
|
59
|
+
driver:
|
60
|
+
docker_platform: linux/amd64
|
64
61
|
- name: inspec
|
65
62
|
driver:
|
66
63
|
provision_command: true
|
data/.travis.yml
CHANGED
@@ -33,15 +33,20 @@ matrix:
|
|
33
33
|
- os: windows
|
34
34
|
language: bash
|
35
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
|
36
40
|
- choco install mingw
|
37
41
|
- choco install msys2
|
38
|
-
- ridk.cmd exec pacman -S --noconfirm --needed base-devel mingw-w64-x86_64-toolchain
|
42
|
+
- ridk.cmd exec pacman -S --noconfirm --needed base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-libxslt
|
39
43
|
script:
|
40
|
-
- taskkill -IM "gpg-agent.exe" -F
|
44
|
+
- if [[ $(tasklist | grep "gpg-agent") ]]; then taskkill -IM "gpg-agent.exe" -F; else echo "Process gpg-agent not found. Skipping."; fi
|
41
45
|
- powershell -ExecutionPolicy Bypass -NoLogo -File docker.ps1
|
42
46
|
- export KITCHEN_YAML=.kitchen.windows.yml
|
43
47
|
- ruby -v
|
44
48
|
- gem install bundler
|
49
|
+
- bundle config build.nokogiri --use-system-libraries
|
45
50
|
- bundle install
|
46
51
|
- bundle exec docker version
|
47
52
|
- bundle exec kitchen --version
|
data/CHANGELOG.md
CHANGED
@@ -1,110 +1,120 @@
|
|
1
1
|
# Kitchen-Docker Changelog
|
2
2
|
|
3
|
+
## 2.13.0 - June 10, 2022
|
4
|
+
|
5
|
+
- Added CentOSStream and PhotonOS - [@garethgreenaway](https://github.com/garethgreenaway)
|
6
|
+
- Fixed image parser when output includes a duration timestamp - [@RulerOf](https://github.com/RulerOf)
|
7
|
+
- Updated the test suites - [@RulerOf](https://github.com/RulerOf)
|
8
|
+
|
9
|
+
## 2.12.0 - December 22, 2021
|
10
|
+
|
11
|
+
- Support Docker BuildKit - [@RulerOf](https://github.com/RulerOf)
|
12
|
+
- Add new `docker_platform` config to allow specifying architectures - [@RulerOf](https://github.com/RulerOf)
|
13
|
+
|
14
|
+
## 2.11.0 - July 2, 2021
|
15
|
+
|
16
|
+
- Update the development dependency on kitchen-inspec to 2.x
|
17
|
+
- Retrieve hostname state data after container is launched to avoid failures when `use_internal_docker_network` is set
|
18
|
+
- Add a new option for setting container isolation. See the readme for additional details
|
19
|
+
- Support GPUs in containers with a new `gpus` option that takes the same arguments that would be passed to `docker run --gpus`
|
20
|
+
- suse platform: use system script for ssh key initialization
|
21
|
+
- Add support for the `--mount` docker CLI option. See the readme for additional details
|
22
|
+
- Use sudo.d files instead of directly editing the sudoers file
|
23
|
+
- Allow passing `--tmpfs` entries to the docker run command. See the readme for additional details
|
24
|
+
- Use less verbose and quicker setup on Gentoo
|
25
|
+
- Lowercase the instance-name to avoid issues since docker does not allow instance with capital cases
|
26
|
+
- Fix the error "Could not parse Docker build output for image ID" by improving the output line matching
|
27
|
+
- Add support for `almalinux` & `rockylinux`
|
28
|
+
|
3
29
|
## 2.10.0 - Mar 28, 2020
|
4
30
|
|
5
|
-
|
6
|
-
|
7
|
-
|
31
|
+
- Switched from require to require_relative to slightly improve load time performance
|
32
|
+
- Allow for train gem 3.x
|
33
|
+
- Refactor driver to include Windows support (includes new transport for all supported platforms)
|
8
34
|
|
9
35
|
## 2.9.0 - Mar 15, 2019
|
10
36
|
|
11
|
-
|
12
|
-
|
37
|
+
- Add automatic OS detection for amazonlinux, opensuse/leap, and opensuse/tumbleweed
|
38
|
+
- On Fedora containers uses dnf to setup the OS not yum
|
13
39
|
|
14
40
|
## 2.8.0 - Jan 18, 2019
|
15
41
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
42
|
+
- Add new config option `use_internal_docker_network`, which allows running Docker within Docker. See readme for usage details.
|
43
|
+
- Resolve errors while loading libraries on archlinux
|
44
|
+
- Fix failures on Ubuntu 18.04
|
45
|
+
- Check if image exists before attempting to remove it so we don't fail
|
46
|
+
- Add oraclelinux platform support
|
47
|
+
- Prevent `uninitialized constant Kitchen::Driver::Docker::Base64` error by requiring `base64`
|
22
48
|
|
23
49
|
## 2.7.0
|
24
50
|
|
25
|
-
|
26
|
-
|
27
|
-
|
51
|
+
- Support for SUSE-based container images.
|
52
|
+
- Improved support for build context shipping.
|
53
|
+
- Changed `use_sudo` to default to `false` in keeping with modern Docker usage.
|
28
54
|
|
29
55
|
## 2.6.0
|
30
56
|
|
31
|
-
|
57
|
+
- Set container name with information from the run so you can identify them
|
32
58
|
later on.
|
33
|
-
|
59
|
+
- Upgrade to new driver base class structure.
|
34
60
|
|
35
61
|
## 2.5.0
|
36
62
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
63
|
+
- [#209](https://github.com/portertech/kitchen-docker/pulls/209) Fix usage with Kitchen rake tasks.
|
64
|
+
- Add `run_options` and `build_options` configuration.
|
65
|
+
- [#195](https://github.com/portertech/kitchen-docker/pulls/195) Fix Arch Linux support.
|
66
|
+
- Fix shell escaping for build paths and SSH keys.
|
41
67
|
|
42
68
|
## 2.4.0
|
43
69
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
70
|
+
- [#148](https://github.com/portertech/kitchen-docker/issues/148) Restored support for older versions of Ruby.
|
71
|
+
- [#149](https://github.com/portertech/kitchen-docker/pulls/149) Handle connecting to a container directly as root.
|
72
|
+
- [#154](https://github.com/portertech/kitchen-docker/pulls/154) Improve container caching by reordering the build steps.
|
73
|
+
- [#176](https://github.com/portertech/kitchen-docker/pulls/176) Expose proxy environment variables to the container automatically.
|
74
|
+
- [#192](https://github.com/portertech/kitchen-docker/pulls/192) Set `$container=docker` for CentOS images.
|
75
|
+
- [#196](https://github.com/portertech/kitchen-docker/pulls/196) Mutex SSH key generation for use with `kitchen -c`.
|
76
|
+
- [#192](https://github.com/portertech/kitchen-docker/pulls/192) Don't wait when stopping a container.
|
51
77
|
|
52
78
|
## 2.3.0
|
53
79
|
|
54
|
-
|
80
|
+
- `build_context` option (boolean) to enable/disable sending the build
|
55
81
|
context to Docker.
|
56
82
|
|
57
83
|
## 2.2.0
|
58
84
|
|
59
|
-
|
85
|
+
- Use a temporary file for each suite instance Docker container
|
60
86
|
Dockerfile, instead of passing their contents via STDIN. This allows for
|
61
87
|
the use of commands like ADD and COPY. **Users must now use Docker >= 1.5.0**
|
62
|
-
|
63
|
-
* Passwordless suite instance Docker container login (SSH), using a
|
88
|
+
- Passwordless suite instance Docker container login (SSH), using a
|
64
89
|
generated key pair.
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
* README YAML highlighting.
|
90
|
+
- Support for sharing a host device with suite instance Docker containers.
|
91
|
+
- README YAML highlighting.
|
69
92
|
|
70
93
|
## 2.1.0
|
71
94
|
|
72
|
-
|
95
|
+
- Use `NUL` instead of `/dev/null` on Windows for output redirection
|
73
96
|
|
74
97
|
## 2.0.0
|
75
98
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
* wait_for_sshd option (boolean)
|
85
|
-
|
86
|
-
* Create `/etc/sudoers.d` if missing
|
87
|
-
|
88
|
-
* Fixed option deprecation warnings, require Docker >= 1.2
|
99
|
+
- Use Docker `top` and `port` instead of `inspect`
|
100
|
+
- Don't create the kitchen user if it already exists
|
101
|
+
- Docker container capabilities options: cap_add, cap_drop
|
102
|
+
- Docker security profile option (SELinux/AppArmor): security_opt
|
103
|
+
- wait_for_sshd option (boolean)
|
104
|
+
- Create `/etc/sudoers.d` if missing
|
105
|
+
- Fixed option deprecation warnings, require Docker >= 1.2
|
89
106
|
|
90
107
|
## 1.7.0
|
91
108
|
|
92
|
-
|
109
|
+
- Ensure a container id is set before attempting to inspect a container
|
93
110
|
|
94
111
|
## 1.6.0
|
95
112
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
* Fixed verify dependencies output redirection
|
105
|
-
|
106
|
-
* Added `fedora` to platform names
|
107
|
-
|
108
|
-
* Support for `gentoo` and `gentoo-paludis` platforms
|
109
|
-
|
110
|
-
* Adding sudo rule to `/etc/sudoers.d/#{username}` in addition to `/etc/sudoers`
|
113
|
+
- `publish_all` option to publish all ports to the host interface
|
114
|
+
- `instance_name` option to name the Docker container
|
115
|
+
- `links` option to link suite instance Docker containers
|
116
|
+
- `socket` option will now default to ENV `DOCKER_HOST` if set
|
117
|
+
- Fixed verify dependencies output redirection
|
118
|
+
- Added `fedora` to platform names
|
119
|
+
- Support for `gentoo` and `gentoo-paludis` platforms
|
120
|
+
- Adding sudo rule to `/etc/sudoers.d/#{username}` in addition to `/etc/sudoers`
|
data/README.md
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
|
8
8
|
A Test Kitchen Driver and Transport for Docker.
|
9
9
|
|
10
|
+
***MAINTAINERS WANTED***: This Test-Kitchen driver is currently without a maintainer and has many known issues. If you're interested in maintaining this driver for the long run including expanding the CI testing please reach out on [Chef Community Slack: #test-kitchen](https://chefcommunity.slack.com/archives/C2B6G1WCQ). Until such a time that this driver is maintained we highly recommend the [kitchen-dokken](https://github.com/test-kitchen/kitchen-dokken) for Chef Infra testing with Docker containers.
|
11
|
+
|
10
12
|
## Requirements
|
11
13
|
|
12
14
|
* [Docker][docker_installation] **(>= 1.5)**
|
@@ -23,7 +25,7 @@ driver:
|
|
23
25
|
name: docker
|
24
26
|
env_variables:
|
25
27
|
TEST_KEY: TEST_VALUE
|
26
|
-
|
28
|
+
|
27
29
|
platforms:
|
28
30
|
- name: ubuntu
|
29
31
|
run_list:
|
@@ -109,8 +111,8 @@ Examples:
|
|
109
111
|
|
110
112
|
### socket
|
111
113
|
|
112
|
-
The Docker daemon socket to use. By default, Docker will listen on `unix:///var/run/docker.sock` (On Windows, `npipe:////./pipe/docker_engine`),
|
113
|
-
and no configuration here is required. If Docker is binding to another host/port or Unix socket, you will need to set this option.
|
114
|
+
The Docker daemon socket to use. By default, Docker will listen on `unix:///var/run/docker.sock` (On Windows, `npipe:////./pipe/docker_engine`),
|
115
|
+
and no configuration here is required. If Docker is binding to another host/port or Unix socket, you will need to set this option.
|
114
116
|
If a TCP socket is set, its host will be used for SSH access to suite containers.
|
115
117
|
|
116
118
|
Examples:
|
@@ -164,6 +166,19 @@ images using the [Docker Index][docker_index].
|
|
164
166
|
The default will be computed, using the platform name (see the Default
|
165
167
|
Configuration section for more details).
|
166
168
|
|
169
|
+
### isolation
|
170
|
+
|
171
|
+
The isolation technology for the container. This is not set by default and will use the default container isolation settings.
|
172
|
+
|
173
|
+
For example, the following driver configuration options can be used to specify the container isolation technology for Windows containers:
|
174
|
+
```yaml
|
175
|
+
# Hyper-V
|
176
|
+
isolation: hyperv
|
177
|
+
|
178
|
+
# Process
|
179
|
+
isolation: process
|
180
|
+
```
|
181
|
+
|
167
182
|
### platform
|
168
183
|
|
169
184
|
The platform of the chosen image. This is used to properly bootstrap the
|
@@ -171,7 +186,7 @@ suite container for Test Kitchen. Kitchen Docker currently supports:
|
|
171
186
|
|
172
187
|
* `arch`
|
173
188
|
* `debian` or `ubuntu`
|
174
|
-
* `amazonlinux`, `rhel`, `centos`, `fedora` or `
|
189
|
+
* `amazonlinux`, `rhel`, `centos`, `fedora`, `oraclelinux`, `almalinux` or `rockylinux`
|
175
190
|
* `gentoo` or `gentoo-paludis`
|
176
191
|
* `opensuse/tumbleweed`, `opensuse/leap`, `opensuse` or `sles`
|
177
192
|
* `windows`
|
@@ -312,6 +327,39 @@ Examples:
|
|
312
327
|
- rvm
|
313
328
|
```
|
314
329
|
|
330
|
+
### mount
|
331
|
+
|
332
|
+
Attach a filesystem mount to the container (**NOTE:** supported only in docker
|
333
|
+
17.05 and newer).
|
334
|
+
|
335
|
+
Examples:
|
336
|
+
|
337
|
+
```yaml
|
338
|
+
mount: type=volume,source=my-volume,destination=/path/in/container
|
339
|
+
```
|
340
|
+
|
341
|
+
```yaml
|
342
|
+
mount:
|
343
|
+
- type=volume,source=my-volume,destination=/path/in/container
|
344
|
+
- type=tmpfs,tmpfs-size=512M,destination=/path/to/tmpdir
|
345
|
+
```
|
346
|
+
|
347
|
+
### tmpfs
|
348
|
+
|
349
|
+
Adds a tmpfs volume(s) to the suite container.
|
350
|
+
|
351
|
+
Examples:
|
352
|
+
|
353
|
+
```yaml
|
354
|
+
tmpfs: /tmp
|
355
|
+
```
|
356
|
+
|
357
|
+
```yaml
|
358
|
+
tmpfs:
|
359
|
+
- /tmp:exec
|
360
|
+
- /run
|
361
|
+
```
|
362
|
+
|
315
363
|
### dns
|
316
364
|
|
317
365
|
Adjusts `resolv.conf` to use the dns servers specified. Otherwise use
|
@@ -548,6 +596,20 @@ Examples:
|
|
548
596
|
use_internal_docker_network: true
|
549
597
|
```
|
550
598
|
|
599
|
+
### docker_platform
|
600
|
+
|
601
|
+
Configure the CPU platform (architecture) used by docker to build the image.
|
602
|
+
|
603
|
+
Examples:
|
604
|
+
|
605
|
+
```yaml
|
606
|
+
docker_platform: linux/arm64
|
607
|
+
```
|
608
|
+
|
609
|
+
```yaml
|
610
|
+
docker_platform: linux/amd64
|
611
|
+
```
|
612
|
+
|
551
613
|
## Development
|
552
614
|
|
553
615
|
* Source hosted at [GitHub][repo]
|
@@ -587,7 +649,7 @@ limitations under the License.
|
|
587
649
|
[docker_upstart_issue]: https://github.com/dotcloud/docker/issues/223
|
588
650
|
[docker_index]: https://index.docker.io/
|
589
651
|
[docker_default_image]: https://index.docker.io/_/base/
|
590
|
-
[test_kitchen_docs]:
|
652
|
+
[test_kitchen_docs]: https://kitchen.ci/docs/getting-started/introduction/
|
591
653
|
[chef_omnibus_dl]: https://downloads.chef.io/chef-client/
|
592
654
|
[cpu_shares]: https://docs.fedoraproject.org/en-US/Fedora/17/html/Resource_Management_Guide/sec-cpu.html
|
593
655
|
[memory_limit]: https://docs.fedoraproject.org/en-US/Fedora/17/html/Resource_Management_Guide/sec-memory.html
|
data/kitchen-docker.gemspec
CHANGED
@@ -34,6 +34,6 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency 'codecov', '~> 0.0', '>= 0.0.2'
|
35
35
|
|
36
36
|
# Integration testing gems.
|
37
|
-
spec.add_development_dependency 'kitchen-inspec', '~>
|
37
|
+
spec.add_development_dependency 'kitchen-inspec', '~> 2.0'
|
38
38
|
spec.add_development_dependency 'train', '>= 2.1', '< 4.0' # validate 4.x when it's released
|
39
39
|
end
|
@@ -17,11 +17,14 @@ require 'securerandom'
|
|
17
17
|
require 'shellwords'
|
18
18
|
|
19
19
|
require_relative '../container'
|
20
|
+
require_relative '../helpers/dockerfile_helper'
|
20
21
|
|
21
22
|
module Kitchen
|
22
23
|
module Docker
|
23
24
|
class Container
|
24
25
|
class Linux < Kitchen::Docker::Container
|
26
|
+
include Kitchen::Docker::Helpers::DockerfileHelper
|
27
|
+
|
25
28
|
MUTEX_FOR_SSH_KEYS = Mutex.new
|
26
29
|
|
27
30
|
def initialize(config)
|
@@ -37,7 +40,7 @@ module Kitchen
|
|
37
40
|
state[:ssh_key] = @config[:private_key]
|
38
41
|
state[:image_id] = build_image(state, dockerfile) unless state[:image_id]
|
39
42
|
state[:container_id] = run_container(state, 22) unless state[:container_id]
|
40
|
-
state[:hostname] =
|
43
|
+
state[:hostname] = hostname(state)
|
41
44
|
state[:port] = container_ssh_port(state)
|
42
45
|
end
|
43
46
|
|
@@ -107,89 +110,11 @@ module Kitchen
|
|
107
110
|
return dockerfile_template if @config[:dockerfile]
|
108
111
|
|
109
112
|
from = "FROM #{@config[:image]}"
|
110
|
-
|
111
|
-
platform = case @config[:platform]
|
112
|
-
when 'debian', 'ubuntu'
|
113
|
-
disable_upstart = <<-CODE
|
114
|
-
RUN [ ! -f "/sbin/initctl" ] || dpkg-divert --local --rename --add /sbin/initctl && ln -sf /bin/true /sbin/initctl
|
115
|
-
CODE
|
116
|
-
packages = <<-CODE
|
117
|
-
ENV DEBIAN_FRONTEND noninteractive
|
118
|
-
ENV container docker
|
119
|
-
RUN apt-get update
|
120
|
-
RUN apt-get install -y sudo openssh-server curl lsb-release
|
121
|
-
CODE
|
122
|
-
@config[:disable_upstart] ? disable_upstart + packages : packages
|
123
|
-
when 'rhel', 'centos', 'oraclelinux', 'amazonlinux'
|
124
|
-
<<-CODE
|
125
|
-
ENV container docker
|
126
|
-
RUN yum clean all
|
127
|
-
RUN yum install -y sudo openssh-server openssh-clients which curl
|
128
|
-
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
|
129
|
-
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
|
130
|
-
CODE
|
131
|
-
when 'fedora'
|
132
|
-
<<-CODE
|
133
|
-
ENV container docker
|
134
|
-
RUN dnf clean all
|
135
|
-
RUN dnf install -y sudo openssh-server openssh-clients which curl
|
136
|
-
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
|
137
|
-
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
|
138
|
-
CODE
|
139
|
-
when 'opensuse/tumbleweed', 'opensuse/leap', 'opensuse', 'sles'
|
140
|
-
<<-CODE
|
141
|
-
ENV container docker
|
142
|
-
RUN zypper install -y sudo openssh which curl
|
143
|
-
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
|
144
|
-
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
|
145
|
-
CODE
|
146
|
-
when 'arch'
|
147
|
-
# See https://bugs.archlinux.org/task/47052 for why we
|
148
|
-
# blank out limits.conf.
|
149
|
-
<<-CODE
|
150
|
-
RUN pacman --noconfirm -Sy archlinux-keyring
|
151
|
-
RUN pacman-db-upgrade
|
152
|
-
RUN pacman --noconfirm -Syu openssl openssh sudo curl
|
153
|
-
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key
|
154
|
-
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
|
155
|
-
RUN echo >/etc/security/limits.conf
|
156
|
-
CODE
|
157
|
-
when 'gentoo'
|
158
|
-
<<-CODE
|
159
|
-
RUN emerge --sync
|
160
|
-
RUN emerge net-misc/openssh app-admin/sudo
|
161
|
-
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key
|
162
|
-
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
|
163
|
-
CODE
|
164
|
-
when 'gentoo-paludis'
|
165
|
-
<<-CODE
|
166
|
-
RUN cave sync
|
167
|
-
RUN cave resolve -zx net-misc/openssh app-admin/sudo
|
168
|
-
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key
|
169
|
-
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
|
170
|
-
CODE
|
171
|
-
else
|
172
|
-
raise ActionFailed, "Unknown platform '#{@config[:platform]}'"
|
173
|
-
end
|
174
|
-
|
113
|
+
platform = dockerfile_platform
|
175
114
|
username = @config[:username]
|
176
115
|
public_key = IO.read(@config[:public_key]).strip
|
177
116
|
homedir = username == 'root' ? '/root' : "/home/#{username}"
|
178
|
-
|
179
|
-
base = <<-CODE
|
180
|
-
RUN if ! getent passwd #{username}; then \
|
181
|
-
useradd -d #{homedir} -m -s /bin/bash -p '*' #{username}; \
|
182
|
-
fi
|
183
|
-
RUN echo "#{username} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
184
|
-
RUN echo "Defaults !requiretty" >> /etc/sudoers
|
185
|
-
RUN mkdir -p #{homedir}/.ssh
|
186
|
-
RUN chown -R #{username} #{homedir}/.ssh
|
187
|
-
RUN chmod 0700 #{homedir}/.ssh
|
188
|
-
RUN touch #{homedir}/.ssh/authorized_keys
|
189
|
-
RUN chown #{username} #{homedir}/.ssh/authorized_keys
|
190
|
-
RUN chmod 0600 #{homedir}/.ssh/authorized_keys
|
191
|
-
RUN mkdir -p /run/sshd
|
192
|
-
CODE
|
117
|
+
base = dockerfile_base_linux(username, homedir)
|
193
118
|
|
194
119
|
custom = ''
|
195
120
|
Array(@config[:provision_command]).each do |cmd|
|
@@ -30,6 +30,7 @@ module Kitchen
|
|
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]
|
33
|
+
state[:hostname] = hostname(state)
|
33
34
|
end
|
34
35
|
|
35
36
|
def execute(command)
|
@@ -37,13 +37,27 @@ module Kitchen
|
|
37
37
|
end
|
38
38
|
|
39
39
|
state[:username] = @config[:username]
|
40
|
-
|
40
|
+
end
|
41
|
+
|
42
|
+
def destroy(state)
|
43
|
+
info("[Docker] Destroying Docker container #{state[:container_id]}") if state[:container_id]
|
44
|
+
remove_container(state) if container_exists?(state)
|
45
|
+
|
46
|
+
if @config[:remove_images] && state[:image_id]
|
47
|
+
remove_image(state) if image_exists?(state)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def hostname(state)
|
52
|
+
hostname = 'localhost'
|
41
53
|
|
42
54
|
if remote_socket?
|
43
|
-
|
44
|
-
elsif config[:use_internal_docker_network]
|
45
|
-
|
55
|
+
hostname = socket_uri.host
|
56
|
+
elsif @config[:use_internal_docker_network]
|
57
|
+
hostname = container_ip_address(state)
|
46
58
|
end
|
59
|
+
|
60
|
+
hostname
|
47
61
|
end
|
48
62
|
|
49
63
|
def upload(locals, remote)
|
@@ -56,15 +70,6 @@ module Kitchen
|
|
56
70
|
|
57
71
|
files
|
58
72
|
end
|
59
|
-
|
60
|
-
def destroy(state)
|
61
|
-
info("[Docker] Destroying Docker container #{state[:container_id]}") if state[:container_id]
|
62
|
-
remove_container(state) if container_exists?(state)
|
63
|
-
|
64
|
-
if @config[:remove_images] && state[:image_id]
|
65
|
-
remove_image(state) if image_exists?(state)
|
66
|
-
end
|
67
|
-
end
|
68
73
|
end
|
69
74
|
end
|
70
75
|
end
|
@@ -36,6 +36,26 @@ module Kitchen
|
|
36
36
|
run_command("#{docker} #{cmd}", docker_shell_opts(options))
|
37
37
|
end
|
38
38
|
|
39
|
+
# Copied from kitchen because we need stderr
|
40
|
+
def run_command(cmd, options = {})
|
41
|
+
if options.fetch(:use_sudo, false)
|
42
|
+
cmd = "#{options.fetch(:sudo_command, "sudo -E")} #{cmd}"
|
43
|
+
end
|
44
|
+
subject = "[#{options.fetch(:log_subject, "local")} command]"
|
45
|
+
|
46
|
+
debug("#{subject} BEGIN (#{cmd})")
|
47
|
+
sh = Mixlib::ShellOut.new(cmd, shell_opts(options))
|
48
|
+
sh.run_command
|
49
|
+
debug("#{subject} END #{Util.duration(sh.execution_time)}")
|
50
|
+
sh.error!
|
51
|
+
sh.stdout + sh.stderr
|
52
|
+
rescue Mixlib::ShellOut::ShellCommandFailed => ex
|
53
|
+
raise ShellCommandFailed, ex.message
|
54
|
+
rescue Exception => error # rubocop:disable Lint/RescueException
|
55
|
+
error.extend(Kitchen::Error)
|
56
|
+
raise
|
57
|
+
end
|
58
|
+
|
39
59
|
def build_run_command(image_id, transport_port = nil)
|
40
60
|
cmd = 'run -d'
|
41
61
|
cmd << ' -i' if config[:interactive]
|
@@ -49,17 +69,22 @@ module Kitchen
|
|
49
69
|
Array(config[:volumes_from]).each { |container| cmd << " --volumes-from #{container}" }
|
50
70
|
Array(config[:links]).each { |link| cmd << " --link #{link}" }
|
51
71
|
Array(config[:devices]).each { |device| cmd << " --device #{device}" }
|
72
|
+
Array(config[:mount]).each {|mount| cmd << " --mount #{mount}"}
|
73
|
+
Array(config[:tmpfs]).each {|tmpfs| cmd << " --tmpfs #{tmpfs}"}
|
52
74
|
cmd << " --name #{config[:instance_name]}" if config[:instance_name]
|
53
75
|
cmd << ' -P' if config[:publish_all]
|
54
76
|
cmd << " -h #{config[:hostname]}" if config[:hostname]
|
55
77
|
cmd << " -m #{config[:memory]}" if config[:memory]
|
56
78
|
cmd << " -c #{config[:cpu]}" if config[:cpu]
|
79
|
+
cmd << " --gpus #{config[:gpus]}" if config[:gpus]
|
57
80
|
cmd << " -e http_proxy=#{config[:http_proxy]}" if config[:http_proxy]
|
58
81
|
cmd << " -e https_proxy=#{config[:https_proxy]}" if config[:https_proxy]
|
59
82
|
cmd << ' --privileged' if config[:privileged]
|
83
|
+
cmd << " --isolation #{config[:isolation]}" if config[:isolation]
|
60
84
|
Array(config[:cap_add]).each { |cap| cmd << " --cap-add=#{cap}"} if config[:cap_add]
|
61
85
|
Array(config[:cap_drop]).each { |cap| cmd << " --cap-drop=#{cap}"} if config[:cap_drop]
|
62
86
|
Array(config[:security_opt]).each { |opt| cmd << " --security-opt=#{opt}"} if config[:security_opt]
|
87
|
+
cmd << " --platform=#{config[:docker_platform]}" if config[:docker_platform]
|
63
88
|
extra_run_options = config_to_options(config[:run_options])
|
64
89
|
cmd << " #{extra_run_options}" unless extra_run_options.empty?
|
65
90
|
cmd << " #{image_id} #{config[:run_command]}"
|
@@ -0,0 +1,160 @@
|
|
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
|
+
require 'kitchen/configurable'
|
16
|
+
|
17
|
+
module Kitchen
|
18
|
+
module Docker
|
19
|
+
module Helpers
|
20
|
+
module DockerfileHelper
|
21
|
+
include Configurable
|
22
|
+
|
23
|
+
def dockerfile_platform
|
24
|
+
case config[:platform]
|
25
|
+
when 'arch'
|
26
|
+
arch_platform
|
27
|
+
when 'debian', 'ubuntu'
|
28
|
+
debian_platform
|
29
|
+
when 'fedora'
|
30
|
+
fedora_platform
|
31
|
+
when 'gentoo'
|
32
|
+
gentoo_platform
|
33
|
+
when 'gentoo-paludis'
|
34
|
+
gentoo_paludis_platform
|
35
|
+
when 'opensuse/tumbleweed', 'opensuse/leap', 'opensuse', 'sles'
|
36
|
+
opensuse_platform
|
37
|
+
when 'rhel', 'centos', 'oraclelinux', 'amazonlinux', 'almalinux', 'rockylinux'
|
38
|
+
rhel_platform
|
39
|
+
when 'centosstream'
|
40
|
+
centosstream_platform
|
41
|
+
when 'photon'
|
42
|
+
photonos_platform
|
43
|
+
else
|
44
|
+
raise ActionFailed, "Unknown platform '#{config[:platform]}'"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def arch_platform
|
49
|
+
# See https://bugs.archlinux.org/task/47052 for why we
|
50
|
+
# blank out limits.conf.
|
51
|
+
<<-CODE
|
52
|
+
RUN pacman --noconfirm -Sy archlinux-keyring
|
53
|
+
RUN pacman-db-upgrade
|
54
|
+
RUN pacman --noconfirm -Syu openssl openssh sudo curl
|
55
|
+
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key
|
56
|
+
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
|
57
|
+
RUN echo >/etc/security/limits.conf
|
58
|
+
CODE
|
59
|
+
end
|
60
|
+
|
61
|
+
def debian_platform
|
62
|
+
disable_upstart = <<-CODE
|
63
|
+
RUN [ ! -f "/sbin/initctl" ] || dpkg-divert --local --rename --add /sbin/initctl \
|
64
|
+
&& ln -sf /bin/true /sbin/initctl
|
65
|
+
CODE
|
66
|
+
packages = <<-CODE
|
67
|
+
ENV DEBIAN_FRONTEND noninteractive
|
68
|
+
ENV container docker
|
69
|
+
RUN apt-get update
|
70
|
+
RUN apt-get install -y sudo openssh-server curl lsb-release
|
71
|
+
CODE
|
72
|
+
config[:disable_upstart] ? disable_upstart + packages : packages
|
73
|
+
end
|
74
|
+
|
75
|
+
def fedora_platform
|
76
|
+
<<-CODE
|
77
|
+
ENV container docker
|
78
|
+
RUN dnf clean all
|
79
|
+
RUN dnf install -y sudo openssh-server openssh-clients which curl
|
80
|
+
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
|
81
|
+
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
|
82
|
+
CODE
|
83
|
+
end
|
84
|
+
|
85
|
+
def gentoo_platform
|
86
|
+
<<-CODE
|
87
|
+
RUN emerge-webrsync
|
88
|
+
RUN emerge --quiet --noreplace net-misc/openssh app-admin/sudo
|
89
|
+
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key
|
90
|
+
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
|
91
|
+
CODE
|
92
|
+
end
|
93
|
+
|
94
|
+
def gentoo_paludis_platform
|
95
|
+
<<-CODE
|
96
|
+
RUN cave sync
|
97
|
+
RUN cave resolve -zx net-misc/openssh app-admin/sudo
|
98
|
+
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key
|
99
|
+
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
|
100
|
+
CODE
|
101
|
+
end
|
102
|
+
|
103
|
+
def opensuse_platform
|
104
|
+
<<-CODE
|
105
|
+
ENV container docker
|
106
|
+
RUN zypper install -y sudo openssh which curl
|
107
|
+
RUN /usr/sbin/sshd-gen-keys-start
|
108
|
+
CODE
|
109
|
+
end
|
110
|
+
|
111
|
+
def rhel_platform
|
112
|
+
<<-CODE
|
113
|
+
ENV container docker
|
114
|
+
RUN yum clean all
|
115
|
+
RUN yum install -y sudo openssh-server openssh-clients which curl
|
116
|
+
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
|
117
|
+
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
|
118
|
+
CODE
|
119
|
+
end
|
120
|
+
|
121
|
+
def centosstream_platform
|
122
|
+
<<-CODE
|
123
|
+
ENV container docker
|
124
|
+
RUN yum clean all
|
125
|
+
RUN yum install -y sudo openssh-server openssh-clients which
|
126
|
+
RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
|
127
|
+
RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
|
128
|
+
CODE
|
129
|
+
end
|
130
|
+
|
131
|
+
def photonos_platform
|
132
|
+
<<-CODE
|
133
|
+
ENV container docker
|
134
|
+
RUN tdnf clean all
|
135
|
+
RUN tdnf install -y sudo openssh-server openssh-clients which curl
|
136
|
+
RUN [ -f "/etc/ssh/ssh_host_ecdsa_key" ] || ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
|
137
|
+
RUN [ -f "/etc/ssh/ssh_host_ed25519_key" ] || ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''
|
138
|
+
CODE
|
139
|
+
end
|
140
|
+
|
141
|
+
def dockerfile_base_linux(username, homedir)
|
142
|
+
<<-CODE
|
143
|
+
RUN if ! getent passwd #{username}; then \
|
144
|
+
useradd -d #{homedir} -m -s /bin/bash -p '*' #{username}; \
|
145
|
+
fi
|
146
|
+
RUN echo "#{username} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/#{username}
|
147
|
+
RUN echo "Defaults !requiretty" >> /etc/sudoers.d/#{username}
|
148
|
+
RUN mkdir -p #{homedir}/.ssh
|
149
|
+
RUN chown -R #{username} #{homedir}/.ssh
|
150
|
+
RUN chmod 0700 #{homedir}/.ssh
|
151
|
+
RUN touch #{homedir}/.ssh/authorized_keys
|
152
|
+
RUN chown #{username} #{homedir}/.ssh/authorized_keys
|
153
|
+
RUN chmod 0600 #{homedir}/.ssh/authorized_keys
|
154
|
+
RUN mkdir -p /run/sshd
|
155
|
+
CODE
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -26,8 +26,13 @@ module Kitchen
|
|
26
26
|
|
27
27
|
def parse_image_id(output)
|
28
28
|
output.each_line do |line|
|
29
|
+
if line =~ /writing image (sha256:[[:xdigit:]]{64})(?: \d*\.\ds)? done/i
|
30
|
+
img_id = line[/writing image (sha256:[[:xdigit:]]{64})(?: \d*\.\ds)? done/i,1]
|
31
|
+
return img_id
|
32
|
+
end
|
29
33
|
if line =~ /image id|build successful|successfully built/i
|
30
|
-
|
34
|
+
img_id = line.split(/\s+/).last
|
35
|
+
return img_id
|
31
36
|
end
|
32
37
|
end
|
33
38
|
raise ActionFailed, 'Could not parse Docker build output for image ID'
|
@@ -41,16 +46,19 @@ module Kitchen
|
|
41
46
|
def build_image(state, dockerfile)
|
42
47
|
cmd = 'build'
|
43
48
|
cmd << ' --no-cache' unless config[:use_cache]
|
49
|
+
cmd << " --platform=#{config[:docker_platform]}" if config[:docker_platform]
|
44
50
|
extra_build_options = config_to_options(config[:build_options])
|
45
51
|
cmd << " #{extra_build_options}" unless extra_build_options.empty?
|
46
52
|
dockerfile_contents = dockerfile
|
47
|
-
build_context = config[:build_context] ? '.' : '-'
|
48
53
|
file = Tempfile.new('Dockerfile-kitchen', Dir.pwd)
|
54
|
+
cmd << " -f #{Shellwords.escape(dockerfile_path(file))}" if config[:build_context]
|
55
|
+
build_context = config[:build_context] ? '.' : '-'
|
49
56
|
output = begin
|
50
57
|
file.write(dockerfile)
|
51
58
|
file.close
|
52
|
-
docker_command("#{cmd}
|
53
|
-
input: dockerfile_contents
|
59
|
+
docker_command("#{cmd} #{build_context}",
|
60
|
+
input: dockerfile_contents,
|
61
|
+
environment: { BUILDKIT_PROGRESS: 'plain' })
|
54
62
|
ensure
|
55
63
|
file.close unless file.closed?
|
56
64
|
file.unlink
|
@@ -1,164 +1,165 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (C) 2014, Sean Porter
|
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
|
-
require 'kitchen'
|
17
|
-
require 'json'
|
18
|
-
require 'securerandom'
|
19
|
-
require 'net/ssh'
|
20
|
-
|
21
|
-
require 'kitchen/driver/base'
|
22
|
-
|
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
|
-
|
28
|
-
module Kitchen
|
29
|
-
module Driver
|
30
|
-
# Docker driver for Kitchen.
|
31
|
-
#
|
32
|
-
# @author Sean Porter <portertech@gmail.com>
|
33
|
-
class Docker < Kitchen::Driver::Base
|
34
|
-
include Kitchen::Docker::Helpers::CliHelper
|
35
|
-
include Kitchen::Docker::Helpers::ContainerHelper
|
36
|
-
include ShellOut
|
37
|
-
|
38
|
-
default_config :binary, 'docker'
|
39
|
-
default_config :build_options, nil
|
40
|
-
default_config :cap_add, nil
|
41
|
-
default_config :cap_drop, nil
|
42
|
-
default_config :disable_upstart, true
|
43
|
-
default_config :env_variables, nil
|
44
|
-
default_config :
|
45
|
-
default_config :
|
46
|
-
default_config :
|
47
|
-
default_config :
|
48
|
-
default_config :
|
49
|
-
default_config :
|
50
|
-
default_config :
|
51
|
-
default_config :
|
52
|
-
default_config :
|
53
|
-
default_config :
|
54
|
-
default_config :
|
55
|
-
default_config :
|
56
|
-
default_config :
|
57
|
-
default_config :
|
58
|
-
default_config :
|
59
|
-
default_config :
|
60
|
-
default_config :
|
61
|
-
default_config :
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
#
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
'-o
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
socket = '
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
#
|
109
|
-
if
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
end
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014, Sean Porter
|
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
|
+
require 'kitchen'
|
17
|
+
require 'json'
|
18
|
+
require 'securerandom'
|
19
|
+
require 'net/ssh'
|
20
|
+
|
21
|
+
require 'kitchen/driver/base'
|
22
|
+
|
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
|
+
|
28
|
+
module Kitchen
|
29
|
+
module Driver
|
30
|
+
# Docker driver for Kitchen.
|
31
|
+
#
|
32
|
+
# @author Sean Porter <portertech@gmail.com>
|
33
|
+
class Docker < Kitchen::Driver::Base
|
34
|
+
include Kitchen::Docker::Helpers::CliHelper
|
35
|
+
include Kitchen::Docker::Helpers::ContainerHelper
|
36
|
+
include ShellOut
|
37
|
+
|
38
|
+
default_config :binary, 'docker'
|
39
|
+
default_config :build_options, nil
|
40
|
+
default_config :cap_add, nil
|
41
|
+
default_config :cap_drop, nil
|
42
|
+
default_config :disable_upstart, true
|
43
|
+
default_config :env_variables, nil
|
44
|
+
default_config :isolation, nil
|
45
|
+
default_config :interactive, false
|
46
|
+
default_config :private_key, File.join(Dir.pwd, '.kitchen', 'docker_id_rsa')
|
47
|
+
default_config :privileged, false
|
48
|
+
default_config :public_key, File.join(Dir.pwd, '.kitchen', 'docker_id_rsa.pub')
|
49
|
+
default_config :publish_all, false
|
50
|
+
default_config :remove_images, false
|
51
|
+
default_config :run_options, nil
|
52
|
+
default_config :security_opt, nil
|
53
|
+
default_config :tls, false
|
54
|
+
default_config :tls_cacert, nil
|
55
|
+
default_config :tls_cert, nil
|
56
|
+
default_config :tls_key, nil
|
57
|
+
default_config :tls_verify, false
|
58
|
+
default_config :tty, false
|
59
|
+
default_config :use_cache, true
|
60
|
+
default_config :use_internal_docker_network, false
|
61
|
+
default_config :use_sudo, false
|
62
|
+
default_config :wait_for_transport, true
|
63
|
+
|
64
|
+
default_config :build_context do |driver|
|
65
|
+
!driver.remote_socket?
|
66
|
+
end
|
67
|
+
|
68
|
+
default_config :image do |driver|
|
69
|
+
driver.default_image
|
70
|
+
end
|
71
|
+
|
72
|
+
default_config :instance_name do |driver|
|
73
|
+
# Borrowed from kitchen-rackspace
|
74
|
+
[
|
75
|
+
driver.instance.name.gsub(/\W/, ''),
|
76
|
+
(Etc.getlogin || 'nologin').gsub(/\W/, ''),
|
77
|
+
Socket.gethostname.gsub(/\W/, '')[0..20],
|
78
|
+
Array.new(8) { rand(36).to_s(36) }.join
|
79
|
+
].join('-').downcase
|
80
|
+
end
|
81
|
+
|
82
|
+
default_config :platform do |driver|
|
83
|
+
driver.default_platform
|
84
|
+
end
|
85
|
+
|
86
|
+
default_config :run_command do |driver|
|
87
|
+
if driver.windows_os?
|
88
|
+
# Launch arbitrary process to keep the Windows container alive
|
89
|
+
# If running in interactive mode, launch powershell.exe instead
|
90
|
+
if driver[:interactive]
|
91
|
+
'powershell.exe'
|
92
|
+
else
|
93
|
+
'ping -t localhost'
|
94
|
+
end
|
95
|
+
else
|
96
|
+
'/usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no -o PasswordAuthentication=yes '\
|
97
|
+
'-o UsePrivilegeSeparation=no -o PidFile=/tmp/sshd.pid'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
default_config :socket do |driver|
|
102
|
+
socket = 'unix:///var/run/docker.sock'
|
103
|
+
socket = 'npipe:////./pipe/docker_engine' if driver.windows_os?
|
104
|
+
ENV['DOCKER_HOST'] || socket
|
105
|
+
end
|
106
|
+
|
107
|
+
default_config :username do |driver|
|
108
|
+
# Return nil to prevent username from being added to Docker
|
109
|
+
# command line args for Windows if a username was not specified
|
110
|
+
if driver.windows_os?
|
111
|
+
nil
|
112
|
+
else
|
113
|
+
'kitchen'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def verify_dependencies
|
118
|
+
run_command("#{config[:binary]} >> #{dev_null} 2>&1", quiet: true, use_sudo: config[:use_sudo])
|
119
|
+
rescue
|
120
|
+
raise UserError, 'You must first install the Docker CLI tool https://www.docker.com/get-started'
|
121
|
+
end
|
122
|
+
|
123
|
+
def create(state)
|
124
|
+
container.create(state)
|
125
|
+
|
126
|
+
wait_for_transport(state)
|
127
|
+
end
|
128
|
+
|
129
|
+
def destroy(state)
|
130
|
+
container.destroy(state)
|
131
|
+
end
|
132
|
+
|
133
|
+
def wait_for_transport(state)
|
134
|
+
if config[:wait_for_transport]
|
135
|
+
instance.transport.connection(state) do |conn|
|
136
|
+
conn.wait_until_ready
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def default_image
|
142
|
+
platform, release = instance.platform.name.split('-')
|
143
|
+
if platform == 'centos' && release
|
144
|
+
release = 'centos' + release.split('.').first
|
145
|
+
end
|
146
|
+
release ? [platform, release].join(':') : platform
|
147
|
+
end
|
148
|
+
|
149
|
+
def default_platform
|
150
|
+
instance.platform.name.split('-').first
|
151
|
+
end
|
152
|
+
|
153
|
+
protected
|
154
|
+
|
155
|
+
def container
|
156
|
+
@container ||= if windows_os?
|
157
|
+
Kitchen::Docker::Container::Windows.new(config)
|
158
|
+
else
|
159
|
+
Kitchen::Docker::Container::Linux.new(config)
|
160
|
+
end
|
161
|
+
@container
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
data/test/Dockerfile
CHANGED
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.13.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: 2022-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-kitchen
|
@@ -176,14 +176,14 @@ dependencies:
|
|
176
176
|
requirements:
|
177
177
|
- - "~>"
|
178
178
|
- !ruby/object:Gem::Version
|
179
|
-
version: '
|
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: '
|
186
|
+
version: '2.0'
|
187
187
|
- !ruby/object:Gem::Dependency
|
188
188
|
name: train
|
189
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -212,6 +212,7 @@ extensions: []
|
|
212
212
|
extra_rdoc_files: []
|
213
213
|
files:
|
214
214
|
- ".cane"
|
215
|
+
- ".github/dependabot.yml"
|
215
216
|
- ".gitignore"
|
216
217
|
- ".kitchen.windows.yml"
|
217
218
|
- ".kitchen.yml"
|
@@ -232,6 +233,7 @@ files:
|
|
232
233
|
- lib/kitchen/docker/erb_context.rb
|
233
234
|
- lib/kitchen/docker/helpers/cli_helper.rb
|
234
235
|
- lib/kitchen/docker/helpers/container_helper.rb
|
236
|
+
- lib/kitchen/docker/helpers/dockerfile_helper.rb
|
235
237
|
- lib/kitchen/docker/helpers/file_helper.rb
|
236
238
|
- lib/kitchen/docker/helpers/image_helper.rb
|
237
239
|
- lib/kitchen/docker/helpers/inspec_helper.rb
|
@@ -249,7 +251,7 @@ homepage: https://github.com/test-kitchen/kitchen-docker
|
|
249
251
|
licenses:
|
250
252
|
- Apache 2.0
|
251
253
|
metadata: {}
|
252
|
-
post_install_message:
|
254
|
+
post_install_message:
|
253
255
|
rdoc_options: []
|
254
256
|
require_paths:
|
255
257
|
- lib
|
@@ -264,8 +266,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
264
266
|
- !ruby/object:Gem::Version
|
265
267
|
version: '0'
|
266
268
|
requirements: []
|
267
|
-
rubygems_version: 3.
|
268
|
-
signing_key:
|
269
|
+
rubygems_version: 3.2.3
|
270
|
+
signing_key:
|
269
271
|
specification_version: 4
|
270
272
|
summary: A Docker Driver for Test Kitchen
|
271
273
|
test_files:
|