beaker-docker 0.5.2 → 0.5.3

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: 64566eeaece32a9571e797f4c09a5e56babbcd1d
4
- data.tar.gz: b7746e663d8fb916ebb7820fea64ab9f55babe8b
3
+ metadata.gz: 7b9f93de9358670645ea7e0c3bf982a7c822b8ca
4
+ data.tar.gz: 19730ee76587c0e098504bf7bae15627c10f1603
5
5
  SHA512:
6
- metadata.gz: ffcf6fd38005a3f28868b00de297205dbc5df5407764758115017fdd391f42797bc1d5866ee42136af7749fa8ba4555130e406f415af4216c662f19795c587e9
7
- data.tar.gz: ac43c591842f18a1cf1841cff074a1cca1393fab223a43e1e26b87fc9812138609c526ca51f46afa5ee87d6979a46c5318b50f11e0ac304054562802f7247d77
6
+ metadata.gz: 78b6a3d9dda05f73f12861c8f3675647b3265428cfa634de30dbd89da20eac938353ecbf44c900079cdc1a7113a9f7304e13915c78c3f39426e1364be9fee0e8
7
+ data.tar.gz: a88c7fe2fa9ec4655e629e1996310baa0154bfc8c69e7294f0111479c447f3ef878305df2cf14b8c4fcd36b272f761c06fa9181bfa330ed943e51a27f63eded5
@@ -1,3 +1,3 @@
1
1
  module BeakerDocker
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
3
3
  end
@@ -44,56 +44,84 @@ module Beaker
44
44
 
45
45
  end
46
46
 
47
+ def install_and_run_ssh(host)
48
+ host['dockerfile'] || host['use_image_entry_point']
49
+ end
50
+
51
+ def get_container_opts(host, image_name)
52
+ container_opts = {}
53
+ if host['dockerfile']
54
+ container_opts['ExposedPorts'] = {'22/tcp' => {} }
55
+ end
56
+
57
+ container_opts.merge! ( {
58
+ 'Image' => image_name,
59
+ 'Hostname' => host.name,
60
+ 'HostConfig' => {
61
+ 'PortBindings' => {
62
+ '22/tcp' => [{ 'HostPort' => rand.to_s[2..5], 'HostIp' => '0.0.0.0'}]
63
+ },
64
+ 'PublishAllPorts' => true,
65
+ 'Privileged' => true,
66
+ 'RestartPolicy' => {
67
+ 'Name' => 'always'
68
+ }
69
+ }
70
+ } )
71
+ end
72
+
73
+ def get_container_image(host)
74
+ @logger.debug("Creating image")
75
+
76
+ if host['use_image_as_is']
77
+ return ::Docker::Image.create('fromImage' => host['image'])
78
+ end
79
+
80
+ dockerfile = host['dockerfile']
81
+ if dockerfile
82
+ # assume that the dockerfile is in the repo and tests are running
83
+ # from the root of the repo; maybe add support for external Dockerfiles
84
+ # with external build dependencies later.
85
+ if File.exist?(dockerfile)
86
+ dir = File.expand_path(dockerfile).chomp(dockerfile)
87
+ return ::Docker::Image.build_from_dir(
88
+ dir,
89
+ { 'dockerfile' => dockerfile,
90
+ :rm => true,
91
+ :buildargs => buildargs_for(host)
92
+ }
93
+ )
94
+ else
95
+ raise "Unable to find dockerfile at #{dockerfile}"
96
+ end
97
+ elsif host['use_image_entry_point']
98
+ df = <<-DF
99
+ FROM #{host['image']}
100
+ EXPOSE 22
101
+ DF
102
+
103
+ cmd = host['docker_cmd']
104
+ df += cmd if cmd
105
+ return ::Docker::Image.build(df, { rm: true, buildargs: buildargs_for(host) })
106
+ end
107
+
108
+ return ::Docker::Image.build(dockerfile_for(host),
109
+ { rm: true, buildargs: buildargs_for(host) })
110
+ end
111
+
47
112
  def provision
48
113
  @logger.notify "Provisioning docker"
49
114
 
50
115
  @hosts.each do |host|
51
116
  @logger.notify "provisioning #{host.name}"
52
117
 
