kitchen-docker 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -12
- data/lib/kitchen/driver/docker.rb +34 -17
- data/lib/kitchen/driver/docker_version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2739fe136af5fc12187dc12311614fc6ff543e5f
|
4
|
+
data.tar.gz: 8cf6f0f2da67f247289076f05e25030faa0ef616
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83cc959ba5834d55b19779a3c864a5682f63b010bf4d2aacb05ba465e997da4a2b43dccbb664ac47fef4e31dae5e3b8cc5f6867c9a882b5f9c630e57fd724b38
|
7
|
+
data.tar.gz: 87b9510146a4aaa80c79d942b4be82baff3fc93a0dac2d210098ff0cacbecc1fb883ab1400e909144bb898ba19c25071c4fa5e4266072e3e9473cfaa27842510
|
data/README.md
CHANGED
@@ -61,6 +61,24 @@ platforms:
|
|
61
61
|
|
62
62
|
## Configuration
|
63
63
|
|
64
|
+
### socket
|
65
|
+
|
66
|
+
The Docker daemon socket to use. By default, Docker it will listen on
|
67
|
+
`unix:///var/run/docker.sock`, and no configuration here is required. If
|
68
|
+
Docker is binding to another host/port or Unix socket, you will need to set
|
69
|
+
this option. If a TCP socket is set, its host will be used for SSH access
|
70
|
+
to containers.
|
71
|
+
|
72
|
+
Examples:
|
73
|
+
|
74
|
+
```
|
75
|
+
socket: unix:///tmp/docker.sock
|
76
|
+
```
|
77
|
+
|
78
|
+
```
|
79
|
+
socket: tcp://docker.example.com:4242
|
80
|
+
```
|
81
|
+
|
64
82
|
### image
|
65
83
|
|
66
84
|
The Docker image to use as the base for the suite containers. You can find
|
@@ -146,13 +164,13 @@ Adds a data volume(s) to the suite container.
|
|
146
164
|
Examples:
|
147
165
|
|
148
166
|
```
|
149
|
-
volume: /ftp
|
167
|
+
volume: /ftp
|
150
168
|
```
|
151
169
|
|
152
170
|
```
|
153
|
-
volume:
|
154
|
-
- /ftp
|
155
|
-
- /srv
|
171
|
+
volume:
|
172
|
+
- /ftp
|
173
|
+
- /srv
|
156
174
|
```
|
157
175
|
|
158
176
|
## dns
|
@@ -163,13 +181,13 @@ dockers defaults.
|
|
163
181
|
Examples:
|
164
182
|
|
165
183
|
```
|
166
|
-
dns: 8.8.8.8
|
184
|
+
dns: 8.8.8.8
|
167
185
|
```
|
168
186
|
|
169
187
|
```
|
170
|
-
dns:
|
171
|
-
- 8.8.8.8
|
172
|
-
- 8.8.4.4
|
188
|
+
dns:
|
189
|
+
- 8.8.8.8
|
190
|
+
- 8.8.4.4
|
173
191
|
```
|
174
192
|
|
175
193
|
### forward
|
@@ -180,13 +198,13 @@ the host (public) port in the mappings, if not, Docker chooses for you.
|
|
180
198
|
Examples:
|
181
199
|
|
182
200
|
```
|
183
|
-
forward: 80
|
201
|
+
forward: 80
|
184
202
|
```
|
185
203
|
|
186
204
|
```
|
187
|
-
forward:
|
188
|
-
- 22:2222
|
189
|
-
- 80:8080
|
205
|
+
forward:
|
206
|
+
- 22:2222
|
207
|
+
- 80:8080
|
190
208
|
```
|
191
209
|
|
192
210
|
## Development
|
@@ -26,15 +26,16 @@ module Kitchen
|
|
26
26
|
# @author Sean Porter <portertech@gmail.com>
|
27
27
|
class Docker < Kitchen::Driver::SSHBase
|
28
28
|
|
29
|
-
default_config :port, '22'
|
30
29
|
default_config :username, 'kitchen'
|
31
30
|
default_config :password, 'kitchen'
|
32
31
|
default_config :require_chef_omnibus, true
|
33
32
|
default_config :remove_images, false
|
34
33
|
default_config :use_sudo, true
|
34
|
+
|
35
35
|
default_config :image do |driver|
|
36
36
|
driver.default_image
|
37
37
|
end
|
38
|
+
|
38
39
|
default_config :platform do |driver|
|
39
40
|
driver.default_platform
|
40
41
|
end
|
@@ -58,8 +59,9 @@ module Kitchen
|
|
58
59
|
def create(state)
|
59
60
|
state[:image_id] = build_image(state) unless state[:image_id]
|
60
61
|
state[:container_id] = run_container(state) unless state[:container_id]
|
61
|
-
state[:hostname] =
|
62
|
-
|
62
|
+
state[:hostname] = remote_socket? ? socket_uri.host : 'localhost'
|
63
|
+
state[:port] = container_ssh_port(state)
|
64
|
+
wait_for_sshd(state[:hostname], :port => state[:port])
|
63
65
|
end
|
64
66
|
|
65
67
|
def destroy(state)
|
@@ -71,6 +73,20 @@ module Kitchen
|
|
71
73
|
|
72
74
|
protected
|
73
75
|
|
76
|
+
def socket_uri
|
77
|
+
URI.parse(config[:socket])
|
78
|
+
end
|
79
|
+
|
80
|
+
def remote_socket?
|
81
|
+
config[:socket] ? socket_uri.scheme == 'tcp' : false
|
82
|
+
end
|
83
|
+
|
84
|
+
def docker_command(cmd, options={})
|
85
|
+
docker = "docker"
|
86
|
+
docker << " -H #{config[:socket]}" if config[:socket]
|
87
|
+
run_command("#{docker} #{cmd}", options)
|
88
|
+
end
|
89
|
+
|
74
90
|
def dockerfile
|
75
91
|
from = "FROM #{config[:image]}"
|
76
92
|
platform = case config[:platform]
|
@@ -119,13 +135,13 @@ module Kitchen
|
|
119
135
|
end
|
120
136
|
|
121
137
|
def build_image(state)
|
122
|
-
output =
|
138
|
+
output = docker_command("build -", :input => dockerfile)
|
123
139
|
parse_image_id(output)
|
124
140
|
end
|
125
141
|
|
126
142
|
def parse_container_id(output)
|
127
143
|
container_id = output.chomp
|
128
|
-
unless container_id.size
|
144
|
+
unless [12, 64].include?(container_id.size)
|
129
145
|
raise ActionFailed,
|
130
146
|
'Could not parse Docker run output for container ID'
|
131
147
|
end
|
@@ -133,7 +149,7 @@ module Kitchen
|
|
133
149
|
end
|
134
150
|
|
135
151
|
def build_run_command(image_id)
|
136
|
-
cmd =
|
152
|
+
cmd = "run -d -p 22"
|
137
153
|
Array(config[:forward]).each {|port| cmd << " -p #{port}"}
|
138
154
|
Array(config[:dns]).each {|dns| cmd << " -dns #{dns}"}
|
139
155
|
Array(config[:volume]).each {|volume| cmd << " -v #{volume}"}
|
@@ -145,36 +161,37 @@ module Kitchen
|
|
145
161
|
|
146
162
|
def run_container(state)
|
147
163
|
cmd = build_run_command(state[:image_id])
|
148
|
-
output =
|
164
|
+
output = docker_command(cmd)
|
149
165
|
parse_container_id(output)
|
150
166
|
end
|
151
167
|
|
152
|
-
def
|
168
|
+
def parse_container_ssh_port(output)
|
153
169
|
begin
|
154
170
|
info = Array(::JSON.parse(output)).first
|
155
|
-
|
156
|
-
|
171
|
+
ports = info['NetworkSettings']['Ports']
|
172
|
+
ssh_port = ports['22/tcp'].detect {|port| port['HostIp'] == '0.0.0.0'}
|
173
|
+
ssh_port['HostPort'].to_i
|
157
174
|
rescue
|
158
175
|
raise ActionFailed,
|
159
|
-
'Could not parse Docker inspect output for container
|
176
|
+
'Could not parse Docker inspect output for container SSH port'
|
160
177
|
end
|
161
178
|
end
|
162
179
|
|
163
|
-
def
|
180
|
+
def container_ssh_port(state)
|
164
181
|
container_id = state[:container_id]
|
165
|
-
output =
|
166
|
-
|
182
|
+
output = docker_command("inspect #{container_id}")
|
183
|
+
parse_container_ssh_port(output)
|
167
184
|
end
|
168
185
|
|
169
186
|
def rm_container(state)
|
170
187
|
container_id = state[:container_id]
|
171
|
-
|
172
|
-
|
188
|
+
docker_command("stop #{container_id}")
|
189
|
+
docker_command("rm #{container_id}")
|
173
190
|
end
|
174
191
|
|
175
192
|
def rm_image(state)
|
176
193
|
image_id = state[:image_id]
|
177
|
-
|
194
|
+
docker_command("rmi #{image_id}")
|
178
195
|
end
|
179
196
|
end
|
180
197
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-docker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Porter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-kitchen
|
@@ -138,3 +138,4 @@ signing_key:
|
|
138
138
|
specification_version: 4
|
139
139
|
summary: A Test Kitchen Driver for Docker
|
140
140
|
test_files: []
|
141
|
+
has_rdoc:
|