centurion 1.9.1 → 1.9.2

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: ac03d4fc21a9efcf750ccd198928a0255d2311f1
4
- data.tar.gz: ebad4c24d759292f10cd2e582d953c54f7167095
3
+ metadata.gz: a616e149340434eb681b993b0fe0503f91dbe0dc
4
+ data.tar.gz: '096241cce242fff7b357fe942488f044f39b6cb0'
5
5
  SHA512:
6
- metadata.gz: ca285ef63081ec02af434daeeb9cc0d8c0f0e141188eeddfba4b360ae16f1916ba62b4d44651817f68a76f13b3c76e0c6c08e7ae6af1c627ac3bec5541a76968
7
- data.tar.gz: b377170c8d4d0012f56ea9b61f1a64e3d64cec149ae2ed1aa8feae8a9fb886d856d2de87b17fd7badcb28c03ca17dc2e4f51485f209256c046b55bee2a62a5de
6
+ metadata.gz: 1f4a17f93aebad77f2a8c59c8a3ceabe58c11bea7d1d4be7c188c4b0264c95b6390e7a622c388809d1ab3e6621a7c3745351b5098ef54f330dc755cd9fe5500b
7
+ data.tar.gz: 136b293f1392c85086d25d28fd61fe7523dafeda29598703c4d37b0c70680fce848a9d56b7be09e592220f6aa9aad9d1b2b8d17ca213cdf3dd2eae1d56b7e642
@@ -1,4 +1,12 @@
1
1
  language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1
6
+ - 2.2
7
+ - 2.3
8
+ - 2.4
9
+ - 2.5
2
10
  before_install:
3
11
  - gem update
4
12
  - gem install bundler
data/README.md CHANGED
@@ -141,6 +141,26 @@ Most of the DSL items (`host_port`, `host_volume`, `env_vars`, `host`) can be
141
141
  specified more than once and will append to the configuration. However, there
142
142
  can only be one `command`; the last one will take priority.
143
143
 
144
+ You can also assign lambdas to environment variables. The lambda function will
145
+ be invoked by Centurion during deploy time with `server_hostname` as its only
146
+ argument. The `server_hostname` yielded will be the same string as was
147
+ specified in the `host` argument for the server currently being deployed to.
148
+
149
+ This is useful to assign a sticky identity for each of the containers
150
+ in the deploy. For example, a hash mapping hostname to another string which is
151
+ different on each host.
152
+ ```ruby
153
+ desc 'Host-specific env vars'
154
+ task :production => :common do
155
+ env_vars MEMBER_ID: lambda do |hostname|
156
+ {
157
+ 'web-server-1.company.net' => 'machine1'
158
+ 'web-server-2.company.net' => 'machine2'
159
+ }[hostname]
160
+ end
161
+ end
162
+ ```
163
+
144
164
  You can cause your container to be started with a specific DNS server
145
165
  IP address (the equivalent of `docker run --dns 172.17.42.1 ...`) like this:
146
166
  ```ruby
@@ -15,7 +15,7 @@ module Centurion::DeployDSL
15
15
  def env_vars(new_vars)
16
16
  current = fetch(:env_vars, {})
17
17
  new_vars.each_pair do |new_key, new_value|
18
- current[new_key.to_s] = new_value.to_s
18
+ current[new_key.to_s] = new_value.respond_to?(:call) ? new_value : new_value.to_s
19
19
  end
20
20
  set(:env_vars, current)
21
21
  end
@@ -125,7 +125,11 @@ module Centurion
125
125
 
126
126
  unless env_vars.empty?
127
127
  container_config['Env'] = env_vars.map do |k,v|
128
- "#{k}=#{interpolate_var(v, server_hostname)}"
128
+ if v.respond_to? :call
129
+ "#{k}=#{v.call(server_hostname)}"
130
+ else
131
+ "#{k}=#{interpolate_var(v, server_hostname)}"
132
+ end
129
133
  end
130
134
  end
131
135
 
@@ -1,3 +1,3 @@
1
1
  module Centurion
2
- VERSION = '1.9.1'
2
+ VERSION = '1.9.2'
3
3
  end
@@ -28,15 +28,18 @@ describe Centurion::DeployDSL do
28
28
  expect(DeployDSLTest.defined_service.command).to eq(command)
29
29
  end
30
30
 
31
- it 'adds new env_vars to the existing ones, as strings' do
31
+ it 'adds new env_vars to the existing ones, maintaining lambdas' do
32
+ lambda = ->() { Random.rand(5) }
32
33
  DeployDSLTest.env_vars('SHAKESPEARE' => 'Hamlet')
33
34
  DeployDSLTest.env_vars('DICKENS' => 'David Copperfield',
34
- DICKENS_BIRTH_YEAR: 1812)
35
+ DICKENS_BIRTH_YEAR: 1812,
36
+ RANDOM_NUMBER: lambda)
35
37
 
36
38
  expect(DeployDSLTest.defined_service.env_vars).to eq(
37
39
  'SHAKESPEARE' => 'Hamlet',
38
40
  'DICKENS' => 'David Copperfield',
39
- 'DICKENS_BIRTH_YEAR' => '1812'
41
+ 'DICKENS_BIRTH_YEAR' => '1812',
42
+ 'RANDOM_NUMBER' => lambda
40
43
  )
41
44
  end
42
45
 
@@ -166,6 +166,12 @@ describe Centurion::Service do
166
166
  expect { service.add_env_vars(SOMETHING: true) }.not_to raise_error
167
167
  end
168
168
 
169
+ it 'does supports lambdas as env vars' do
170
+ service = Centurion::Service.new(:redis)
171
+ service.add_env_vars(DYNAMIC_VAR: ->(hostname) { "the-#{hostname}" })
172
+ expect(service.build_config('example.com')['Env']).to eq(['DYNAMIC_VAR=the-example.com'])
173
+ end
174
+
169
175
  it 'builds a valid docker host configuration' do
170
176
  service = Centurion::Service.new(:redis)
171
177
  service.dns = 'example.com'
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.9.1
4
+ version: 1.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nic Benders
@@ -21,7 +21,7 @@ authors:
21
21
  autorequire:
22
22
  bindir: bin
23
23
  cert_chain: []
24
- date: 2018-04-16 00:00:00.000000000 Z
24
+ date: 2018-07-27 00:00:00.000000000 Z
25
25
  dependencies:
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: trollop
@@ -291,7 +291,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
291
291
  version: '0'
292
292
  requirements: []
293
293
  rubyforge_project:
294
- rubygems_version: 2.5.2
294
+ rubygems_version: 2.6.13
295
295
  signing_key:
296
296
  specification_version: 4
297
297
  summary: A deployment tool for Docker. Takes containers from a Docker registry and