centurion 1.9.1 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/README.md +20 -0
- data/lib/centurion/deploy_dsl.rb +1 -1
- data/lib/centurion/service.rb +5 -1
- data/lib/centurion/version.rb +1 -1
- data/spec/deploy_dsl_spec.rb +6 -3
- data/spec/service_spec.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a616e149340434eb681b993b0fe0503f91dbe0dc
|
4
|
+
data.tar.gz: '096241cce242fff7b357fe942488f044f39b6cb0'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f4a17f93aebad77f2a8c59c8a3ceabe58c11bea7d1d4be7c188c4b0264c95b6390e7a622c388809d1ab3e6621a7c3745351b5098ef54f330dc755cd9fe5500b
|
7
|
+
data.tar.gz: 136b293f1392c85086d25d28fd61fe7523dafeda29598703c4d37b0c70680fce848a9d56b7be09e592220f6aa9aad9d1b2b8d17ca213cdf3dd2eae1d56b7e642
|
data/.travis.yml
CHANGED
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
|
data/lib/centurion/deploy_dsl.rb
CHANGED
@@ -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
|
data/lib/centurion/service.rb
CHANGED
@@ -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
|
-
|
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
|
|
data/lib/centurion/version.rb
CHANGED
data/spec/deploy_dsl_spec.rb
CHANGED
@@ -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,
|
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
|
|
data/spec/service_spec.rb
CHANGED
@@ -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.
|
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-
|
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.
|
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
|