kitchen-dokken 2.4.3 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c96c48b219e98045ac11e51e56610767eaba3b5
4
- data.tar.gz: f3bdb6494d7c029ce6144d27a8ffa1448940309b
3
+ metadata.gz: 5cb3ca939dbea3ff17317f0e2dc84221cbafab95
4
+ data.tar.gz: a0e116039de06714f0f0968be5742499b76534a1
5
5
  SHA512:
6
- metadata.gz: 2c452fb897d7a6cfa9a537e403b205556578f079592eee2746418b79a2069b7956c250638e887cc2f1ca0b8784785783c3bdb6b5ded4c7991e48d698fa090914
7
- data.tar.gz: ec2525c3c9baae58bb5aeaa4ef206d586e1f5ab6672c1633a9e9bbf0f3ca4957e1f4004b5887d99e620adc67922008c2b4849de073a5b0819d7057f64af9cc2b
6
+ metadata.gz: 13b58476cfb34012b99105568d87ce7fd165467e0bc3abcae79978f838612707ab00fabd8335eca7cbeb487a232feec29018f629aba49825b691bdcc69d9d886
7
+ data.tar.gz: 17c563f9084e427b20de70820bc25a91e0c1f9628cf30ab23691306a3e99b0219439b87eb174005062e6531da96d24a0c64add832595bbbd96f96fcc819a36a1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Dokken Changelog
2
2
 
3
+ # 2.5.0
4
+ - Adding support for exposing ports.
5
+ - Port systax matches docker-compose
6
+
7
+ ```
8
+ driver:
9
+ hostname: www.computers.biz
10
+ port "1234"
11
+ ```
12
+ ...or something like
13
+
14
+ ```
15
+ driver:
16
+ hostname: www.computers.biz
17
+ ports:
18
+ - '1234'
19
+ - '4321:4321/udp'
20
+ ```
21
+
3
22
  # 2.4.3
4
23
  - Using better paths for lockfiles
5
24
 
@@ -42,9 +42,8 @@ module Kitchen
42
42
  default_config :data_image, 'dokken/kitchen-cache:latest'
43
43
  default_config :dns, nil
44
44
  default_config :dns_search, nil
45
- # default_config :docker_info, docker_info
45
+ default_config :ports, nil
46
46
  default_config :docker_host_url, default_docker_host
47
- default_config :forward, nil
48
47
  default_config :hostname, 'dokken'
49
48
  default_config :image_prefix, nil
50
49
  default_config :links, nil
@@ -57,7 +56,7 @@ module Kitchen
57
56
  default_config :write_timeout, 3600
58
57
 
59
58
  # (see Base#create)
60
- def create(state)
59
+ def create(state)
61
60
  # image to config
62
61
  pull_platform_image
63
62
 
@@ -100,6 +99,12 @@ module Kitchen
100
99
 
101
100
  private
102
101
 
102
+ class PartialHash < Hash
103
+ def ==(other)
104
+ other.is_a?(Hash) && all? { |key, val| other.key?(key) && other[key] == val }
105
+ end
106
+ end
107
+
103
108
  def api_retries
104
109
  config[:api_retries]
105
110
  end
@@ -195,12 +200,6 @@ module Kitchen
195
200
  instance_name
196
201
  end
197
202
 
198
- class PartialHash < Hash
199
- def ==(other)
200
- other.is_a?(Hash) && all? { |key, val| other.key?(key) && other[key] == val }
201
- end
202
- end
203
-
204
203
  def dokken_binds
205
204
  ret = []
206
205
  ret << "#{dokken_kitchen_sandbox}:/opt/kitchen" unless dokken_kitchen_sandbox.nil? || remote_docker_host?
@@ -248,7 +247,7 @@ module Kitchen
248
247
  'Cmd' => Shellwords.shellwords(self[:pid_one_command]),
249
248
  'Image' => "#{repo(work_image)}:#{tag(work_image)}",
250
249
  'Hostname' => self[:hostname],
251
- 'ExposedPorts' => exposed_ports({}, self[:forward]),
250
+ 'ExposedPorts' => exposed_ports,
252
251
  'Volumes' => dokken_volumes,
253
252
  'HostConfig' => {
254
253
  'Privileged' => self[:privileged],
@@ -261,7 +260,7 @@ module Kitchen
261
260
  'CapDrop' => Array(self[:cap_drop]),
262
261
  'SecurityOpt' => Array(self[:security_opt]),
263
262
  'NetworkMode' => self[:network_mode],
264
- 'PortBindings' => port_forwards({}, self[:forward]),
263
+ 'PortBindings' => port_bindings,
265
264
  },
