centurion 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -138,19 +138,40 @@ module Centurion::Deploy
138
138
 
139
139
  private
140
140
 
141
+ # By default we always use on-failure policy.
142
+ def build_host_config_restart_policy(host_config={})
143
+ host_config['RestartPolicy'] = {}
144
+
145
+ restart_policy_name = fetch(:restart_policy_name) || 'on-failure'
146
+ restart_policy_name = 'on-failure' unless ["always", "on-failure", "no"].include?(restart_policy_name)
147
+
148
+ restart_policy_max_retry_count = fetch(:restart_policy_max_retry_count) || 10
149
+
150
+ host_config['RestartPolicy']['Name'] = restart_policy_name
151
+ host_config['RestartPolicy']['MaximumRetryCount'] = restart_policy_max_retry_count if restart_policy_name == 'on-failure'
152
+
153
+ host_config
154
+ end
155
+
141
156
  def start_container_with_config(target_server, volumes, port_bindings, container_config)
142
157
  info "Creating new container for #{container_config['Image'][0..7]}"
143
158
  new_container = target_server.create_container(container_config, fetch(:name))
144
159
 
145
160
  host_config = {}
161
+
146
162
  # Map some host volumes if needed
147
163
  host_config['Binds'] = volumes if volumes && !volumes.empty?
164
+
148
165
  # Bind the ports
149
166
  host_config['PortBindings'] = port_bindings
167
+
150
168
  # DNS if specified
151
169
  dns = fetch(:custom_dns)
152
170
  host_config['Dns'] = dns if dns
153
171
 
172
+ # Restart Policy
173
+ host_config = build_host_config_restart_policy(host_config)
174
+
154
175
  info "Starting new container #{new_container['Id'][0..7]}"
155
176
  target_server.start_container(new_container['Id'], host_config)
156
177
 
@@ -1,3 +1,3 @@
1
1
  module Centurion
2
- VERSION = '1.4.0'
2
+ VERSION = '1.4.1'
3
3
  end
@@ -241,7 +241,110 @@ describe Centurion::Deploy do
241
241
  'abc123456',
242
242
  {
243
243
  'PortBindings' => bindings,
244
- 'Dns' => '8.8.8.8'
244
+ 'Dns' => '8.8.8.8',
245
+ 'RestartPolicy' => {
246
+ 'Name' => 'on-failure',
247
+ 'MaximumRetryCount' => 10
248
+ }
249
+ }
250
+ ).once
251
+
252
+ test_deploy.start_new_container(server, 'image_id', bindings, {}, nil, nil)
253
+ end
254
+ end
255
+
256
+ describe '#start_container_with_restart_policy' do
257
+ let(:bindings) { {'80/tcp'=>[{'HostIp'=>'0.0.0.0', 'HostPort'=>'80'}]} }
258
+
259
+ before do
260
+ allow(server).to receive(:container_config_for).and_return({
261
+ 'Image' => 'image_id',
262
+ 'Hostname' => server.hostname,
263
+ })
264
+
265
+ allow(server).to receive(:create_container).and_return({
266
+ 'Id' => 'abc123456'
267
+ })
268
+
269
+ allow(server).to receive(:inspect_container)
270
+ end
271
+
272
+ it 'pass no restart policy to start_container' do
273
+ expect(server).to receive(:start_container).with(
274
+ 'abc123456',
275
+ {
276
+ 'PortBindings' => bindings,
277
+ 'RestartPolicy' => {
278
+ 'Name' => 'on-failure',
279
+ 'MaximumRetryCount' => 10
280
+ }
281
+ }
282
+ ).once
283
+
284
+ test_deploy.start_new_container(server, 'image_id', bindings, {}, nil, nil)
285
+ end
286
+
287
+ it 'pass "always" restart policy to start_container' do
288
+ allow(test_deploy).to receive(:fetch).with(:restart_policy_name).and_return('always')
289
+
290
+ expect(server).to receive(:start_container).with(
291
+ 'abc123456',
292
+ {
293
+ 'PortBindings' => bindings,
294
+ 'RestartPolicy' => {
295
+ 'Name' => 'always'
296
+ }
297
+ }
298
+ ).once
299
+
300
+ test_deploy.start_new_container(server, 'image_id', bindings, {}, nil, nil)
301
+ end
302
+
303
+ it 'pass "on-failure with 50 retries" restart policy to start_container' do
304
+ allow(test_deploy).to receive(:fetch).with(:restart_policy_name).and_return('on-failure')
305
+ allow(test_deploy).to receive(:fetch).with(:restart_policy_max_retry_count).and_return(50)
306
+
307
+ expect(server).to receive(:start_container).with(
308
+ 'abc123456',
309
+ {
310
+ 'PortBindings' => bindings,
311
+ 'RestartPolicy' => {
312
+ 'Name' => 'on-failure',
313
+ 'MaximumRetryCount' => 50
314
+ }
315
+ }
316
+ ).once
317
+
318
+ test_deploy.start_new_container(server, 'image_id', bindings, {}, nil, nil)
319
+ end
320
+
321
+ it 'pass "no" restart policy to start_container' do
322
+ allow(test_deploy).to receive(:fetch).with(:restart_policy_name).and_return('no')
323
+
324
+ expect(server).to receive(:start_container).with(
325
+ 'abc123456',
326
+ {
327
+ 'PortBindings' => bindings,
328
+ 'RestartPolicy' => {
329
+ 'Name' => 'no'
330
+ }
331
+ }
332
+ ).once
333
+
334
+ test_deploy.start_new_container(server, 'image_id', bindings, {}, nil, nil)
335
+ end
336
+
337
+ it 'pass "garbage" restart policy to start_container' do
338
+ allow(test_deploy).to receive(:fetch).with(:restart_policy_name).and_return('garbage')
339
+
340
+ expect(server).to receive(:start_container).with(
341
+ 'abc123456',
342
+ {
343
+ 'PortBindings' => bindings,
344
+ 'RestartPolicy' => {
345
+ 'Name' => 'on-failure',
346
+ 'MaximumRetryCount' => 10
347
+ }
245
348
  }
246
349
  ).once
247
350
 
@@ -50,8 +50,10 @@ describe Centurion::Dogestry do
50
50
 
51
51
  describe '#pull' do
52
52
  it 'returns correct value' do
53
- expect(registry).to receive(:echo).with("dogestry #{flags} pull #{registry.s3_url} #{repo}")
54
- registry.pull(repo, pull_hosts)
53
+ if registry.which('dogestry')
54
+ expect(registry).to receive(:echo).with("dogestry pull #{registry.s3_url} #{repo}")
55
+ registry.pull(repo, {})
56
+ end
55
57
  end
56
58
  end
57
59
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: centurion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -21,7 +21,7 @@ authors:
21
21
  autorequire:
22
22
  bindir: bin
23
23
  cert_chain: []
24
- date: 2015-01-06 00:00:00.000000000 Z
24
+ date: 2015-01-09 00:00:00.000000000 Z
25
25
  dependencies:
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: trollop