centurion 1.8.9 → 1.8.10

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8966e2e693a5e6dd465d8c656622937e5844aca
4
- data.tar.gz: b7d314a3c53734bf240f1662c91ce8a69044faf0
3
+ metadata.gz: ec921ec16391c51e0941a6a9e2d6fe2e060155da
4
+ data.tar.gz: 5ee10d7e3028d1135e5fe4eb1f8075e1146e643c
5
5
  SHA512:
6
- metadata.gz: d3b49c8b73ef7206922b8ccb700a14a43d53fa2a3b0a7f3d8706fc59a22041bbcbdad44d7af83a9fdf6372743ea558fdc919404d5d1f6ac94e08beae22bd2c6c
7
- data.tar.gz: 9972af6f0db91ea3ecfb9eb977090822109fd78faf285d48d2d64b680f0edf757f97e004bd38c12048a2d13cf554fac83f88e1d379c55199d874e2e9f5fcba52
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
- *Note:* While `host_port` remains required, the mappings specified in it are
219
- *ignored* when using `host` and `container...` network modes.
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
 
@@ -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]
@@ -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
@@ -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.")
@@ -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?
@@ -1,3 +1,3 @@
1
1
  module Centurion
2
- VERSION = '1.8.9'
2
+ VERSION = '1.8.10'
3
3
  end
@@ -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'
@@ -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
@@ -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.9
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-01-13 00:00:00.000000000 Z
23
+ date: 2017-03-06 00:00:00.000000000 Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: trollop