kitchen-docker-api 0.1.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.
- data/.gitignore +19 -0
- data/.kitchen.yml +14 -0
- data/.tailor +4 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -0
- data/LICENSE +15 -0
- data/README.md +291 -0
- data/Rakefile +28 -0
- data/kitchen-docker-api.gemspec +30 -0
- data/lib/kitchen/driver/docker.rb +211 -0
- data/lib/kitchen/driver/docker_version.rb +24 -0
- metadata +171 -0
data/.gitignore
ADDED
data/.kitchen.yml
ADDED
data/.tailor
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Author:: Aaron Nichols <anichols@trumped.org>
|
2
|
+
|
3
|
+
Copyright (C) 2014, Aaron Nichols
|
4
|
+
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
you may not use this file except in compliance with the License.
|
7
|
+
You may obtain a copy of the License at
|
8
|
+
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
See the License for the specific language governing permissions and
|
15
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,291 @@
|
|
1
|
+
# Kitchen::Docker
|
2
|
+
|
3
|
+
A Test Kitchen Driver for Docker. This driver utilizes the
|
4
|
+
[docker-api](https://github.com/swipely/docker-api) gem as the docker
|
5
|
+
client making a CLI client unnecessary. If you would prefer a docker
|
6
|
+
driver which uses the docker CLI you should look at the original
|
7
|
+
[kitchen-docker](https://github.com/portertech/kitchen-docker) from
|
8
|
+
which this fork originated.
|
9
|
+
|
10
|
+
Substantial credit for this driver goes to Sean Porter for the CLI
|
11
|
+
implmentation & his support in developing the docker-api based version.
|
12
|
+
We ultimately decided it would be best to have two versions so folks
|
13
|
+
could choose to use the CLI or docker-api based client.
|
14
|
+
|
15
|
+
## Requirements
|
16
|
+
|
17
|
+
* [Docker][docker_getting_started]
|
18
|
+
|
19
|
+
## Known Issues
|
20
|
+
|
21
|
+
* Upstart is neutered due to [this issue][docker_upstart_issue].
|
22
|
+
|
23
|
+
## Installation and Setup
|
24
|
+
|
25
|
+
Please read the Test Kitchen [docs][test_kitchen_docs] for more details.
|
26
|
+
|
27
|
+
Example `.kitchen.local.yml`:
|
28
|
+
|
29
|
+
```
|
30
|
+
---
|
31
|
+
driver_plugin: docker
|
32
|
+
|
33
|
+
platforms:
|
34
|
+
- name: ubuntu
|
35
|
+
run_list:
|
36
|
+
- recipe[apt]
|
37
|
+
- name: centos
|
38
|
+
driver_config:
|
39
|
+
image: centos
|
40
|
+
platform: rhel
|
41
|
+
run_list:
|
42
|
+
- recipe[yum]
|
43
|
+
```
|
44
|
+
|
45
|
+
## Default Configuration
|
46
|
+
|
47
|
+
This driver can determine an image and platform type for a select number of
|
48
|
+
platforms. Currently, the following platform names are supported:
|
49
|
+
|
50
|
+
```
|
51
|
+
---
|
52
|
+
platforms:
|
53
|
+
- name: ubuntu-12.04
|
54
|
+
- name: centos-6.4
|
55
|
+
```
|
56
|
+
|
57
|
+
This will effectively generate a configuration similar to:
|
58
|
+
|
59
|
+
```
|
60
|
+
---
|
61
|
+
platforms:
|
62
|
+
- name: ubuntu-12.04
|
63
|
+
driver_config:
|
64
|
+
image: ubuntu:12.04
|
65
|
+
platform: ubuntu
|
66
|
+
- name: centos-6.4
|
67
|
+
driver_config:
|
68
|
+
image: centos:6.4
|
69
|
+
platform: centos
|
70
|
+
```
|
71
|
+
|
72
|
+
## Configuration
|
73
|
+
|
74
|
+
### socket
|
75
|
+
|
76
|
+
The Docker daemon socket to use. By default, Docker will listen on
|
77
|
+
`unix:///var/run/docker.sock`, and no configuration here is required. If
|
78
|
+
Docker is binding to another host/port or Unix socket, you will need to set
|
79
|
+
this option. If a TCP socket is set, its host will be used for SSH access
|
80
|
+
to suite containers.
|
81
|
+
|
82
|
+
Examples:
|
83
|
+
|
84
|
+
```
|
85
|
+
socket: unix:///tmp/docker.sock
|
86
|
+
```
|
87
|
+
|
88
|
+
```
|
89
|
+
socket: tcp://docker.example.com:4242
|
90
|
+
```
|
91
|
+
|
92
|
+
### image
|
93
|
+
|
94
|
+
The Docker image to use as the base for the suite containers. You can find
|
95
|
+
images using the [Docker Index][docker_index].
|
96
|
+
|
97
|
+
The default will be determined by the Platform name, if a default exists
|
98
|
+
(see the Default Configuration section for more details). If a default
|
99
|
+
cannot be computed, then the default value is `base`, an official Ubuntu
|
100
|
+
[image][docker_default_image].
|
101
|
+
|
102
|
+
### platform
|
103
|
+
|
104
|
+
The platform of the chosen image. This is used to properly bootstrap the
|
105
|
+
suite container for Test Kitchen. Kitchen Docker currently supports:
|
106
|
+
|
107
|
+
* `debian` or `ubuntu`
|
108
|
+
* `rhel` or `centos`
|
109
|
+
|
110
|
+
The default will be determined by the Platform name, if a default exists
|
111
|
+
(see the Default Configuration section for more details). If a default
|
112
|
+
cannot be computed, then the default value is `ubuntu`.
|
113
|
+
|
114
|
+
### require\_chef\_omnibus
|
115
|
+
|
116
|
+
Determines whether or not a Chef [Omnibus package][chef_omnibus_dl] will be
|
117
|
+
installed. There are several different behaviors available:
|
118
|
+
|
119
|
+
* `true` - the latest release will be installed. Subsequent converges
|
120
|
+
will skip re-installing if chef is present.
|
121
|
+
* `latest` - the latest release will be installed. Subsequent converges
|
122
|
+
will always re-install even if chef is present.
|
123
|
+
* `<VERSION_STRING>` (ex: `10.24.0`) - the desired version string will
|
124
|
+
be passed the the install.sh script. Subsequent converges will skip if
|
125
|
+
the installed version and the desired version match.
|
126
|
+
* `false` or `nil` - no chef is installed.
|
127
|
+
|
128
|
+
The default value is `true`.
|
129
|
+
|
130
|
+
### provision\_command
|
131
|
+
|
132
|
+
Custom command(s) to be run when provisioning the base for the suite containers.
|
133
|
+
|
134
|
+
Examples:
|
135
|
+
|
136
|
+
```
|
137
|
+
provision_command: curl -L https://www.opscode.com/chef/install.sh | bash
|
138
|
+
```
|
139
|
+
|
140
|
+
```
|
141
|
+
provision_command:
|
142
|
+
- apt-get install dnsutils
|
143
|
+
- apt-get install telnet
|
144
|
+
```
|
145
|
+
|
146
|
+
```
|
147
|
+
driver_config:
|
148
|
+
provision_command: curl -L https://www.opscode.com/chef/install.sh | bash
|
149
|
+
require_chef_omnibus: false
|
150
|
+
```
|
151
|
+
|
152
|
+
### remove\_images
|
153
|
+
|
154
|
+
This determines if images are automatically removed when the suite container is
|
155
|
+
destroyed.
|
156
|
+
|
157
|
+
The default value is `false`.
|
158
|
+
|
159
|
+
### run_command
|
160
|
+
|
161
|
+
Sets the command used to run the suite container.
|
162
|
+
|
163
|
+
The default value is `/usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no`.
|
164
|
+
|
165
|
+
Examples:
|
166
|
+
|
167
|
+
```
|
168
|
+
run_command: /sbin/init
|
169
|
+
```
|
170
|
+
|
171
|
+
### memory
|
172
|
+
|
173
|
+
Sets the memory limit for the suite container in bytes. Otherwise use Dockers
|
174
|
+
default. You can read more about `memory.limit_in_bytes` [here][memory_limit].
|
175
|
+
|
176
|
+
### cpu
|
177
|
+
|
178
|
+
Sets the CPU shares (relative weight) for the suite container. Otherwise use
|
179
|
+
Dockers defaults. You can read more about cpu.shares [here][cpu_shares].
|
180
|
+
|
181
|
+
### volume
|
182
|
+
|
183
|
+
Adds a data volume(s) to the suite container.
|
184
|
+
|
185
|
+
Examples:
|
186
|
+
|
187
|
+
```
|
188
|
+
volume: /ftp
|
189
|
+
```
|
190
|
+
|
191
|
+
```
|
192
|
+
volume:
|
193
|
+
- /ftp
|
194
|
+
- /srv
|
195
|
+
```
|
196
|
+
|
197
|
+
## dns
|
198
|
+
|
199
|
+
Adjusts `resolv.conf` to use the dns servers specified. Otherwise use
|
200
|
+
Dockers defaults.
|
201
|
+
|
202
|
+
Examples:
|
203
|
+
|
204
|
+
```
|
205
|
+
dns: 8.8.8.8
|
206
|
+
```
|
207
|
+
|
208
|
+
```
|
209
|
+
dns:
|
210
|
+
- 8.8.8.8
|
211
|
+
- 8.8.4.4
|
212
|
+
```
|
213
|
+
|
214
|
+
### forward
|
215
|
+
|
216
|
+
Set suite container port(s) to forward to the host machine. You may specify
|
217
|
+
the host (public) port in the mappings, if not, Docker chooses for you.
|
218
|
+
|
219
|
+
Examples:
|
220
|
+
|
221
|
+
```
|
222
|
+
forward: 80
|
223
|
+
```
|
224
|
+
|
225
|
+
```
|
226
|
+
forward:
|
227
|
+
- 22:2222
|
228
|
+
- 80:8080
|
229
|
+
```
|
230
|
+
|
231
|
+
### hostname
|
232
|
+
|
233
|
+
Set the suite container hostname. Otherwise use Dockers default.
|
234
|
+
|
235
|
+
Examples:
|
236
|
+
|
237
|
+
```
|
238
|
+
hostname: foobar.local
|
239
|
+
```
|
240
|
+
|
241
|
+
### privileged
|
242
|
+
|
243
|
+
Run the suite container in privileged mode. This allows certain functionality
|
244
|
+
inside the Docker container which is not otherwise permitted.
|
245
|
+
|
246
|
+
The default value is `false`.
|
247
|
+
|
248
|
+
Examples:
|
249
|
+
|
250
|
+
```
|
251
|
+
privileged: true
|
252
|
+
```
|
253
|
+
|
254
|
+
## Development
|
255
|
+
|
256
|
+
* Source hosted at [GitHub][repo]
|
257
|
+
* Report issues/questions/feature requests on [GitHub Issues][issues]
|
258
|
+
|
259
|
+
Pull requests are very welcome! Make sure your patches are well tested.
|
260
|
+
Ideally create a topic branch for every separate change you make. For
|
261
|
+
example:
|
262
|
+
|
263
|
+
1. Fork the repo
|
264
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
265
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
266
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
267
|
+
5. Create new Pull Request
|
268
|
+
|
269
|
+
## Authors
|
270
|
+
|
271
|
+
Created and maintained by [Aaron Nichols][author] (<anichols@trumped.org>)
|
272
|
+
|
273
|
+
Original kitchen-docker by [Sean Porter](<portertech@gmail.com>)
|
274
|
+
|
275
|
+
## License
|
276
|
+
|
277
|
+
Apache 2.0 (see [LICENSE][license])
|
278
|
+
|
279
|
+
|
280
|
+
[author]: https://github.com/adnichols
|
281
|
+
[issues]: https://github.com/adnichols/kitchen-docker-api/issues
|
282
|
+
[license]: https://github.com/adnichols/kitchen-docker-api/blob/master/LICENSE
|
283
|
+
[repo]: https://github.com/adnichols/kitchen-docker-api
|
284
|
+
[docker_getting_started]: http://www.docker.io/gettingstarted/
|
285
|
+
[docker_upstart_issue]: https://github.com/dotcloud/docker/issues/223
|
286
|
+
[docker_index]: https://index.docker.io/
|
287
|
+
[docker_default_image]: https://index.docker.io/_/base/
|
288
|
+
[test_kitchen_docs]: http://kitchen.ci/docs/getting-started/
|
289
|
+
[chef_omnibus_dl]: http://www.opscode.com/chef/install/
|
290
|
+
[cpu_shares]: https://docs.fedoraproject.org/en-US/Fedora/17/html/Resource_Management_Guide/sec-cpu.html
|
291
|
+
[memory_limit]: https://docs.fedoraproject.org/en-US/Fedora/17/html/Resource_Management_Guide/sec-memory.html
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'cane/rake_task'
|
3
|
+
require 'tailor/rake_task'
|
4
|
+
|
5
|
+
desc "Run cane to check quality metrics"
|
6
|
+
Cane::RakeTask.new do |cane|
|
7
|
+
cane.canefile = './.cane'
|
8
|
+
end
|
9
|
+
|
10
|
+
Tailor::RakeTask.new
|
11
|
+
|
12
|
+
desc "Display LOC stats"
|
13
|
+
task :stats do
|
14
|
+
puts "\n## Production Code Stats"
|
15
|
+
sh "countloc -r lib"
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Run all quality tasks"
|
19
|
+
task :quality => [:cane, :tailor, :stats]
|
20
|
+
|
21
|
+
task :default => [:quality]
|
22
|
+
|
23
|
+
begin
|
24
|
+
require 'kitchen/rake_tasks'
|
25
|
+
Kitchen::RakeTasks.new
|
26
|
+
rescue LoadError
|
27
|
+
puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI']
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kitchen/driver/docker_version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'kitchen-docker-api'
|
8
|
+
spec.version = Kitchen::Driver::DOCKER_VERSION
|
9
|
+
spec.authors = ['Sean Porter', 'Aaron Nichols']
|
10
|
+
spec.email = ['anichols@trumped.org']
|
11
|
+
spec.description = %q{A Test Kitchen Driver for Docker - docker-api based}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = 'https://github.com/adnichols/kitchen-docker-api'
|
14
|
+
spec.license = 'Apache 2.0'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = []
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'test-kitchen', '>= 1.0.0'
|
22
|
+
spec.add_dependency 'docker-api', '~> 1.9.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'cane'
|
28
|
+
spec.add_development_dependency 'tailor'
|
29
|
+
spec.add_development_dependency 'countloc'
|
30
|
+
end
|
@@ -0,0 +1,211 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014, Aaron Nichols
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'kitchen'
|
18
|
+
require 'json'
|
19
|
+
require 'docker'
|
20
|
+
|
21
|
+
module Kitchen
|
22
|
+
|
23
|
+
module Driver
|
24
|
+
|
25
|
+
# Docker driver
|
26
|
+
class Docker < Kitchen::Driver::SSHBase
|
27
|
+
|
28
|
+
default_config :socket, 'unix:///var/run/docker.sock'
|
29
|
+
default_config :privileged, false
|
30
|
+
default_config :remove_images, false
|
31
|
+
default_config :run_command, '/usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no'
|
32
|
+
default_config :username, 'kitchen'
|
33
|
+
default_config :password, 'kitchen'
|
34
|
+
default_config :read_timeout, 300
|
35
|
+
|
36
|
+
default_config :image do |driver|
|
37
|
+
driver.default_image
|
38
|
+
end
|
39
|
+
|
40
|
+
default_config :platform do |driver|
|
41
|
+
driver.default_platform
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize(*args)
|
45
|
+
super(*args)
|
46
|
+
@docker_connection = ::Docker::Connection.new(config[:socket], :read_timeout => config[:read_timeout])
|
47
|
+
if Kitchen.logger.debug?
|
48
|
+
::Docker.logger = Kitchen.logger
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def default_image
|
53
|
+
platform, release = instance.platform.name.split('-')
|
54
|
+
release ? [platform, release].join(':') : 'base'
|
55
|
+
end
|
56
|
+
|
57
|
+
def default_platform
|
58
|
+
platform, release = instance.platform.name.split('-')
|
59
|
+
release ? platform : 'ubuntu'
|
60
|
+
end
|
61
|
+
|
62
|
+
def create(state)
|
63
|
+
state[:image_id] = create_image(state) unless state[:image_id]
|
64
|
+
state[:container_id] = create_container(state) unless state[:container_id]
|
65
|
+
state[:hostname] = container_ssh_host
|
66
|
+
state[:port] = container_ssh_port(state)
|
67
|
+
wait_for_sshd(state[:hostname], nil, :port => state[:port])
|
68
|
+
end
|
69
|
+
|
70
|
+
def destroy(state)
|
71
|
+
destroy_container(state) if state[:container_id]
|
72
|
+
if config[:remove_images] && state[:image_id]
|
73
|
+
destroy_image(state)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
protected
|
78
|
+
|
79
|
+
def socket_uri
|
80
|
+
URI.parse(config[:socket])
|
81
|
+
end
|
82
|
+
|
83
|
+
def remote_socket?
|
84
|
+
config[:socket] ? socket_uri.scheme == 'tcp' : false
|
85
|
+
end
|
86
|
+
|
87
|
+
def dockerfile
|
88
|
+
from = "FROM #{config[:image]}"
|
89
|
+
platform = case config[:platform]
|
90
|
+
when 'debian', 'ubuntu'
|
91
|
+
<<-eos
|
92
|
+
ENV DEBIAN_FRONTEND noninteractive
|
93
|
+
RUN dpkg-divert --local --rename --add /sbin/initctl
|
94
|
+
RUN ln -sf /bin/true /sbin/initctl
|
95
|
+
RUN apt-get update
|
96
|
+
RUN apt-get install -y sudo openssh-server curl lsb-release
|
97
|
+
eos
|
98
|
+
when 'rhel', 'centos'
|
99
|
+
<<-eos
|
100
|
+
RUN yum clean all
|
101
|
+
RUN yum install -y sudo openssh-server openssh-clients curl
|
102
|
+
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
|
103
|
+
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
|
104
|
+
eos
|
105
|
+
else
|
106
|
+
raise ActionFailed,
|
107
|
+
"Unknown platform '#{config[:platform]}'"
|
108
|
+
end
|
109
|
+
username = config[:username]
|
110
|
+
password = config[:password]
|
111
|
+
base = <<-eos
|
112
|
+
RUN mkdir -p /var/run/sshd
|
113
|
+
RUN useradd -d /home/#{username} -m -s /bin/bash #{username}
|
114
|
+
RUN echo #{username}:#{password} | chpasswd
|
115
|
+
RUN echo '#{username} ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
116
|
+
eos
|
117
|
+
custom = ''
|
118
|
+
Array(config[:provision_command]).each do |cmd|
|
119
|
+
custom << "RUN #{cmd}\n"
|
120
|
+
end
|
121
|
+
[from, platform, base, custom].join("\n")
|
122
|
+
end
|
123
|
+
|
124
|
+
def container_config(state)
|
125
|
+
data = {
|
126
|
+
:Cmd => config[:run_command].split,
|
127
|
+
:Image => state[:image_id],
|
128
|
+
:AttachStdout => true,
|
129
|
+
:AttachStderr => true,
|
130
|
+
:Privileged => config[:privileged],
|
131
|
+
:PublishAllPorts => false
|
132
|
+
}
|
133
|
+
data[:CpuShares] = config[:cpu] if config[:cpu]
|
134
|
+
data[:Dns] = config[:dns] if config[:dns]
|
135
|
+
data[:Hostname] = config[:hostname] if config[:hostname]
|
136
|
+
data[:Memory] = config[:memory] if config[:memory]
|
137
|
+
forward = ['22'] + Array(config[:forward]).map { |mapping| mapping.to_s }
|
138
|
+
forward.compact!
|
139
|
+
data[:PortSpecs] = forward
|
140
|
+
data[:PortBindings] = forward.inject({}) do |bindings, mapping|
|
141
|
+
guest_port, host_port = mapping.split(':').reverse
|
142
|
+
bindings["#{guest_port}/tcp"] = [{
|
143
|
+
:HostIp => '',
|
144
|
+
:HostPort => host_port || ''
|
145
|
+
}]
|
146
|
+
bindings
|
147
|
+
end
|
148
|
+
data[:Volumes] = Hash[Array(config[:volume]).map { |volume| [volume, {}] }]
|
149
|
+
data
|
150
|
+
end
|
151
|
+
|
152
|
+
def parse_log_chunk(chunk)
|
153
|
+
if ::Kitchen.logger.debug?
|
154
|
+
logger.debug chunk
|
155
|
+
else
|
156
|
+
parsed_chunk = JSON.parse(chunk)
|
157
|
+
parsed_chunk.each do |k, v|
|
158
|
+
if [ "stream", "status" ].include? k
|
159
|
+
logger.info parsed_chunk[k].strip
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def create_image(state, opts = {})
|
166
|
+
info("Fetching Docker base image '#{config[:image]}' and building...")
|
167
|
+
opts[:rm] = config[:remove_images]
|
168
|
+
image = ::Docker::Image.build(dockerfile, opts, @docker_connection) do |chunk|
|
169
|
+
parse_log_chunk(chunk)
|
170
|
+
end
|
171
|
+
image.id
|
172
|
+
end
|
173
|
+
|
174
|
+
def create_container(state)
|
175
|
+
config_data = container_config(state)
|
176
|
+
container = ::Docker::Container.create(config_data, @docker_connection)
|
177
|
+
container.start(config_data)
|
178
|
+
container.id
|
179
|
+
end
|
180
|
+
|
181
|
+
def docker_image(state)
|
182
|
+
::Docker::Image.get(state[:image_id], nil, @docker_connection)
|
183
|
+
end
|
184
|
+
|
185
|
+
def docker_container(state)
|
186
|
+
::Docker::Container.get(state[:container_id], nil, @docker_connection)
|
187
|
+
end
|
188
|
+
|
189
|
+
def container_ssh_host
|
190
|
+
remote_socket? ? socket_uri.host : 'localhost'
|
191
|
+
end
|
192
|
+
|
193
|
+
def container_ssh_port(state)
|
194
|
+
container = docker_container(state)
|
195
|
+
container.json['NetworkSettings']['Ports']['22/tcp'].first['HostPort']
|
196
|
+
end
|
197
|
+
|
198
|
+
def destroy_container(state)
|
199
|
+
container = docker_container(state)
|
200
|
+
container.stop
|
201
|
+
container.wait
|
202
|
+
container.delete
|
203
|
+
end
|
204
|
+
|
205
|
+
def destroy_image(state)
|
206
|
+
image = docker_image(state)
|
207
|
+
image.remove
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2014, Aaron Nichols
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module Kitchen
|
18
|
+
|
19
|
+
module Driver
|
20
|
+
|
21
|
+
# Version string for Docker Kitchen driver
|
22
|
+
DOCKER_VERSION = "0.1.0"
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kitchen-docker-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sean Porter
|
9
|
+
- Aaron Nichols
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: test-kitchen
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 1.0.0
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: docker-api
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 1.9.0
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.9.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.3'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rake
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: cane
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: tailor
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: countloc
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
description: A Test Kitchen Driver for Docker - docker-api based
|
128
|
+
email:
|
129
|
+
- anichols@trumped.org
|
130
|
+
executables: []
|
131
|
+
extensions: []
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- .gitignore
|
135
|
+
- .kitchen.yml
|
136
|
+
- .tailor
|
137
|
+
- .travis.yml
|
138
|
+
- CHANGELOG.md
|
139
|
+
- Gemfile
|
140
|
+
- LICENSE
|
141
|
+
- README.md
|
142
|
+
- Rakefile
|
143
|
+
- kitchen-docker-api.gemspec
|
144
|
+
- lib/kitchen/driver/docker.rb
|
145
|
+
- lib/kitchen/driver/docker_version.rb
|
146
|
+
homepage: https://github.com/adnichols/kitchen-docker-api
|
147
|
+
licenses:
|
148
|
+
- Apache 2.0
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ! '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 1.8.23
|
168
|
+
signing_key:
|
169
|
+
specification_version: 3
|
170
|
+
summary: A Test Kitchen Driver for Docker - docker-api based
|
171
|
+
test_files: []
|