kitchen-docker-api 0.2.2 → 0.3.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/README.md +62 -0
- data/lib/kitchen/driver/docker.rb +29 -2
- data/lib/kitchen/driver/docker_version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -67,6 +67,23 @@ platforms:
|
|
67
67
|
|
68
68
|
## Configuration
|
69
69
|
|
70
|
+
* [socket](#socket) - Configure the socket to connect to Docker daemon
|
71
|
+
* [image](#image) - base image used for Docker container
|
72
|
+
* [platform](#platform) - platform of Docker container
|
73
|
+
* [require_chef_omnibus](#require_chef_omnibus) - Install Chef?
|
74
|
+
* [container_name](#container_name) - Customize container name
|
75
|
+
* [disable_upstart](#disable_upstart) - Disable upstart tweaks during container build
|
76
|
+
* [dockerfile](#dockerfile) - Specify a custom Dockerfile
|
77
|
+
* [provision_command](#provision_command) - List of RUN commands during container build
|
78
|
+
* [remove_images](#remove_images) - Remove intermediate images after image creation
|
79
|
+
* [run_command](#run_command) - Command to run at container start
|
80
|
+
* [memory](#memory) - Memory limits for container
|
81
|
+
* [cpu](#cpu) - CPU limits for container
|
82
|
+
* [volume](#volume) - Volumes to mount in container
|
83
|
+
* [dns](#dns) - DNS servers to configure in container
|
84
|
+
* [forward](#forward) - Ports to forward to running container
|
85
|
+
* [privileged](#privileged) - Run container in privileged mode
|
86
|
+
|
70
87
|
### socket
|
71
88
|
|
72
89
|
The Docker daemon socket to use. By default, Docker will listen on
|
@@ -148,6 +165,51 @@ support a working upstart.
|
|
148
165
|
|
149
166
|
The default value is `true`.
|
150
167
|
|
168
|
+
### dockerfile
|
169
|
+
|
170
|
+
This allows you to point to a specific dockerfile used to prepare an
|
171
|
+
image for testing under test-kitchen. It is expected that this
|
172
|
+
Dockerfile will do everything necessary to configure the image for use
|
173
|
+
by kitchen-docker-api including:
|
174
|
+
|
175
|
+
* Setup the username & password kitchen-docker-api expects to use
|
176
|
+
* Provide the user with NOPASSWD sudo rights
|
177
|
+
* Ensure ssh is installed and will work at container start
|
178
|
+
* If using /sbin/init as `run_command` ensure ssh is started on start
|
179
|
+
* Install any requisite packages
|
180
|
+
* Specify a CMD, the driver will still use `config[:run_command]` at
|
181
|
+
container start but docker requires a CMD is specified
|
182
|
+
|
183
|
+
If you specify a dockerfile path kitchen-docker-api will take no action
|
184
|
+
to make sure your image is setup correctly, it will simply build an
|
185
|
+
image using the specified dockerfile & run that image.
|
186
|
+
|
187
|
+
Note that the dockerfile is parsed as ERB and the `config` hash from
|
188
|
+
`kitchen-docker-api` is passed into the template so any configuration in
|
189
|
+
your yml may be referenced inside the Dockerfile. This allows you to
|
190
|
+
place conditionals and other logic directly in your Dockerfile.
|
191
|
+
|
192
|
+
This parameter supports 3 types of values:
|
193
|
+
* File path (eg. `Dockerfile` or `/path/to/Dockerfile`)
|
194
|
+
* Http URL (eg. `http://someurl.com/Dockerfile` )
|
195
|
+
* `internal` will use the internal Dockerfile generator
|
196
|
+
|
197
|
+
Default value: `internal`
|
198
|
+
|
199
|
+
Example Dockerfile:
|
200
|
+
```erb
|
201
|
+
FROM tianon/centos:6.5
|
202
|
+
RUN yum clean all
|
203
|
+
RUN yum install -y sudo openssh-server openssh-clients curl
|
204
|
+
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
|
205
|
+
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
|
206
|
+
RUN mkdir -p /var/run/sshd
|
207
|
+
RUN useradd -d /home/<%= @username %> -m -s /bin/bash <%= @username %>
|
208
|
+
RUN echo <%= "#{@username}:#{@password}" %> | chpasswd
|
209
|
+
RUN echo '<%= @username %> ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
210
|
+
CMD [ "/usr/sbin/sshd", "-D", "-o", "UseDNS=no", "-o", "UsePAM=no" ]
|
211
|
+
```
|
212
|
+
|
151
213
|
### provision\_command
|
152
214
|
|
153
215
|
Custom command(s) to be run when provisioning the base for the suite containers.
|
@@ -19,10 +19,9 @@ require 'json'
|
|
19
19
|
require 'docker'
|
20
20
|
require 'socket'
|
21
21
|
|
22
|
-
module Kitchen
|
23
22
|
|
23
|
+
module Kitchen
|
24
24
|
module Driver
|
25
|
-
|
26
25
|
# Docker driver
|
27
26
|
class Docker < Kitchen::Driver::SSHBase
|
28
27
|
|
@@ -33,6 +32,7 @@ module Kitchen
|
|
33
32
|
default_config :username, 'kitchen'
|
34
33
|
default_config :password, 'kitchen'
|
35
34
|
default_config :read_timeout, 300
|
35
|
+
default_config :dockerfile, 'internal'
|
36
36
|
|
37
37
|
default_config :image do |driver|
|
38
38
|
driver.default_image
|
@@ -98,6 +98,14 @@ module Kitchen
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def dockerfile
|
101
|
+
if config[:dockerfile] == 'internal'
|
102
|
+
return internal_dockerfile
|
103
|
+
else
|
104
|
+
return fetch_dockerfile
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def internal_dockerfile
|
101
109
|
from = "FROM #{config[:image]}"
|
102
110
|
platform = case config[:platform]
|
103
111
|
when 'debian', 'ubuntu'
|
@@ -137,6 +145,13 @@ module Kitchen
|
|
137
145
|
[from, platform, base, custom].join("\n")
|
138
146
|
end
|
139
147
|
|
148
|
+
def fetch_dockerfile
|
149
|
+
require 'open-uri'
|
150
|
+
require 'erb'
|
151
|
+
erb = ERB.new(open(config[:dockerfile]) { |f| f.read })
|
152
|
+
erb.result(ERBContext.new(config).get_binding)
|
153
|
+
end
|
154
|
+
|
140
155
|
def container_config(state)
|
141
156
|
data = {
|
142
157
|
:Cmd => config[:run_command].split,
|
@@ -219,5 +234,17 @@ module Kitchen
|
|
219
234
|
container.delete
|
220
235
|
end
|
221
236
|
end
|
237
|
+
# Erb class
|
238
|
+
class ERBContext
|
239
|
+
def initialize(config)
|
240
|
+
config.each_pair do |k, v|
|
241
|
+
instance_variable_set('@' + k.to_s, v)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def get_binding
|
246
|
+
binding
|
247
|
+
end
|
248
|
+
end
|
222
249
|
end
|
223
250
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-docker-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-03-
|
13
|
+
date: 2014-03-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: test-kitchen
|