kitchen-dokken 2.3.0 → 2.4.1

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: 6d57a3f9e31b502476ae1e99b045b550132c98f2
4
- data.tar.gz: 241ab4e34076eeeddec3bb4c883953a804d188d7
3
+ metadata.gz: b36486a74d03c58b8ed8fdad948f06028f1fb1ae
4
+ data.tar.gz: c8a95b0ab5526d783a60a23c0a693392645f51d2
5
5
  SHA512:
6
- metadata.gz: 962d742a44fae5ee8916f751b04d500e4ebf06430c35ce5e2168790042fbcec052d1a06471031ac1d0808f7fa4f9fc656fd3a9b6fcbf6a1e20798217ed027558
7
- data.tar.gz: 385d6239b82aae293e9bca7c4b17a9fa7bafe6f4859f8518b9bdceaabde238da00de1a363ef6a75338da03b81d13171a81c3e8bf06806c2604e7d0bb883b72be
6
+ metadata.gz: 7ca1a539cecff671e82091faf2cb41e696bf52c8b330398748dd89989d18e8842011ef2ead744537cd569f3771582f98f00641ef9a5647ecc7450c9f373c5796
7
+ data.tar.gz: 59ffd591e931ae9698c3aafc8240baaa1c13101838b6e1d729294b8270563671769097fe29ffa1a6f1dc216e07262ff5a980003154ab032de4741b9509ebbc9a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Dokken Changelog
2
2
 
3
+ # 2.4.1
4
+ - Adding NotFoundError to with_retries and beefing up rescues
5
+
6
+ # 2.4.0
7
+ - Features meant for 2.2.0, but tested properly this time.
8
+ - Initial support for clusters / inter-suite name resolution
9
+ - Dokken now creates a user-defined network named "dokken" and
10
+ connects containers to it. This allows us to take advantage of the
11
+ built in DNS server that in Docker 1.10 and later.
12
+
13
+ ```
14
+ driver:
15
+ hostname: www.computers.biz
16
+ ```
17
+
18
+ # 2.3.1
19
+ - Actually doing the things in 2.3.0
20
+
3
21
  # 2.3.0
4
22
  - Reverting 2.2.x bits to 2.1.x. to restore stability to users.
5
23
  - That'll teach me to push gems at odd hours.
@@ -41,7 +41,7 @@ module Kitchen
41
41
  default_config :data_image, 'dokken/kitchen-cache:latest'
42
42
  default_config :dns, nil
43
43
  default_config :dns_search, nil
44
- default_config :docker_info, docker_info
44
+ # default_config :docker_info, docker_info
45
45
  default_config :docker_host_url, default_docker_host
46
46
  default_config :forward, nil
47
47
  default_config :hostname, 'dokken'
@@ -114,10 +114,12 @@ module Kitchen
114
114
  return unless ::Docker::Image.exist?(work_image, {}, docker_connection)
115
115
  with_retries { @work_image = ::Docker::Image.get(work_image, {}, docker_connection) }
116
116
 
117
- begin
118
- with_retries { @work_image.remove(force: true) }
119
- rescue ::Docker::Error::ConflictError
120
- debug "driver - #{work_image} cannot be removed"
117
+ with_retries do
118
+ begin
119
+ with_retries { @work_image.remove(force: true) }
120
+ rescue ::Docker::Error::ConflictError
121
+ debug "driver - #{work_image} cannot be removed"
122
+ end
121
123
  end
122
124
  end
123
125
 
@@ -280,7 +282,14 @@ module Kitchen
280
282
  'HostConfig' => {
281
283
  'PortBindings' => port_forwards({}, '22'),
282
284
  'PublishAllPorts' => true,
283
- 'NetworkMode' => self[:network_mode],
285
+ 'NetworkMode' => 'bridge',
286
+ },
287
+ 'NetworkingConfig' => {
288
+ 'EndpointsConfig' => {
289
+ self[:network_mode] => {
290
+ 'Aliases' => Array(self[:hostname]),
291
+ },
292
+ },
284
293
  },
285
294
  }
286
295
  data_container = run_container(config)
@@ -288,14 +297,17 @@ module Kitchen
288
297
  end
289
298
 
290
299
  def make_dokken_network
291
- info 'driver - checking for dokken network'
292
- ::Docker::Network.get('dokken', {}, docker_connection)
300
+ debug 'driver - checking for dokken network'
301
+ with_retries { ::Docker::Network.get('dokken', {}, docker_connection) }
293
302
  rescue
294
- begin
295
- info 'driver - creating dokken network'
296
- ::Docker::Network.create('dokken', {})
297
- rescue ::Docker::Error => e
298
- info "driver - :#{e}:"
303
+ with_retries do
304
+ begin
305
+ info 'Creating dokken network'
306
+ n = ::Docker::Network.create('dokken', {})
307
+ debug "n - #{n}"
308
+ rescue ::Docker::Error => e
309
+ debug "driver - :#{e}:"
310
+ end
299
311
  end
300
312
  end
301
313
 
@@ -305,22 +317,24 @@ module Kitchen
305
317
  end
306
318
 
307
319
  def create_chef_container(state)
308
- ::Docker::Container.get(chef_container_name, {}, docker_connection)
320
+ with_retries { ::Docker::Container.get(chef_container_name, {}, docker_connection) }
309
321
  rescue ::Docker::Error::NotFoundError
310
- begin
311
- debug "driver - creating volume container #{chef_container_name} from #{chef_image}"
312
- config = {
313
- 'name' => chef_container_name,
314
- 'Cmd' => 'true',
315
- 'Image' => "#{repo(chef_image)}:#{tag(chef_image)}",
316
- 'HostConfig' => {
317
- 'NetworkMode' => self[:network_mode],
318
- },
319
- }
320
- chef_container = create_container(config)
321
- state[:chef_container] = chef_container.json
322
- rescue ::Docker::Error => e
323
- raise "driver - #{chef_container_name} failed to create #{e}"
322
+ with_retries do
323
+ begin
324
+ debug "driver - creating volume container #{chef_container_name} from #{chef_image}"
325
+ config = {
326
+ 'name' => chef_container_name,
327
+ 'Cmd' => 'true',
328
+ 'Image' => "#{repo(chef_image)}:#{tag(chef_image)}",
329
+ 'HostConfig' => {
330
+ 'NetworkMode' => self[:network_mode],
331
+ },
332
+ }
333
+ chef_container = create_container(config)
334
+ state[:chef_container] = chef_container.json
335
+ rescue ::Docker::Error => e
336
+ raise "driver - #{chef_container_name} failed to create #{e}"
337
+ end
324
338
  end
325
339
  end
326
340
 
@@ -366,12 +380,25 @@ module Kitchen
366
380
  end
367
381
 
368
382
  def create_container(args)
383
+ with_retries { @container = ::Docker::Container.get(args['name'], {}, docker_connection) }
384
+ rescue
369
385
  with_retries do
370
- @container = ::Docker::Container.create(args.clone, docker_connection)
371
- @container = ::Docker::Container.get(args['name'], {}, docker_connection)
386
+ begin
387
+ info "Creating container #{args['name']}"
388
+ debug "driver - create_container args #{args}"
389
+ with_retries do
390
+ begin
391
+ @container = ::Docker::Container.create(args.clone, docker_connection)
392
+ rescue ::Docker::Error::ConflictError
393
+ debug "driver - rescue ConflictError: #{args['name']}"
394
+ with_retries { @container = ::Docker::Container.get(args['name'], {}, docker_connection) }
395
+
396
+ end
397
+ end
398
+ rescue ::Docker::Error => e
399
+ raise "driver - failed to create_container #{args['name']}"
400
+ end
372
401
  end
373
- rescue ::Docker::Error::ConflictError
374
- with_retries { @container = ::Docker::Container.get(args['name'], {}, docker_connection) }
375
402
  end
376
403
 
377
404
  def run_container(args)
@@ -492,9 +519,12 @@ module Kitchen
492
519
  rescue ::Docker::Error::ServerError, # 404
493
520
  ::Docker::Error::UnexpectedResponseError, # 400
494
521
  ::Docker::Error::TimeoutError,
495
- ::Docker::Error::IOError => e
522
+ ::Docker::Error::IOError,
523
+ ::Docker::Error::NotFoundError => e
496
524
  tries -= 1
525
+ sleep 0.1
497
526
  retry if tries > 0
527
+ debug "tries: #{tries} e: #{e}"
498
528
  raise e
499
529
  end
500
530
  end
@@ -19,6 +19,6 @@
19
19
  module Kitchen
20
20
  module Driver
21
21
  # Version string for Dokken Kitchen driver
22
- DOKKEN_VERSION = '2.3.0'.freeze
22
+ DOKKEN_VERSION = '2.4.1'.freeze
23
23
  end
24
24
  end
@@ -1,5 +1,26 @@
1
1
  module Dokken
2
2
  module Helpers
3
+ # https://stackoverflow.com/questions/517219/ruby-see-if-a-port-is-open
4
+ require 'socket'
5
+ require 'timeout'
6
+
7
+ def port_open?(ip, port)
8
+ begin
9
+ Timeout.timeout(1) do
10
+ begin
11
+ s = TCPSocket.new(ip, port)
12
+ s.close
13
+ return true
14
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
15
+ return false
16
+ end
17
+ end
18
+ rescue Timeout::Error
19
+ end
20
+
21
+ false
22
+ end
23
+
3
24
  def insecure_ssh_public_key
4
25
  <<-EOF
5
26
  ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoJwyW7qNhw+NTuOjC4+RVpESl+JBXebXzB7JqxRgKAbymq6B39azEAiNx5NzHkWcQmOyQNhFpKFSAufegcXRS4ctS1LcElEoXe9brDAqKEBSkmnXYfZXMNIG0Enw4+5W/rZxHFCAlsUSAHYtYZEs+3CgbIWuHhZ95C8UC6nGLWHNZOjcbsYZFrnFfO0qg0ene2w8LKhxqj5X0MRSdCIn1IwyxIbl5NND5Yk1Hx8JKsJtTiNTdxssiMgmM5bvTbYQUSf8pbGrRI30VQKBgQ8/UkidZbaTfvzWXYpwcDUERSbzEYCvkUytTemZIv6uhpPxqkfjl6KEOOml/iGqquPEr test-kitchen-rsa
@@ -42,14 +63,20 @@ EOF
42
63
  <<-EOF
43
64
  FROM centos:7
44
65
  MAINTAINER Sean OMeara \"sean@sean.io\"
45
-
46
66
  ENV LANG en_US.UTF-8
47
67
 
48
68
  RUN yum -y install tar rsync openssh-server passwd git
49
69
  RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
50
70
 
71
+ # uncomment to debug cert issues
72
+ # RUN echo 'root:dokkendokkendokken' | chpasswd
73
+ # RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
74
+ # RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
75
+
51
76
  RUN mkdir -p /root/.ssh/
52
77
  COPY authorized_keys /root/.ssh/authorized_keys
78
+ RUN chmod 700 /root/.ssh/
79
+ RUN chmod 600 /root/.ssh/authorized_keys
53
80
 
54
81
  EXPOSE 22
55
82
  CMD [ "/usr/sbin/sshd", "-D", "-p", "22", "-o", "UseDNS=no", "-o", "UsePrivilegeSeparation=no", "-o", "MaxAuthTries=60" ]
@@ -142,7 +169,7 @@ EOF
142
169
  end
143
170
 
144
171
  def remote_docker_host?
145
- return false if config[:docker_info]['OperatingSystem'].include?('Boot2Docker')
172
+ # return false if config[:docker_info]['OperatingSystem'].include?('Boot2Docker')
146
173
  return true if config[:docker_host_url] =~ /^tcp:/
147
174
  false
148
175
  end
@@ -77,26 +77,42 @@ module Kitchen
77
77
  end
78
78
 
79
79
  def upload(locals, remote)
80
- port = options[:data_container][:NetworkSettings][:Ports][:"22/tcp"][0][:HostPort]
81
-
82
80
  if options[:host_ip_override]
83
81
  # Allow connecting to any ip/hostname to support sibling containers
84
- ip = options[:host_ip_override]
82
+ ssh_ip = options[:host_ip_override]
83
+ ssh_port = options[:data_container][:NetworkSettings][:Ports][:"22/tcp"][0][:HostPort]
84
+
85
85
  elsif options[:docker_host_url] =~ /unix:/
86
86
  if options[:data_container][:NetworkSettings][:Ports][:"22/tcp"][0][:HostIp] == '0.0.0.0'
87
- ip = options[:data_container][:NetworkSettings][:IPAddress]
88
- port = '22'
87
+ ssh_ip = options[:data_container][:NetworkSettings][:IPAddress]
88
+ ssh_port = '22'
89
89
  else
90
90
  # we should read the proper mapped ip, since this allows us to upload the files
91
- ip = options[:data_container][:NetworkSettings][:Ports][:"22/tcp"][0][:HostIp]
91
+ ssh_ip = options[:data_container][:NetworkSettings][:Ports][:"22/tcp"][0][:HostIp]
92
+ ssh_port = options[:data_container][:NetworkSettings][:Ports][:"22/tcp"][0][:HostPort]
92
93
  end
94
+
93
95
  elsif options[:docker_host_url] =~ /tcp:/
94
- ip = options[:docker_host_url].split('tcp://')[1].split(':')[0]
96
+ name = options[:data_container][:Name]
97
+ candidate_ip = ::Docker::Container.all.select do |x|
98
+ x.info['Names'][0].eql?(name)
99
+ end.first.info['NetworkSettings']['Networks']['dokken']['IPAddress']
100
+
101
+ if port_open?(candidate_ip, '22')
102
+ ssh_ip = candidate_ip
103
+ ssh_port = '22'
104
+ 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]
107
+ end
95
108
  else
96
109
  raise Kitchen::UserError, 'docker_host_url must be tcp:// or unix://'
97
110
  end
98
111
 
99
- require 'pry'; tmpdir = Dir.tmpdir + '/dokken/'
112
+ debug "ssh_ip : #{ssh_ip}"
113
+ debug "ssh_port : #{ssh_port}"
114
+
115
+ tmpdir = Dir.tmpdir + '/dokken/'
100
116
  FileUtils.mkdir_p tmpdir.to_s, mode: 0o777
101
117
  tmpdir += Process.uid.to_s
102
118
  FileUtils.mkdir_p tmpdir.to_s
@@ -114,20 +130,20 @@ module Kitchen
114
130
  rsync_cmd << ' -o StrictHostKeyChecking=no'
115
131
  rsync_cmd << ' -o UserKnownHostsFile=/dev/null'
116
132
  rsync_cmd << ' -o LogLevel=ERROR'
117
- rsync_cmd << " -p #{port}"
133
+ rsync_cmd << " -p #{ssh_port}"
118
134
  rsync_cmd << '\''
119
- rsync_cmd << " #{locals.join(' ')} root@#{ip}:#{remote}"
135
+ rsync_cmd << " #{locals.join(' ')} root@#{ssh_ip}:#{remote}"
120
136
  debug "rsync_cmd :#{rsync_cmd}:"
121
137
  `#{rsync_cmd}`
122
138
  rescue Errno::ENOENT
123
139
  debug 'Rsync is not installed. Falling back to SCP.'
124
140
  locals.each do |local|
125
- Net::SCP.upload!(ip,
141
+ Net::SCP.upload!(ssh_ip,
126
142
  'root',
127
143
  local,
128
144
  remote,
129
145
  recursive: true,
130
- ssh: { port: port, keys: ["#{tmpdir}/id_rsa"] })
146
+ ssh: { port: ssh_port, keys: ["#{tmpdir}/id_rsa"] })
131
147
  end
132
148
  end
133
149
  end
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.3.0
4
+ version: 2.4.1
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-16 00:00:00.000000000 Z
11
+ date: 2017-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen