centurion 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,14 +5,14 @@ module Centurion; end
5
5
  module Centurion::Deploy
6
6
  FAILED_CONTAINER_VALIDATION = 100
7
7
 
8
- def stop_containers(target_server, port_bindings)
8
+ def stop_containers(target_server, port_bindings, timeout = 30)
9
9
  public_port = public_port_for(port_bindings)
10
10
  old_containers = target_server.find_containers_by_public_port(public_port)
11
11
  info "Stopping container(s): #{old_containers.inspect}"
12
12
 
13
13
  old_containers.each do |old_container|
14
14
  info "Stopping old container #{old_container['Id'][0..7]} (#{old_container['Names'].join(',')})"
15
- target_server.stop_container(old_container['Id'])
15
+ target_server.stop_container(old_container['Id'], timeout)
16
16
  end
17
17
  end
18
18
 
@@ -67,7 +67,7 @@ module Centurion::Deploy
67
67
  return false unless response
68
68
  return true if response.status >= 200 && response.status < 300
69
69
 
70
- warn "Got HTTP status: #{response.status}"
70
+ warn "Got HTTP status: #{response.status}"
71
71
  false
72
72
  end
73
73
 
@@ -119,39 +119,34 @@ module Centurion::Deploy
119
119
  container_config
120
120
  end
121
121
 
122
- def start_new_container(target_server, image_id, port_bindings, volumes, env_vars=nil, command=nil, cidfile=nil)
122
+ def start_new_container(target_server, image_id, port_bindings, volumes, env_vars=nil, command=nil)
123
123
  container_config = container_config_for(target_server, image_id, port_bindings, env_vars, volumes, command)
124
- start_container_with_config(target_server, volumes, port_bindings, container_config, cidfile)
124
+ start_container_with_config(target_server, volumes, port_bindings, container_config)
125
125
  end
126
126
 
127
- def launch_console(target_server, image_id, port_bindings, volumes, env_vars=nil, cidfile=nil)
127
+ def launch_console(target_server, image_id, port_bindings, volumes, env_vars=nil)
128
128
  container_config = container_config_for(target_server, image_id, port_bindings, env_vars, volumes, ['/bin/bash']).merge(
129
129
  'AttachStdin' => true,
130
130
  'Tty' => true,
131
131
  'OpenStdin' => true,
132
132
  )
133
133
 
134
- container = start_container_with_config(target_server, volumes, port_bindings, container_config, cidfile)
134
+ container = start_container_with_config(target_server, volumes, port_bindings, container_config)
135
135
 
136
136
  target_server.attach(container['Id'])
137
137
  end
138
138
 
139
139
  private
140
-
141
- def start_container_with_config(target_server, volumes, port_bindings, container_config, cidfile)
140
+
141
+ def start_container_with_config(target_server, volumes, port_bindings, container_config)
142
142
  info "Creating new container for #{container_config['Image'][0..7]}"
143
143
  new_container = target_server.create_container(container_config)
144
144
 
145
145
  host_config = {}
146
-
147
146
  # Map some host volumes if needed
148
147
  host_config['Binds'] = volumes if volumes && !volumes.empty?
149
-
150
148
  # Bind the ports
151
- host_config['PortBindings'] = port_bindings
152
-
153
- # Assign cidfile
154
- host_config['ContainerIDFile'] = cidfile if cidfile
149
+ host_config['PortBindings'] = port_bindings
155
150
 
156
151
  info "Starting new container #{new_container['Id'][0..7]}"
157
152
  target_server.start_container(new_container['Id'], host_config)
@@ -11,7 +11,7 @@ module Centurion::DeployDSL
11
11
  def env_vars(new_vars)
12
12
  current = fetch(:env_vars, {})
13
13
  new_vars.each_pair do |new_key, new_value|
14
- current[new_key.to_s] = new_value
14
+ current[new_key.to_s] = new_value.to_s
15
15
  end
16
16
  set(:env_vars, current)
17
17
  end
@@ -51,8 +51,8 @@ class Centurion::DockerViaApi
51
51
  true
52
52
  end
53
53
 
54
- def stop_container(container_id)
55
- path = "/v1.7/containers/#{container_id}/stop?t=30"
54
+ def stop_container(container_id, timeout = 30)
55
+ path = "/v1.7/containers/#{container_id}/stop?t=#{timeout}"
56
56
  response = Excon.post(
57
57
  @base_uri + path,
58
58
  )