266
265
  'NetworkingConfig' => {
267
266
  'EndpointsConfig' => {
@@ -281,7 +280,7 @@ module Kitchen
281
280
  'name' => data_container_name,
282
281
  'Image' => "#{repo(data_image)}:#{tag(data_image)}",
283
282
  'HostConfig' => {
284
- 'PortBindings' => port_forwards({}, '22'),
283
+ 'PortBindings' => port_bindings,
285
284
  'PublishAllPorts' => true,
286
285
  'NetworkMode' => 'bridge',
287
286
  },
@@ -487,24 +486,6 @@ module Kitchen
487
486
  release ? [platform, release].join(':') : platform
488
487
  end
489
488
 
490
- def exposed_ports(config, rules)
491
- Array(rules).each do |prt_string|
492
- guest, _host = prt_string.to_s.split(':').reverse
493
- config["#{guest}/tcp"] = {}
494
- end
495
- config
496
- end
497
-
498
- def port_forwards(config, rules)
499
- Array(rules).each do |prt_string|
500
- guest, host = prt_string.to_s.split(':').reverse
501
- config["#{guest}/tcp"] = [{
502
- HostPort: host || '',
503
- }]
504
- end
505
- config
506
- end
507
-
508
489
  def pull_if_missing(image)
509
490
  return if ::Docker::Image.exist?("#{repo(image)}:#{tag(image)}", {}, docker_connection)
510
491
  pull_image image
@@ -19,6 +19,6 @@
19
19
  module Kitchen
20
20
  module Driver
21
21
  # Version string for Dokken Kitchen driver
22
- DOKKEN_VERSION = '2.4.3'.freeze
22
+ DOKKEN_VERSION = '2.5.0'.freeze
23
23
  end
24
24
  end
@@ -168,6 +168,78 @@ EOF
168
168
  "#{prefix}-#{instance.name}"
169
169
  end
170
170
 
171
+ def exposed_ports
172
+ coerce_exposed_ports(config[:ports])
173
+ end
174
+
175
+ def port_bindings
176
+ coerce_port_bindings(config[:ports])
177
+ end
178
+
179
+ def coerce_exposed_ports(v)
180
+ case v
181
+ when Hash, nil
182
+ v
183
+ else
184
+ x = Array(v).map { |a| parse_port(a) }
185
+ x.flatten!
186
+ x.each_with_object({}) do |y, h|
187
+ h[y['container_port']] = {}
188
+ end
189
+ end
190
+ end
191
+
192
+ def coerce_port_bindings(v)
193
+ case v
194
+ when Hash, nil
195
+ v
196
+ else
197
+ x = Array(v).map { |a| parse_port(a) }
198
+ x.flatten!
199
+ x.each_with_object({}) do |y, h|
200
+ h[y['container_port']] = [] unless h[y['container_port']]
201
+ h[y['container_port']] << {
202
+ 'HostIp' => y['host_ip'],
203
+ 'HostPort' => y['host_port'],
204
+ }
205
+ end
206
+ end
207
+ end
208
+
209
+ def parse_port(v)
210
+ parts = v.split(':')
211
+ case parts.length
212
+ when 3
213
+ host_ip = parts[0]
214
+ host_port = parts[1]
215
+ container_port = parts[2]
216
+ when 2
217
+ host_ip = '0.0.0.0'
218
+ host_port = parts[0]
219
+ container_port = parts[1]
220
+ when 1
221
+ host_ip = ''
222
+ host_port = ''
223
+ container_port = parts[0]
224
+ end
225
+ port_range, protocol = container_port.split('/')
226
+ if port_range.include?('-')
227
+ port_range = container_port.split('-')
228
+ port_range.map!(&:to_i)
229
+ Chef::Log.fatal("FATAL: Invalid port range! #{container_port}") if port_range[0] > port_range[1]
230
+ port_range = (port_range[0]..port_range[1]).to_a
231
+ end
232
+ # qualify the port-binding protocol even when it is implicitly tcp #427.
233
+ protocol = 'tcp' if protocol.nil?
234
+ Array(port_range).map do |port|
235
+ {
236
+ 'host_ip' => host_ip,
237
+ 'host_port' => host_port,
238
+ 'container_port' => "#{port}/#{protocol}",
239
+ }
240
+ end
241
+ end
242
+
171
243
  def remote_docker_host?
172
244
  # return false if config[:docker_info]['OperatingSystem'].include?('Boot2Docker')
173
245
  return true if config[:docker_host_url] =~ /^tcp:/
@@ -94,16 +94,33 @@ module Kitchen
94
94
 
95
95
  elsif options[:docker_host_url] =~ /tcp:/
96
96
  name = options[:data_container][:Name]
97
+
98
+ # DOCKER_HOST
99
+ docker_host_url_ip = options[:docker_host_url].split('tcp://')[1].split(':')[0]
100
+
101
+ # mapped IP of data container
97
102
  candidate_ip = ::Docker::Container.all.select do |x|
98
103
  x.info['Names'][0].eql?(name)
99
104
  end.first.info['NetworkSettings']['Networks']['dokken']['IPAddress']
100
105
 
101
- if port_open?(candidate_ip, '22')
106
+ # mapped port
107
+ candidate_ssh_port = options[:data_container][:NetworkSettings][:Ports][:"22/tcp"][0][:HostPort]
108
+
109
+ debug "candidate_ip - #{candidate_ip}"
110
+ debug "candidate_ssh_port - #{candidate_ssh_port}"
111
+
112
+ if port_open?(candidate_ip, candidate_ssh_port)
113
+ debug "candidate_ip - #{candidate_ip}/#{candidate_ssh_port} open"
114
+ ssh_ip = candidate_ip
115
+ ssh_port = candidate_ssh_port
116
+
117
+ elsif port_open?(candidate_ip, '22')
102
118
  ssh_ip = candidate_ip
103
119
  ssh_port = '22'
120
+ debug "candidate_ip - #{candidate_ip}/22 open"
104
121
  else
105
- ssh_ip = options[:docker_host_url].split('tcp://')[1].split(':')[0]
106
- ssh_port = options[:data_container][:NetworkSettings][:Ports][:"22/tcp"][0][:HostPort]
122
+ ssh_ip = docker_host_url_ip
123
+ ssh_port = candidate_ssh_port
107
124
  end
108
125
  else
109
126
  raise Kitchen::UserError, 'docker_host_url must be tcp:// or unix://'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-dokken
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.3
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean OMeara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-22 00:00:00.000000000 Z
11
+ date: 2017-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen