beaker-docker 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +16 -8
- data/beaker-docker.gemspec +6 -1
- data/docker.md +26 -0
- data/lib/beaker-docker/version.rb +1 -1
- data/lib/beaker/hypervisor/docker.rb +185 -101
- data/spec/beaker/hypervisor/docker_spec.rb +66 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07fca4dada242e02c4caa429ebd0209cc3911fb9
|
4
|
+
data.tar.gz: 9aa1e6633cfa7c267cb9b47f07d17eee0a540e0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2eb49d22fb4827aa73774e4dcdbac5c5063f84662db010eb87ae440cfac083b1b7eb50152725225d6d3411f0249ce111497685127d79ec5bacc093359251ba0
|
7
|
+
data.tar.gz: fbd2f2246972460cfb0c8efb0d5db8aac08fbb04f7012a95bb5ca391b2c6d7df32beb192e54b3e9d5b54082347d1b164fbab4cfabdb9a65615137f66bd4c69dc
|
data/Gemfile
CHANGED
@@ -16,7 +16,7 @@ end
|
|
16
16
|
# We don't put beaker in as a test dependency because we
|
17
17
|
# don't want to create a transitive dependency
|
18
18
|
group :acceptance_testing do
|
19
|
-
gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '~>
|
19
|
+
gem "beaker", *location_for(ENV['BEAKER_VERSION'] || '~> 4.0')
|
20
20
|
end
|
21
21
|
|
22
22
|
|
data/README.md
CHANGED
@@ -4,18 +4,26 @@ Beaker library to use docker hypervisor
|
|
4
4
|
|
5
5
|
# How to use this wizardry
|
6
6
|
|
7
|
-
This gem that allows you to use hosts with [docker](docker.md) hypervisor with [beaker](https://github.com/puppetlabs/beaker).
|
7
|
+
This gem that allows you to use hosts with [docker](docker.md) hypervisor with [beaker](https://github.com/puppetlabs/beaker).
|
8
8
|
|
9
|
-
|
9
|
+
Beaker will automatically load the appropriate hypervisors for any given hosts file, so as long as your project dependencies are satisfied there's nothing else to do. No need to `require` this library in your tests.
|
10
10
|
|
11
|
-
|
11
|
+
## With Beaker 3.x
|
12
12
|
|
13
|
-
|
13
|
+
This library is included as a dependency of Beaker 3.x versions, so there's nothing to do.
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
to use
|
18
|
-
|
15
|
+
## With Beaker 4.x
|
16
|
+
|
17
|
+
As of Beaker 4.0, all hypervisor and DSL extension libraries have been removed and are no longer dependencies. In order to use a specific hypervisor or DSL extension library in your project, you will need to include them alongside Beaker in your Gemfile or project.gemspec. E.g.
|
18
|
+
|
19
|
+
~~~ruby
|
20
|
+
# Gemfile
|
21
|
+
gem 'beaker', '~>4.0'
|
22
|
+
gem 'beaker-aws'
|
23
|
+
# project.gemspec
|
24
|
+
s.add_runtime_dependency 'beaker', '~>4.0'
|
25
|
+
s.add_runtime_dependency 'beaker-aws'
|
26
|
+
~~~
|
19
27
|
|
20
28
|
# Spec tests
|
21
29
|
|
data/beaker-docker.gemspec
CHANGED
@@ -20,7 +20,12 @@ Gem::Specification.new do |s|
|
|
20
20
|
# Testing dependencies
|
21
21
|
s.add_development_dependency 'rspec', '~> 3.0'
|
22
22
|
s.add_development_dependency 'rspec-its'
|
23
|
-
|
23
|
+
# pin fakefs for Ruby < 2.3
|
24
|
+
if RUBY_VERSION < "2.3"
|
25
|
+
s.add_development_dependency 'fakefs', '~> 0.6', '< 0.14'
|
26
|
+
else
|
27
|
+
s.add_development_dependency 'fakefs', '~> 0.6'
|
28
|
+
end
|
24
29
|
s.add_development_dependency 'rake', '~> 10.1'
|
25
30
|
s.add_development_dependency 'simplecov'
|
26
31
|
s.add_development_dependency 'pry', '~> 0.10'
|
data/docker.md
CHANGED
@@ -48,6 +48,32 @@ By default the docker container just runs an sshd which is adequate for 'puppet
|
|
48
48
|
CONFIG:
|
49
49
|
type: foss
|
50
50
|
|
51
|
+
### Using the entrypoint of an image and not sshd ###
|
52
|
+
Instead of using ssh as the CMD for a container, beaker will use the entrypoint already defined if `use_image_entry_point` is used. Beaker will still load ssh onto the container and start it, but ssh will not be the entrypoint for the container. Below is an example of using the puppetserver image.
|
53
|
+
|
54
|
+
HOSTS:
|
55
|
+
puppetserver:
|
56
|
+
platform: ubuntu-1604-x86_64
|
57
|
+
hypervisor: docker
|
58
|
+
image: puppet/puppetserver-standalone:6.0.1
|
59
|
+
use_image_entry_point: true
|
60
|
+
roles:
|
61
|
+
- master
|
62
|
+
CONFIG:
|
63
|
+
type: foss
|
64
|
+
|
65
|
+
### Using dockerfiles with beaker hosts files ###
|
66
|
+
Beaker can utilize a dockerfile specified in hosts file; use the `dockerfile` attribute of a host to specify the location of the dockerfile. Beaker will use the directory it is run in to pass as the context for dockerfile DSL commands such as COPY and VOLUME, so make sure the paths are set correctly for the right context.
|
67
|
+
|
68
|
+
HOSTS:
|
69
|
+
ubuntu-12-10:
|
70
|
+
platform: ubuntu-12.10-x64
|
71
|
+
dockerfile: path/to/my/dockerfile
|
72
|
+
hypervisor: docker
|
73
|
+
docker_cmd: '["/sbin/init"]'
|
74
|
+
CONFIG:
|
75
|
+
type: foss
|
76
|
+
|
51
77
|
### Preserve Docker Image ###
|
52
78
|
Unless the image configuration changes you might want to keep the Docker image for multiple spec runs. Use `docker_preserve_image` option for a host.
|
53
79
|
|
@@ -50,10 +50,46 @@ module Beaker
|
|
50
50
|
@hosts.each do |host|
|
51
51
|
@logger.notify "provisioning #{host.name}"
|
52
52
|
|
53
|
+
container_opts = {}
|
53
54
|
@logger.debug("Creating image")
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
if dockerfile = host['dockerfile']
|
56
|
+
install_and_run_ssh = true
|
57
|
+
container_opts['ExposedPorts'] = {'22/tcp' => {} }
|
58
|
+
# assume that the dockerfile is in the repo and tests are running
|
59
|
+
# from the root of the repo; maybe add support for external Dockerfiles
|
60
|
+
# with external build dependencies later.
|
61
|
+
if File.exist?(dockerfile)
|
62
|
+
dir = File.expand_path(dockerfile).chomp(dockerfile)
|
63
|
+
image = ::Docker::Image.build_from_dir(
|
64
|
+
dir,
|
65
|
+
{ 'dockerfile' => dockerfile,
|
66
|
+
:rm => true,
|
67
|
+
:buildargs => buildargs_for(host)
|
68
|
+
}
|
69
|
+
)
|
70
|
+
else
|
71
|
+
raise "Unable to find dockerfile at #{dockerfile}"
|
72
|
+
end
|
73
|
+
elsif host['use_image_entry_point']
|
74
|
+
install_and_run_ssh = true
|
75
|
+
df = <<-DF
|
76
|
+
FROM #{host['image']}
|
77
|
+
EXPOSE 22
|
78
|
+
DF
|
79
|
+
|
80
|
+
if cmd = host['docker_cmd']
|
81
|
+
df += cmd
|
82
|
+
end
|
83
|
+
image = ::Docker::Image.build(df, {
|
84
|
+
:rm => true, :buildargs => buildargs_for(host)
|
85
|
+
})
|
86
|
+
|
87
|
+
else
|
88
|
+
|
89
|
+
image = ::Docker::Image.build(dockerfile_for(host), {
|
90
|
+
:rm => true, :buildargs => buildargs_for(host)
|
91
|
+
})
|
92
|
+
end
|
57
93
|
|
58
94
|
if @docker_type == 'swarm'
|
59
95
|
image_name = "#{@registry}/beaker/#{image.id}"
|
@@ -67,7 +103,7 @@ module Beaker
|
|
67
103
|
image_name = image.id
|
68
104
|
end
|
69
105
|
|
70
|
-
container_opts
|
106
|
+
container_opts.merge! ( {
|
71
107
|
'Image' => image_name,
|
72
108
|
'Hostname' => host.name,
|
73
109
|
'HostConfig' => {
|
@@ -80,7 +116,7 @@ module Beaker
|
|
80
116
|
'Name' => 'always'
|
81
117
|
}
|
82
118
|
}
|
83
|
-
}
|
119
|
+
} )
|
84
120
|
if host['dockeropts'] || @options[:dockeropts]
|
85
121
|
dockeropts = host['dockeropts'] ? host['dockeropts'] : @options[:dockeropts]
|
86
122
|
dockeropts.each do |k,v|
|
@@ -129,6 +165,12 @@ module Beaker
|
|
129
165
|
@logger.debug("Starting container #{container.id}")
|
130
166
|
container.start
|
131
167
|
|
168
|
+
if install_and_run_ssh
|
169
|
+
@logger.notify("Installing ssh components and starting ssh daemon in #{host} container")
|
170
|
+
install_ssh_components(container, host)
|
171
|
+
# run fixssh to configure and start the ssh service
|
172
|
+
fix_ssh(container, host)
|
173
|
+
end
|
132
174
|
# Find out where the ssh port is from the container
|
133
175
|
# When running on swarm DOCKER_HOST points to the swarm manager so we have to get the
|
134
176
|
# IP of the swarm slave via the container data
|
@@ -171,6 +213,50 @@ module Beaker
|
|
171
213
|
|
172
214
|
end
|
173
215
|
|
216
|
+
# This sideloads sshd after a container starts
|
217
|
+
def install_ssh_components(container, host)
|
218
|
+
case host['platform']
|
219
|
+
when /ubuntu/, /debian/
|
220
|
+
container.exec(%w(apt-get update))
|
221
|
+
container.exec(%w(apt-get install -y openssh-server openssh-client))
|
222
|
+
when /cumulus/
|
223
|
+
container.exec(%w(apt-get update))
|
224
|
+
container.exec(%w(apt-get install -y openssh-server openssh-client))
|
225
|
+
when /fedora-(2[2-9])/
|
226
|
+
container.exec(%w(dnf clean all))
|
227
|
+
container.exec(%w(dnf install -y sudo openssh-server openssh-clients))
|
228
|
+
container.exec(%w(ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key))
|
229
|
+
container.exec(%w(ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key))
|
230
|
+
when /^el-/, /centos/, /fedora/, /redhat/, /eos/
|
231
|
+
container.exec(%w(yum clean all))
|
232
|
+
container.exec(%w(yum install -y sudo openssh-server openssh-clients))
|
233
|
+
container.exec(%w(ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key))
|
234
|
+
container.exec(%w(ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key))
|
235
|
+
when /opensuse/, /sles/
|
236
|
+
container.exec(%w(zypper -n in openssh))
|
237
|
+
container.exec(%w(ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key))
|
238
|
+
container.exec(%w(ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key))
|
239
|
+
container.exec(%w(sed -ri 's/^#?UsePAM .*/UsePAM no/' /etc/ssh/sshd_config))
|
240
|
+
when /archlinux/
|
241
|
+
container.exec(%w(pacman --noconfirm -Sy archlinux-keyring))
|
242
|
+
container.exec(%w(pacman --noconfirm -Syu))
|
243
|
+
container.exec(%w(pacman -S --noconfirm openssh))
|
244
|
+
container.exec(%w(ssh-keygen -A))
|
245
|
+
container.exec(%w(sed -ri 's/^#?UsePAM .*/UsePAM no/' /etc/ssh/sshd_config))
|
246
|
+
container.exec(%w(systemctl enable sshd))
|
247
|
+
when /alpine/
|
248
|
+
container.exec(%w(apk add --update openssh))
|
249
|
+
container.exec(%w(ssh-keygen -A))
|
250
|
+
else
|
251
|
+
# TODO add more platform steps here
|
252
|
+
raise "platform #{host['platform']} not yet supported on docker"
|
253
|
+
end
|
254
|
+
|
255
|
+
# Make sshd directory, set root password
|
256
|
+
container.exec(%w(mkdir -p /var/run/sshd))
|
257
|
+
container.exec(['/bin/sh', '-c', "echo root:#{root_password} | chpasswd"])
|
258
|
+
end
|
259
|
+
|
174
260
|
def cleanup
|
175
261
|
@logger.notify "Cleaning up docker"
|
176
262
|
@hosts.each do |host|
|
@@ -233,118 +319,110 @@ module Beaker
|
|
233
319
|
end
|
234
320
|
|
235
321
|
def dockerfile_for(host)
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
322
|
+
# specify base image
|
323
|
+
dockerfile = <<-EOF
|
324
|
+
FROM #{host['image']}
|
325
|
+
ENV container docker
|
326
|
+
EOF
|
327
|
+
|
328
|
+
# additional options to specify to the sshd
|
329
|
+
# may vary by platform
|
330
|
+
sshd_options = ''
|
331
|
+
|
332
|
+
# add platform-specific actions
|
333
|
+
service_name = "sshd"
|
334
|
+
case host['platform']
|
335
|
+
when /ubuntu/, /debian/
|
336
|
+
service_name = "ssh"
|
337
|
+
dockerfile += <<-EOF
|
338
|
+
RUN apt-get update
|
339
|
+
RUN apt-get install -y openssh-server openssh-client #{Beaker::HostPrebuiltSteps::DEBIAN_PACKAGES.join(' ')}
|
250
340
|
EOF
|
251
|
-
|
252
|
-
# additional options to specify to the sshd
|
253
|
-
# may vary by platform
|
254
|
-
sshd_options = ''
|
255
|
-
|
256
|
-
# add platform-specific actions
|
257
|
-
service_name = "sshd"
|
258
|
-
case host['platform']
|
259
|
-
when /ubuntu/, /debian/
|
260
|
-
service_name = "ssh"
|
261
|
-
dockerfile += <<-EOF
|
262
|
-
RUN apt-get update
|
263
|
-
RUN apt-get install -y openssh-server openssh-client #{Beaker::HostPrebuiltSteps::DEBIAN_PACKAGES.join(' ')}
|
264
|
-
EOF
|
265
|
-
when /cumulus/
|
266
|
-
dockerfile += <<-EOF
|
267
|
-
RUN apt-get update
|
268
|
-
RUN apt-get install -y openssh-server openssh-client #{Beaker::HostPrebuiltSteps::CUMULUS_PACKAGES.join(' ')}
|
269
|
-
EOF
|
270
|
-
when /fedora-(2[2-9])/
|
271
|
-
dockerfile += <<-EOF
|
272
|
-
RUN dnf clean all
|
273
|
-
RUN dnf install -y sudo openssh-server openssh-clients #{Beaker::HostPrebuiltSteps::UNIX_PACKAGES.join(' ')}
|
274
|
-
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
|
275
|
-
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
|
276
|
-
EOF
|
277
|
-
when /^el-/, /centos/, /fedora/, /redhat/, /eos/
|
341
|
+
when /cumulus/
|
278
342
|
dockerfile += <<-EOF
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
EOF
|
284
|
-
when /opensuse/, /sles/
|
285
|
-
dockerfile += <<-EOF
|
286
|
-
RUN zypper -n in openssh #{Beaker::HostPrebuiltSteps::SLES_PACKAGES.join(' ')}
|
287
|
-
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
|
288
|
-
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
|
289
|
-
RUN sed -ri 's/^#?UsePAM .*/UsePAM no/' /etc/ssh/sshd_config
|
290
|
-
EOF
|
291
|
-
when /archlinux/
|
292
|
-
dockerfile += <<-EOF
|
293
|
-
RUN pacman --noconfirm -Sy archlinux-keyring
|
294
|
-
RUN pacman --noconfirm -Syu
|
295
|
-
RUN pacman -S --noconfirm openssh #{Beaker::HostPrebuiltSteps::ARCHLINUX_PACKAGES.join(' ')}
|
296
|
-
RUN ssh-keygen -A
|
297
|
-
RUN sed -ri 's/^#?UsePAM .*/UsePAM no/' /etc/ssh/sshd_config
|
298
|
-
RUN systemctl enable sshd
|
299
|
-
EOF
|
300
|
-
else
|
301
|
-
# TODO add more platform steps here
|
302
|
-
raise "platform #{host['platform']} not yet supported on docker"
|
303
|
-
end
|
304
|
-
|
305
|
-
# Make sshd directory, set root password
|
343
|
+
RUN apt-get update
|
344
|
+
RUN apt-get install -y openssh-server openssh-client #{Beaker::HostPrebuiltSteps::CUMULUS_PACKAGES.join(' ')}
|
345
|
+
EOF
|
346
|
+
when /fedora-(2[2-9])/
|
306
347
|
dockerfile += <<-EOF
|
307
|
-
RUN
|
308
|
-
RUN
|
348
|
+
RUN dnf clean all
|
349
|
+
RUN dnf install -y sudo openssh-server openssh-clients #{Beaker::HostPrebuiltSteps::UNIX_PACKAGES.join(' ')}
|
350
|
+
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
|
351
|
+
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
|
309
352
|
EOF
|
310
|
-
|
311
|
-
# Configure sshd service to allowroot login using password
|
312
|
-
# Also, disable reverse DNS lookups to prevent every. single. ssh
|
313
|
-
# operation taking 30 seconds while the lookup times out.
|
353
|
+
when /^el-/, /centos/, /fedora/, /redhat/, /eos/
|
314
354
|
dockerfile += <<-EOF
|
315
|
-
RUN
|
316
|
-
RUN
|
317
|
-
RUN
|
355
|
+
RUN yum clean all
|
356
|
+
RUN yum install -y sudo openssh-server openssh-clients #{Beaker::HostPrebuiltSteps::UNIX_PACKAGES.join(' ')}
|
357
|
+
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
|
358
|
+
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
|
318
359
|
EOF
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
if host['docker_image_entrypoint']
|
328
|
-
dockerfile += "ENTRYPOINT #{host['docker_image_entrypoint']}\n"
|
329
|
-
end
|
330
|
-
|
331
|
-
# How to start a sshd on port 22. May be an init for more supervision
|
332
|
-
# Ensure that the ssh server can be restarted (done from set_env) and container keeps running
|
333
|
-
cmd = host['docker_cmd'] || ["sh","-c","service #{service_name} start ; tail -f /dev/null"]
|
360
|
+
when /opensuse/, /sles/
|
361
|
+
dockerfile += <<-EOF
|
362
|
+
RUN zypper -n in openssh #{Beaker::HostPrebuiltSteps::SLES_PACKAGES.join(' ')}
|
363
|
+
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
|
364
|
+
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
|
365
|
+
RUN sed -ri 's/^#?UsePAM .*/UsePAM no/' /etc/ssh/sshd_config
|
366
|
+
EOF
|
367
|
+
when /archlinux/
|
334
368
|
dockerfile += <<-EOF
|
335
|
-
|
336
|
-
|
369
|
+
RUN pacman --noconfirm -Sy archlinux-keyring
|
370
|
+
RUN pacman --noconfirm -Syu
|
371
|
+
RUN pacman -S --noconfirm openssh #{Beaker::HostPrebuiltSteps::ARCHLINUX_PACKAGES.join(' ')}
|
372
|
+
RUN ssh-keygen -A
|
373
|
+
RUN sed -ri 's/^#?UsePAM .*/UsePAM no/' /etc/ssh/sshd_config
|
374
|
+
RUN systemctl enable sshd
|
337
375
|
EOF
|
376
|
+
else
|
377
|
+
# TODO add more platform steps here
|
378
|
+
raise "platform #{host['platform']} not yet supported on docker"
|
379
|
+
end
|
338
380
|
|
381
|
+
# Make sshd directory, set root password
|
382
|
+
dockerfile += <<-EOF
|
383
|
+
RUN mkdir -p /var/run/sshd
|
384
|
+
RUN echo root:#{root_password} | chpasswd
|
385
|
+
EOF
|
386
|
+
|
387
|
+
# Configure sshd service to allowroot login using password
|
388
|
+
# Also, disable reverse DNS lookups to prevent every. single. ssh
|
389
|
+
# operation taking 30 seconds while the lookup times out.
|
390
|
+
dockerfile += <<-EOF
|
391
|
+
RUN sed -ri 's/^#?PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
|
392
|
+
RUN sed -ri 's/^#?PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
|
393
|
+
RUN sed -ri 's/^#?UseDNS .*/UseDNS no/' /etc/ssh/sshd_config
|
394
|
+
EOF
|
395
|
+
|
396
|
+
|
397
|
+
# Any extra commands specified for the host
|
398
|
+
dockerfile += (host['docker_image_commands'] || []).map { |command|
|
399
|
+
"RUN #{command}\n"
|
400
|
+
}.join('')
|
401
|
+
|
402
|
+
# Override image entrypoint
|
403
|
+
if host['docker_image_entrypoint']
|
404
|
+
dockerfile += "ENTRYPOINT #{host['docker_image_entrypoint']}\n"
|
339
405
|
end
|
340
406
|
|
407
|
+
# How to start a sshd on port 22. May be an init for more supervision
|
408
|
+
# Ensure that the ssh server can be restarted (done from set_env) and container keeps running
|
409
|
+
cmd = host['docker_cmd'] || ["sh","-c","service #{service_name} start ; tail -f /dev/null"]
|
410
|
+
dockerfile += <<-EOF
|
411
|
+
EXPOSE 22
|
412
|
+
CMD #{cmd}
|
413
|
+
EOF
|
414
|
+
|
415
|
+
# end
|
416
|
+
|
341
417
|
@logger.debug("Dockerfile is #{dockerfile}")
|
342
418
|
return dockerfile
|
343
419
|
end
|
344
420
|
|
345
421
|
# a puppet run may have changed the ssh config which would
|
346
422
|
# keep us out of the container. This is a best effort to fix it.
|
347
|
-
|
423
|
+
# Optionally pass in a host object to to determine which ssh
|
424
|
+
# restart command we should try.
|
425
|
+
def fix_ssh(container, host=nil)
|
348
426
|
@logger.debug("Fixing ssh on container #{container.id}")
|
349
427
|
container.exec(['sed','-ri',
|
350
428
|
's/^#?PermitRootLogin .*/PermitRootLogin yes/',
|
@@ -355,7 +433,13 @@ module Beaker
|
|
355
433
|
container.exec(['sed','-ri',
|
356
434
|
's/^#?UseDNS .*/UseDNS no/',
|
357
435
|
'/etc/ssh/sshd_config'])
|
358
|
-
|
436
|
+
if host
|
437
|
+
if host['platform'] =~ /alpine/
|
438
|
+
container.exec(%w(/usr/sbin/sshd))
|
439
|
+
else
|
440
|
+
container.exec(%w(service ssh restart))
|
441
|
+
end
|
442
|
+
end
|
359
443
|
end
|
360
444
|
|
361
445
|
|
@@ -163,14 +163,79 @@ module Beaker
|
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
+
describe '#install_ssh_components' do
|
167
|
+
let(:test_container) { double('container') }
|
168
|
+
let(:host) {hosts[0]}
|
169
|
+
before :each do
|
170
|
+
allow( ::Docker ).to receive(:validate_version!)
|
171
|
+
allow( docker ).to receive(:dockerfile_for)
|
172
|
+
end
|
173
|
+
|
174
|
+
platforms.each do |platform|
|
175
|
+
it 'should call exec at least twice' do
|
176
|
+
host['platform'] = platform
|
177
|
+
expect(test_container).to receive(:exec).at_least(:twice)
|
178
|
+
docker.install_ssh_components(test_container, host)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should accept alpine as valid platform' do
|
183
|
+
host['platform'] = 'alpine-3.8-x86_64'
|
184
|
+
expect(test_container).to receive(:exec).at_least(:twice)
|
185
|
+
docker.install_ssh_components(test_container, host)
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'should raise an error with an unsupported platform' do
|
189
|
+
host['platform'] = 'boogeyman-2000-x86_64'
|
190
|
+
expect{docker.install_ssh_components(test_container, host)}.to raise_error(RuntimeError, /boogeyman/)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
166
194
|
describe '#provision' do
|
167
195
|
before :each do
|
168
196
|
allow( ::Docker ).to receive(:validate_version!)
|
169
197
|
allow( docker ).to receive(:dockerfile_for)
|
170
198
|
end
|
171
199
|
|
200
|
+
context 'when the host has "use_image_entry_point" set to true on the host' do
|
201
|
+
|
202
|
+
before :each do
|
203
|
+
hosts.each do |host|
|
204
|
+
host['use_image_entry_point'] = true
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'should not call #dockerfile_for but run methods necessary for ssh installation' do
|
209
|
+
expect( docker ).not_to receive(:dockerfile_for)
|
210
|
+
expect( docker ).to receive(:install_ssh_components).exactly(3).times #once per host
|
211
|
+
expect( docker ).to receive(:fix_ssh).exactly(3).times #once per host
|
212
|
+
docker.provision
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context 'when the host has a "dockerfile" for the host' do
|
217
|
+
|
218
|
+
before :each do
|
219
|
+
allow( docker ).to receive(:buildargs_for).and_return('buildargs')
|
220
|
+
hosts.each do |host|
|
221
|
+
host['dockerfile'] = 'mydockerfile'
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'should not call #dockerfile_for but run methods necessary for ssh installation' do
|
226
|
+
allow( File ).to receive(:exist?).with('mydockerfile').and_return(true)
|
227
|
+
allow( ::Docker::Image ).to receive(:build_from_dir).with("/", hash_including(:rm => true, :buildargs => 'buildargs')).and_return(image)
|
228
|
+
expect( docker ).not_to receive(:dockerfile_for)
|
229
|
+
expect( docker ).to receive(:install_ssh_components).exactly(3).times #once per host
|
230
|
+
expect( docker ).to receive(:fix_ssh).exactly(3).times #once per host
|
231
|
+
docker.provision
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
172
235
|
it 'should call dockerfile_for with all the hosts' do
|
173
236
|
hosts.each do |host|
|
237
|
+
expect( docker ).not_to receive(:install_ssh_components)
|
238
|
+
expect( docker ).not_to receive(:fix_ssh)
|
174
239
|
expect( docker ).to receive(:dockerfile_for).with(host).and_return('')
|
175
240
|
end
|
176
241
|
|
@@ -445,7 +510,7 @@ module Beaker
|
|
445
510
|
host['docker_container_name'] = container_name
|
446
511
|
|
447
512
|
expect( ::Docker::Container ).to receive(:all).and_return([container])
|
448
|
-
expect(
|
513
|
+
expect(docker).to receive(:fix_ssh).exactly(1).times
|
449
514
|
end
|
450
515
|
docker.provision
|
451
516
|
end
|
@@ -519,10 +584,6 @@ module Beaker
|
|
519
584
|
expect { docker.send(:dockerfile_for, {'platform' => 'a_sidewalk', 'image' => 'foobar' }) }.to raise_error(/platform a_sidewalk not yet supported/)
|
520
585
|
end
|
521
586
|
|
522
|
-
it 'should raise on missing image' do
|
523
|
-
expect { docker.send(:dockerfile_for, {'platform' => 'centos-7-x86_64'})}.to raise_error(/Docker image undefined/)
|
524
|
-
end
|
525
|
-
|
526
587
|
it 'should set "ENV container docker"' do
|
527
588
|
FakeFS.deactivate!
|
528
589
|
platforms.each do |platform|
|
@@ -595,16 +656,6 @@ module Beaker
|
|
595
656
|
|
596
657
|
expect( dockerfile ).to be =~ /RUN pacman -S --noconfirm openssh/
|
597
658
|
end
|
598
|
-
|
599
|
-
it 'should use user dockerfile if specified' do
|
600
|
-
FakeFS.deactivate!
|
601
|
-
dockerfile = docker.send(:dockerfile_for, {
|
602
|
-
'dockerfile' => 'README.md'
|
603
|
-
})
|
604
|
-
|
605
|
-
expect( dockerfile ).to be == File.read('README.md')
|
606
|
-
end
|
607
|
-
|
608
659
|
end
|
609
660
|
end
|
610
661
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beaker-docker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rishi Javia, Kevin Imber, Tony Vu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|