@@ -1,3 +1,3 @@
1
1
  module Centurion
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -37,7 +37,9 @@ namespace :deploy do
37
37
  # - remote: list
38
38
  # - remote: stop
39
39
  task :stop do
40
- on_each_docker_host { |server| stop_containers(server, fetch(:port_bindings)) }
40
+ on_each_docker_host do |server|
41
+ stop_containers(server, fetch(:port_bindings), fetch(:stop_timeout, 30))
42
+ end
41
43
  end
42
44
 
43
45
  # start
@@ -51,8 +53,7 @@ namespace :deploy do
51
53
  fetch(:image_id),
52
54
  fetch(:port_bindings),
53
55
  fetch(:binds),
54
- fetch(:env_vars),
55
- fetch(:cidfile, '/etc/cidfile')
56
+ fetch(:env_vars)
56
57
  )
57
58
  end
58
59
  end
@@ -64,23 +65,21 @@ namespace :deploy do
64
65
  fetch(:image_id),
65
66
  fetch(:port_bindings),
66
67
  fetch(:binds),
67
- fetch(:env_vars),
68
- fetch(:cidfile, '/etc/cidfile')
68
+ fetch(:env_vars)
69
69
  )
70
70
  end
71
71
  end
72
72
 
73
73
  task :rolling_deploy do
74
74
  on_each_docker_host do |server|
75
- stop_containers(server, fetch(:port_bindings))
75
+ stop_containers(server, fetch(:port_bindings), fetch(:stop_timeout, 30))
76
76
 
77
77
  start_new_container(
78
78
  server,
79
79
  fetch(:image_id),
80
80
  fetch(:port_bindings),
81
81
  fetch(:binds),
82
- fetch(:env_vars),
83
- fetch(:cidfile, '/etc/cidfile')
82
+ fetch(:env_vars)
84
83
  )
85
84
 
86
85
  fetch(:port_bindings).each_pair do |container_port, host_ports|
@@ -28,13 +28,15 @@ describe Centurion::DeployDSL do
28
28
  expect(DeployDSLTest.fetch(:command)).to equal(command)
29
29
  end
30
30
 
31
- it 'adds new env_vars to the existing ones' do
31
+ it 'adds new env_vars to the existing ones, as strings' do
32
32
  DeployDSLTest.set(:env_vars, { 'SHAKESPEARE' => 'Hamlet' })
33
- DeployDSLTest.env_vars('DICKENS' => 'David Copperfield')
33
+ DeployDSLTest.env_vars('DICKENS' => 'David Copperfield',
34
+ :DICKENS_BIRTH_YEAR => 1812)
34
35
 
35
36
  expect(DeployDSLTest.fetch(:env_vars)).to include(
36
- 'SHAKESPEARE' => 'Hamlet',
37
- 'DICKENS' => 'David Copperfield'
37
+ 'SHAKESPEARE' => 'Hamlet',
38
+ 'DICKENS' => 'David Copperfield',
39
+ 'DICKENS_BIRTH_YEAR' => '1812'
38
40
  )
39
41
  end
40
42
 
@@ -9,8 +9,8 @@ describe Centurion::Deploy do
9
9
  let(:port) { 8484 }
10
10
  let(:container) { { 'Ports' => [{ 'PublicPort' => port }, 'Created' => Time.now.to_i ], 'Id' => '21adfd2ef2ef2349494a', 'Names' => [ 'name1' ] } }
11
11
  let(:endpoint) { '/status/check' }
12
- let(:test_deploy) do
13
- Object.new.tap do |o|
12
+ let(:test_deploy) do
13
+ Object.new.tap do |o|
14
14
  o.send(:extend, Centurion::Deploy)
15
15
  o.send(:extend, Centurion::DeployDSL)
16
16
  o.send(:extend, Centurion::Logging)
@@ -84,7 +84,7 @@ describe Centurion::Deploy do
84
84
  test_deploy.stub(:warn)
85
85
  expect(test_deploy).to receive(:exit)
86
86
  expect(test_deploy).to receive(:sleep).with(0)
87
-
87
+
88
88
  test_deploy.wait_for_http_status_ok(server, port, '/foo', 'image_id', 'chaucer', 0, 1)
89
89
  expect(test_deploy).to have_received(:info).with(/Waiting for the port/)
90
90
  end
@@ -95,7 +95,7 @@ describe Centurion::Deploy do
95
95
  test_deploy.stub(:error)
96
96
  test_deploy.stub(:warn)
97
97
  expect(test_deploy).to receive(:exit)
98
-
98
+
99
99
  test_deploy.wait_for_http_status_ok(server, port, '/foo', 'image_id', 'chaucer', 1, 0)
100
100
  expect(test_deploy).to have_received(:info).with(/Waiting for the port/)
101
101
  end
@@ -126,8 +126,8 @@ describe Centurion::Deploy do
126
126
 
127
127
  expect(server).to receive(:find_containers_by_public_port).and_return(containers)
128
128
  expect(test_deploy).to receive(:public_port_for).with(bindings).and_return('80')
129
- expect(server).to receive(:stop_container).with(container['Id']).once
130
- expect(server).to receive(:stop_container).with(second_container['Id']).once
129
+ expect(server).to receive(:stop_container).with(container['Id'], 30).once
130
+ expect(server).to receive(:stop_container).with(second_container['Id'], 30).once
131
131
 
132
132
  test_deploy.stop_containers(server, bindings)
133
133
  end
@@ -229,12 +229,11 @@ describe Centurion::Deploy do
229
229
  expect(server).to receive(:start_container).with(
230
230
  'abc123456',
231
231
  {
232
- 'PortBindings' => bindings,
233
- 'ContainerIDFile' => '/etc/cidfile'
232
+ 'PortBindings' => bindings
234
233
  }
235
234
  ).once
236
235
 
237
- test_deploy.start_new_container(server, 'image_id', bindings, {}, nil, nil, '/etc/cidfile')
236
+ test_deploy.start_new_container(server, 'image_id', bindings, {}, nil, nil)
238
237
  end
239
238
  end
240
239
 
@@ -252,16 +251,8 @@ describe Centurion::Deploy do
252
251
  test_deploy.start_new_container(server, 'image_id', bindings, {}, nil)
253
252
  end
254
253
 
255
- it 'pass cidfile to start_container_with_config method' do
256
- test_deploy.stub(:container_config_for)
257
-
258
- expect(test_deploy).to receive(:start_container_with_config).with(server, anything(), bindings, nil, '/etc/cidfile').once
259
-
260
- test_deploy.start_new_container(server, 'image_id', bindings, {}, nil, nil, '/etc/cidfile')
261
- end
262
-
263
254
  it 'starts the container' do
264
- expect(test_deploy).to receive(:start_container_with_config).with(server, {}, anything(), anything(), anything())
255
+ expect(test_deploy).to receive(:start_container_with_config).with(server, {}, anything(), anything())
265
256
 
266
257
  test_deploy.start_new_container(server, 'image_id', bindings, {})
267
258
  end
@@ -291,20 +282,18 @@ describe Centurion::Deploy do
291
282
  let(:volumes) { nil }
292
283
  let(:env) { nil }
293
284
  let(:command) { nil }
294
- let(:cidfile) { nil }
295
285
 
296
286
  it 'configures the container' do
297
287
  expect(test_deploy).to receive(:container_config_for).with(server, 'image_id', bindings, env, volumes, command).once
298
288
  test_deploy.stub(:start_container_with_config)
299
289
 
300
- test_deploy.start_new_container(server, 'image_id', bindings, volumes, env, command, cidfile)
290
+ test_deploy.start_new_container(server, 'image_id', bindings, volumes, env, command)
301
291
  end
302
292
 
303
293
  it 'augments the container_config' do
304
294
  expect(test_deploy).to receive(:start_container_with_config).with(server, volumes,
305
295
  anything(),
306
- hash_including('Cmd' => [ '/bin/bash' ], 'AttachStdin' => true , 'Tty' => true , 'OpenStdin' => true),
307
- anything()
296
+ hash_including('Cmd' => [ '/bin/bash' ], 'AttachStdin' => true , 'Tty' => true , 'OpenStdin' => true)
308
297
  ).and_return({'Id' => 'shakespeare'})
309
298
 
310
299
  test_deploy.launch_console(server, 'image_id', bindings, volumes, env)
@@ -312,7 +301,7 @@ describe Centurion::Deploy do
312
301
 
313
302
  it 'starts the console' do
314
303
  expect(test_deploy).to receive(:start_container_with_config).with(
315
- server, nil, anything(), anything(), anything()
304
+ server, nil, anything(), anything()
316
305
  ).and_return({'Id' => 'shakespeare'})
317
306
 
318
307
  test_deploy.launch_console(server, 'image_id', bindings, volumes, env)
@@ -61,6 +61,13 @@ describe Centurion::DockerViaApi do
61
61
  end
62
62
 
63
63
  it 'stops a container' do
64
+ expect(Excon).to receive(:post).
65
+ with(excon_uri + "v1.7" + "/containers/12345/stop?t=300").
66
+ and_return(double(status: 204))
67
+ api.stop_container('12345', 300)
68
+ end
69
+
70
+ it 'stops a container with a custom timeout' do
64
71
  expect(Excon).to receive(:post).
65
72
  with(excon_uri + "v1.7" + "/containers/12345/stop?t=30").
66
73
  and_return(double(status: 204))
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: centurion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Nic Benders
@@ -20,118 +21,134 @@ authors:
20
21
  autorequire:
21
22
  bindir: bin
22
23
  cert_chain: []
23
- date: 2014-09-08 00:00:00.000000000 Z
24
+ date: 2014-10-07 00:00:00.000000000 Z
24
25
  dependencies:
25
26
  - !ruby/object:Gem::Dependency
26
27
  name: trollop
27
28
  requirement: !ruby/object:Gem::Requirement
29
+ none: false
28
30
  requirements:
29
- - - ">="
31
+ - - ! '>='
30
32
  - !ruby/object:Gem::Version
31
33
  version: '0'
32
34
  type: :runtime
33
35
  prerelease: false
34
36
  version_requirements: !ruby/object:Gem::Requirement
37
+ none: false
35
38
  requirements:
36
- - - ">="
39
+ - - ! '>='
37
40
  - !ruby/object:Gem::Version
38
41
  version: '0'
39
42
  - !ruby/object:Gem::Dependency
40
43
  name: excon
41
44
  requirement: !ruby/object:Gem::Requirement
45
+ none: false
42
46
  requirements:
43
- - - "~>"
47
+ - - ~>
44
48
  - !ruby/object:Gem::Version
45
49
  version: '0.33'
46
50
  type: :runtime
47
51
  prerelease: false
48
52
  version_requirements: !ruby/object:Gem::Requirement
53
+ none: false
49
54
  requirements:
50
- - - "~>"
55
+ - - ~>
51
56
  - !ruby/object:Gem::Version
52
57
  version: '0.33'
53
58
  - !ruby/object:Gem::Dependency
54
59
  name: logger-colors
55
60
  requirement: !ruby/object:Gem::Requirement
61
+ none: false
56
62
  requirements:
57
- - - ">="
63
+ - - ! '>='
58
64
  - !ruby/object:Gem::Version
59
65
  version: '0'
60
66
  type: :runtime
61
67
  prerelease: false
62
68
  version_requirements: !ruby/object:Gem::Requirement
69
+ none: false
63
70
  requirements:
64
- - - ">="
71
+ - - ! '>='
65
72
  - !ruby/object:Gem::Version
66
73
  version: '0'
67
74
  - !ruby/object:Gem::Dependency
68
75
  name: bundler
69
76
  requirement: !ruby/object:Gem::Requirement
77
+ none: false
70
78
  requirements:
71
- - - ">="
79
+ - - ! '>='
72
80
  - !ruby/object:Gem::Version
73
81
  version: '0'
74
82
  type: :development
75
83
  prerelease: false
76
84
  version_requirements: !ruby/object:Gem::Requirement
85
+ none: false
77
86
  requirements:
78
- - - ">="
87
+ - - ! '>='
79
88
  - !ruby/object:Gem::Version
80
89
  version: '0'
81
90
  - !ruby/object:Gem::Dependency
82
91
  name: rake
83
92
  requirement: !ruby/object:Gem::Requirement
93
+ none: false
84
94
  requirements:
85
- - - ">="
95
+ - - ! '>='
86
96
  - !ruby/object:Gem::Version
87
97
  version: '0'
88
98
  type: :development
89
99
  prerelease: false
90
100
  version_requirements: !ruby/object:Gem::Requirement
101
+ none: false
91
102
  requirements:
92
- - - ">="
103
+ - - ! '>='
93
104
  - !ruby/object:Gem::Version
94
105
  version: '0'
95
106
  - !ruby/object:Gem::Dependency
96
107
  name: rspec
97
108
  requirement: !ruby/object:Gem::Requirement
109
+ none: false
98
110
  requirements:
99
- - - "~>"
111
+ - - ~>
100
112
  - !ruby/object:Gem::Version
101
113
  version: 2.14.0
102
114
  type: :development
103
115
  prerelease: false
104
116
  version_requirements: !ruby/object:Gem::Requirement
117
+ none: false
105
118
  requirements:
106
- - - "~>"
119
+ - - ~>
107
120
  - !ruby/object:Gem::Version
108
121
  version: 2.14.0
109
122
  - !ruby/object:Gem::Dependency
110
123
  name: pry
111
124
  requirement: !ruby/object:Gem::Requirement
125
+ none: false
112
126
  requirements:
113
- - - ">="
127
+ - - ! '>='
114
128
  - !ruby/object:Gem::Version
115
129
  version: '0'
116
130
  type: :development
117
131
  prerelease: false
118
132
  version_requirements: !ruby/object:Gem::Requirement
133
+ none: false
119
134
  requirements:
120
- - - ">="
135
+ - - ! '>='
121
136
  - !ruby/object:Gem::Version
122
137
  version: '0'
123
138
  - !ruby/object:Gem::Dependency
124
139
  name: simplecov
125
140
  requirement: !ruby/object:Gem::Requirement
141
+ none: false
126
142
  requirements:
127
- - - ">="
143
+ - - ! '>='
128
144
  - !ruby/object:Gem::Version
129
145
  version: '0'
130
146
  type: :development
131
147
  prerelease: false
132
148
  version_requirements: !ruby/object:Gem::Requirement
149
+ none: false
133
150
  requirements:
134
- - - ">="
151
+ - - ! '>='
135
152
  - !ruby/object:Gem::Version
136
153
  version: '0'
137
154
  description:
@@ -155,7 +172,7 @@ executables:
155
172
  extensions: []
156
173
  extra_rdoc_files: []
157
174
  files:
158
- - ".gitignore"
175
+ - .gitignore
159
176
  - CONTRIBUTORS.md
160
177
  - Gemfile
161
178
  - LICENSE
@@ -192,26 +209,27 @@ files:
192
209
  homepage: https://github.com/newrelic/centurion
193
210
  licenses:
194
211
  - MIT
195
- metadata: {}
196
212
  post_install_message:
197
213
  rdoc_options: []
198
214
  require_paths:
199
215
  - lib
200
216
  required_ruby_version: !ruby/object:Gem::Requirement
217
+ none: false
201
218
  requirements:
202
- - - ">="
219
+ - - ! '>='
203
220
  - !ruby/object:Gem::Version
204
221
  version: 1.9.3
205
222
  required_rubygems_version: !ruby/object:Gem::Requirement
223
+ none: false
206
224
  requirements:
207
- - - ">="
225
+ - - ! '>='
208
226
  - !ruby/object:Gem::Version
209
227
  version: '0'
210
228
  requirements: []
211
229
  rubyforge_project:
212
- rubygems_version: 2.2.2
230
+ rubygems_version: 1.8.23
213
231
  signing_key:
214
- specification_version: 4
232
+ specification_version: 3
215
233
  summary: A deployment tool for Docker. Takes containers from a Docker registry and
216
234
  runs them on a fleet of hosts with the correct environment variables, host mappings,
217
235
  and port mappings. Supports rolling deployments out of the box, and makes it easy
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 3eb7f396991461f2a7e0db2fe83ff6209313233e
4
- data.tar.gz: ee9f4bc48a899190fa48439353f5803523bbe2ec
5
- SHA512:
6
- metadata.gz: e0f35cd1e2626d5fd1c582ae2397c07b9daa7f53ace494094eea423f02865cba1d2852202e90cba8d7e82357002613db2ae48ee9e7280b11a6d53b329905b1f4
7
- data.tar.gz: 01577cabe24211a9e65df8d0e4a140fd18042fab6742d5e65ed567becea161bc2582179b8c86df11055a69234b21f43e5b536c9f36a088bf79af0f139ad39905