53
- container_opts = {}
54
- @logger.debug("Creating image")
55
-
56
- dockerfile = host['dockerfile']
57
- if dockerfile
58
- install_and_run_ssh = true
59
- container_opts['ExposedPorts'] = {'22/tcp' => {} }
60
- # assume that the dockerfile is in the repo and tests are running
61
- # from the root of the repo; maybe add support for external Dockerfiles
62
- # with external build dependencies later.
63
- if File.exist?(dockerfile)
64
- dir = File.expand_path(dockerfile).chomp(dockerfile)
65
- image = ::Docker::Image.build_from_dir(
66
- dir,
67
- { 'dockerfile' => dockerfile,
68
- :rm => true,
69
- :buildargs => buildargs_for(host)
70
- }
71
- )
72
- else
73
- raise "Unable to find dockerfile at #{dockerfile}"
74
- end
75
- elsif host['use_image_entry_point']
76
- install_and_run_ssh = true
77
- df = <<-DF
78
- FROM #{host['image']}
79
- EXPOSE 22
80
- DF
81
-
82
- cmd = host['docker_cmd']
83
- df += cmd if cmd
84
118
 
85
- image = ::Docker::Image.build(df, { rm: true, buildargs: buildargs_for(host) })
119
+ image = get_container_image(host)
86
120
 
87
- else
88
-
89
- image = ::Docker::Image.build(dockerfile_for(host),
90
- { rm: true, buildargs: buildargs_for(host) })
121
+ if host['tag']
122
+ image.tag({:repo => host['tag']})
91
123
  end
92
124
 
93
- if host['tag']
94
- image.tag({:repo => host['tag']})
95
- end
96
-
97
125
  if @docker_type == 'swarm'
98
126
  image_name = "#{@registry}/beaker/#{image.id}"
99
127
  ret = ::Docker::Image.search(:term => image_name)
@@ -106,20 +134,7 @@ module Beaker
106
134
  image_name = image.id
107
135
  end
108
136
 
109
- container_opts.merge! ( {
110
- 'Image' => image_name,
111
- 'Hostname' => host.name,
112
- 'HostConfig' => {
113
- 'PortBindings' => {
114
- '22/tcp' => [{ 'HostPort' => rand.to_s[2..5], 'HostIp' => '0.0.0.0'}]
115
- },
116
- 'PublishAllPorts' => true,
117
- 'Privileged' => true,
118
- 'RestartPolicy' => {
119
- 'Name' => 'always'
120
- }
121
- }
122
- } )
137
+ container_opts = get_container_opts(host, image_name)
123
138
  if host['dockeropts'] || @options[:dockeropts]
124
139
  dockeropts = host['dockeropts'] ? host['dockeropts'] : @options[:dockeropts]
125
140
  dockeropts.each do |k,v|
@@ -169,7 +184,7 @@ module Beaker
169
184
  @logger.debug("Starting container #{container.id}")
170
185
  container.start
171
186
 
172
- if install_and_run_ssh
187
+ if install_and_run_ssh(host)
173
188
  @logger.notify("Installing ssh components and starting ssh daemon in #{host} container")
174
189
  install_ssh_components(container, host)
175
190
  # run fixssh to configure and start the ssh service
@@ -100,6 +100,7 @@ module Beaker
100
100
  allow( ::Docker ).to receive(:logger=)
101
101
  allow( ::Docker ).to receive(:version).and_return(version)
102
102
  allow( ::Docker::Image ).to receive(:build).and_return(image)
103
+ allow( ::Docker::Image ).to receive(:create).and_return(image)
103
104
  allow( ::Docker::Container ).to receive(:create).and_return(container)
104
105
  allow_any_instance_of( ::Docker::Container ).to receive(:start)
105
106
  end
@@ -244,6 +245,19 @@ module Beaker
244
245
  end
245
246
  end
246
247
 
248
+ it 'should call image create for hosts when use_image_as_is is defined' do
249
+ hosts.each do |host|
250
+ host['use_image_as_is'] = true
251
+ expect( docker ).not_to receive(:install_ssh_components)
252
+ expect( docker ).not_to receive(:fix_ssh)
253
+ expect( ::Docker::Image ).to receive(:create).with('fromImage' => host['image']) #once per host
254
+ expect( ::Docker::Image ).not_to receive(:build)
255
+ expect( ::Docker::Image ).not_to receive(:build_from_dir)
256
+ end
257
+
258
+ docker.provision
259
+ end
260
+
247
261
  it 'should call dockerfile_for with all the hosts' do
248
262
  hosts.each do |host|
249
263
  expect( docker ).not_to receive(:install_ssh_components)
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.5.2
4
+ version: 0.5.3
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: 2019-02-11 00:00:00.000000000 Z
11
+ date: 2019-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec