centurion 1.8.9 → 1.8.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +38 -2
- data/bin/centurion +1 -1
- data/lib/centurion/deploy.rb +1 -1
- data/lib/centurion/deploy_dsl.rb +8 -0
- data/lib/centurion/service.rb +8 -1
- data/lib/centurion/version.rb +1 -1
- data/spec/deploy_dsl_spec.rb +12 -0
- data/spec/deploy_spec.rb +16 -0
- data/spec/service_spec.rb +9 -0
- 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: ec921ec16391c51e0941a6a9e2d6fe2e060155da
|
4
|
+
data.tar.gz: 5ee10d7e3028d1135e5fe4eb1f8075e1146e643c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8a80e7c694b008596459d7ce7b05000c2a50e6d7e89d388e7589a59287059b2bd487b6dea8fb683e9d283f333e372854aa3900673094d98202e817e6b1bbe5d
|
7
|
+
data.tar.gz: cb23d715dff77b5cb3b0d20fe9d8e3e9dbb74f14c34322e4553024f098ba9b4cc6e6d833b96a355fd970400e9a95aa1a0624448d6e85f9cd928fa35166a1156c
|
data/README.md
CHANGED
@@ -173,6 +173,40 @@ deploy a project:
|
|
173
173
|
```
|
174
174
|
With this, the container will be named something like `backend-4f692997`.
|
175
175
|
|
176
|
+
### Container Labels
|
177
|
+
|
178
|
+
You may add arbitrary labels to your containers by calling `labels` with a hash.
|
179
|
+
The call is cumulative, so you may express patterns like:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
namespace :environment do
|
183
|
+
task :common do
|
184
|
+
set :image, 'example.com/newrelic/radio-radio'
|
185
|
+
host 'docker-server-1.example.com'
|
186
|
+
labels team: 'radio-ops'
|
187
|
+
end
|
188
|
+
|
189
|
+
desc 'Staging environment'
|
190
|
+
task :staging => :common do
|
191
|
+
labels environment: 'radio-staging'
|
192
|
+
env_vars YOUR_ENV: 'staging'
|
193
|
+
end
|
194
|
+
end
|
195
|
+
```
|
196
|
+
|
197
|
+
This would result in the container having two labels, as shown in a
|
198
|
+
`docker inspect` example:
|
199
|
+
|
200
|
+
```
|
201
|
+
"Labels": {
|
202
|
+
"team": "radio-ops",
|
203
|
+
"environment": "radio-staging"
|
204
|
+
}
|
205
|
+
```
|
206
|
+
|
207
|
+
Hash keys and values will be stringified, so you may pass any object with a
|
208
|
+
`#to_s` method.
|
209
|
+
|
176
210
|
### Container Hostnames
|
177
211
|
|
178
212
|
If you don't specify a hostname to use inside your container, the container
|
@@ -215,8 +249,10 @@ set :network_mode, 'networkmode'
|
|
215
249
|
Docker (and therefore Centurion) supports one of `bridge` (the default), `host`,
|
216
250
|
and `container:<container-id>` for this argument.
|
217
251
|
|
218
|
-
|
219
|
-
|
252
|
+
In `host` and `container...` network modes, you may specify a
|
253
|
+
`host_port, container_port` mapping, however the port numbers will only be used
|
254
|
+
for container health checks. The mapping itself, while still passed via the API,
|
255
|
+
will be ignored by Docker.
|
220
256
|
|
221
257
|
### CGroup Resource Constraints
|
222
258
|
|
data/bin/centurion
CHANGED
@@ -55,7 +55,7 @@ invoke("environment:#{opts[:environment]}")
|
|
55
55
|
set :image, opts[:image] if opts[:image]
|
56
56
|
set :tag, opts[:tag] if opts[:tag]
|
57
57
|
set :hosts, opts[:hosts].split(",") if opts[:hosts]
|
58
|
-
set :name, opts[:project].gsub(/_/, '-')
|
58
|
+
set :name, opts[:project].gsub(/_/, '-') unless fetch(:name)
|
59
59
|
|
60
60
|
# Override environment variables when specified
|
61
61
|
if opts[:override_env]
|
data/lib/centurion/deploy.rb
CHANGED
@@ -7,7 +7,7 @@ module Centurion::Deploy
|
|
7
7
|
FAILED_CONTAINER_VALIDATION = 100
|
8
8
|
|
9
9
|
def stop_containers(target_server, service, timeout = 30)
|
10
|
-
old_containers = if service.public_ports.nil? || service.public_ports.empty?
|
10
|
+
old_containers = if service.public_ports.nil? || service.public_ports.empty? || service.network_mode == 'host'
|
11
11
|
info "Looking for containers with names like #{service.name}"
|
12
12
|
target_server.find_containers_by_name(service.name)
|
13
13
|
else
|
data/lib/centurion/deploy_dsl.rb
CHANGED
@@ -20,6 +20,14 @@ module Centurion::DeployDSL
|
|
20
20
|
set(:env_vars, current)
|
21
21
|
end
|
22
22
|
|
23
|
+
def labels(new_labels)
|
24
|
+
current = fetch(:labels, {})
|
25
|
+
new_labels.each_pair do |new_key, new_value|
|
26
|
+
current[new_key.to_s] = new_value.to_s
|
27
|
+
end
|
28
|
+
set(:labels, current)
|
29
|
+
end
|
30
|
+
|
23
31
|
def add_capability(new_cap_adds)
|
24
32
|
if !valid_capability?(new_cap_adds)
|
25
33
|
abort("Invalid capability addition #{new_cap_adds} specified.")
|
data/lib/centurion/service.rb
CHANGED
@@ -6,7 +6,7 @@ module Centurion
|
|
6
6
|
extend ::Capistrano::DSL
|
7
7
|
|
8
8
|
attr_accessor :command, :dns, :extra_hosts, :image, :name, :volumes, :port_bindings, :network_mode, :cap_adds, :cap_drops, :ipc_mode
|
9
|
-
attr_reader :memory, :cpu_shares, :env_vars
|
9
|
+
attr_reader :memory, :cpu_shares, :env_vars, :labels
|
10
10
|
|
11
11
|
def initialize(name)
|
12
12
|
@name = name
|
@@ -15,6 +15,7 @@ module Centurion
|
|
15
15
|
@port_bindings = []
|
16
16
|
@cap_adds = []
|
17
17
|
@cap_drops = []
|
18
|
+
@labels = {}
|
18
19
|
@network_mode = 'bridge'
|
19
20
|
end
|
20
21
|
|
@@ -38,6 +39,7 @@ module Centurion
|
|
38
39
|
s.cpu_shares = fetch(:cpu_shares, 0)
|
39
40
|
s.ipc_mode = fetch(:ipc_mode, nil)
|
40
41
|
|
42
|
+
s.add_labels(fetch(:labels, {}))
|
41
43
|
s.add_env_vars(fetch(:env_vars, {}))
|
42
44
|
end
|
43
45
|
end
|
@@ -54,6 +56,10 @@ module Centurion
|
|
54
56
|
@volumes << Volume.new(host_volume, container_volume)
|
55
57
|
end
|
56
58
|
|
59
|
+
def add_labels(labels)
|
60
|
+
@labels.merge!(Hash[labels.map { |(k,v)| [ k.to_s, v.to_s ]}])
|
61
|
+
end
|
62
|
+
|
57
63
|
def cap_adds=(capabilites)
|
58
64
|
unless capabilites.is_a? Array
|
59
65
|
raise ArgumentError, "invalid value for capability additions: #{capabilites}, value must be an array"
|
@@ -101,6 +107,7 @@ module Centurion
|
|
101
107
|
c['Cmd'] = command if command
|
102
108
|
c['Memory'] = memory if memory
|
103
109
|
c['CpuShares'] = cpu_shares if cpu_shares
|
110
|
+
c['Labels'] = labels unless labels.nil? || labels.empty?
|
104
111
|
end
|
105
112
|
|
106
113
|
unless port_bindings.empty?
|
data/lib/centurion/version.rb
CHANGED
data/spec/deploy_dsl_spec.rb
CHANGED
@@ -40,6 +40,18 @@ describe Centurion::DeployDSL do
|
|
40
40
|
)
|
41
41
|
end
|
42
42
|
|
43
|
+
it 'adds new labels to the existing ones, as strings' do
|
44
|
+
DeployDSLTest.labels(Shakespeare: 'Hamlet')
|
45
|
+
DeployDSLTest.labels(Dickens: 'David Copperfield',
|
46
|
+
Dickens_birth_year: 1812)
|
47
|
+
|
48
|
+
expect(DeployDSLTest.defined_service.labels).to eq(
|
49
|
+
'Shakespeare' => 'Hamlet',
|
50
|
+
'Dickens' => 'David Copperfield',
|
51
|
+
'Dickens_birth_year' => '1812'
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
43
55
|
describe '#add_capability' do
|
44
56
|
it 'adds one capability' do
|
45
57
|
DeployDSLTest.add_capability 'IPC_LOCK'
|
data/spec/deploy_spec.rb
CHANGED
@@ -147,6 +147,22 @@ describe Centurion::Deploy do
|
|
147
147
|
|
148
148
|
test_deploy.stop_containers(server, service)
|
149
149
|
end
|
150
|
+
|
151
|
+
it 'calls stop_container on the right containers in host networking mode' do
|
152
|
+
service = Centurion::Service.new(:centurion)
|
153
|
+
service.network_mode = 'host'
|
154
|
+
service.add_port_bindings(8080, 80)
|
155
|
+
|
156
|
+
second_container = container.dup
|
157
|
+
second_container = container.dup.tap { |c| c['Id'] = c['Id'].sub(/49494/, '55555') }
|
158
|
+
containers = [ container, second_container ]
|
159
|
+
|
160
|
+
expect(server).to receive(:find_containers_by_name).with(:centurion).and_return(containers)
|
161
|
+
expect(server).to receive(:stop_container).with(container['Id'], 30).once
|
162
|
+
expect(server).to receive(:stop_container).with(second_container['Id'], 30).once
|
163
|
+
|
164
|
+
test_deploy.stop_containers(server, service)
|
165
|
+
end
|
150
166
|
end
|
151
167
|
|
152
168
|
describe '#wait_for_load_balancer_check_interval' do
|
data/spec/service_spec.rb
CHANGED
@@ -6,6 +6,7 @@ describe Centurion::Service do
|
|
6
6
|
let(:service) { Centurion::Service.new(:redis) }
|
7
7
|
let(:hostname) { 'shakespeare' }
|
8
8
|
let(:image) { 'redis' }
|
9
|
+
let(:labels) { { 'test' => '123' } }
|
9
10
|
|
10
11
|
it 'creates a service from the environment' do
|
11
12
|
extend Capistrano::DSL
|
@@ -15,6 +16,7 @@ describe Centurion::Service do
|
|
15
16
|
set(:hostname, hostname)
|
16
17
|
set(:binds, [ Centurion::Service::Volume.new('/foo', '/foo/bar') ])
|
17
18
|
set(:port_bindings, [ Centurion::Service::PortBinding.new(12340, 80, 'tcp') ])
|
19
|
+
set(:labels, labels)
|
18
20
|
|
19
21
|
svc = Centurion::Service.from_env
|
20
22
|
expect(svc.name).to eq('mycontainer')
|
@@ -24,6 +26,7 @@ describe Centurion::Service do
|
|
24
26
|
expect(svc.volumes.first.host_volume).to eq('/foo')
|
25
27
|
expect(svc.port_bindings.size).to eq(1)
|
26
28
|
expect(svc.port_bindings.first.container_port).to eq(80)
|
29
|
+
expect(svc.labels).to eq(labels)
|
27
30
|
end
|
28
31
|
|
29
32
|
it 'starts with a command' do
|
@@ -70,6 +73,12 @@ describe Centurion::Service do
|
|
70
73
|
expect(service.env_vars).to eq(SLAVE_OF: '127.0.0.1', USE_AOF: '1')
|
71
74
|
end
|
72
75
|
|
76
|
+
it 'has labels and flattens them all to text' do
|
77
|
+
service.add_labels(labels)
|
78
|
+
service.add_labels(another: 'label')
|
79
|
+
expect(service.labels).to eq(labels.merge('another' => 'label'))
|
80
|
+
end
|
81
|
+
|
73
82
|
it 'has volume bindings' do
|
74
83
|
service.add_volume('/volumes/redis/data', '/data')
|
75
84
|
service.add_volume('/volumes/redis/config', '/config')
|
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.8.
|
4
|
+
version: 1.8.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nic Benders
|
@@ -20,7 +20,7 @@ authors:
|
|
20
20
|
autorequire:
|
21
21
|
bindir: bin
|
22
22
|
cert_chain: []
|
23
|
-
date: 2017-
|
23
|
+
date: 2017-03-06 00:00:00.000000000 Z
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: trollop
|