marathon_deploy 0.1.50 → 0.1.51
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 +4 -4
- data/README.md +8 -0
- data/bin/marathon_deploy +5 -1
- data/examples/CUSTOM_ENV.yml +13 -0
- data/examples/run-with-env-overrides.sh +2 -0
- data/lib/marathon_deploy/application.rb +63 -27
- data/lib/marathon_deploy/marathon_client.rb +5 -1
- data/lib/marathon_deploy/version.rb +1 -1
- data/marathon_deploy.gemspec +1 -0
- data/test/application_test.rb +23 -1
- data/test/fixtures/env/STAGING.yml +14 -0
- data/test/fixtures/env/deploy.yml +25 -0
- metadata +28 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8ec0de90dd1044ab3fb6c745573bd7c581b05cf
|
4
|
+
data.tar.gz: 9acb752923bc76613fb52dc434321ca91e59a131
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fe017f45a353d2facdeb6be31d6242c236cdb4eca9c6dc50774f168a046a42e94bb52f2568cfe2ba828a8e510391fa2ca24fcd7d5e87d89f541463babd68c99
|
7
|
+
data.tar.gz: ed35c7dece6853974fcb02017d3f0264495c488fb807e85f607b535691db3eb18d22ea4856c1973469c237dfd3d4161beb67bf0487460f1df8294c513704aac5
|
data/README.md
CHANGED
@@ -51,6 +51,14 @@ Usage: bin/marathon_deploy [options]
|
|
51
51
|
-e, --environment ENVIRONMENT Default: PREPRODUC
|
52
52
|
```
|
53
53
|
|
54
|
+
### Overriding configuration based on environment
|
55
|
+
By using the `-e <ENVIRONMENT>` switch you can specify a custom environment which can overwrite the settings in the deploy file.
|
56
|
+
For example, setting `-e STAGING` and creating a STAGING.yml or STAGING.json file in the same folder with the deploy file
|
57
|
+
will trigger the overwriting process.
|
58
|
+
|
59
|
+
See `examples/run-with-env-overrides.sh` for a demo of this feature. Here we are specifying different
|
60
|
+
memory settings and appending a custom health-check based on environment.
|
61
|
+
|
54
62
|
### Example Deployfile
|
55
63
|
By default, a file called 'deploy.yml' is searched for in the current directory where deploy.rb is run from. An alternative file name can be provided with the -f parameter.
|
56
64
|
|
data/bin/marathon_deploy
CHANGED
@@ -133,7 +133,11 @@ remove_elements = Array.new
|
|
133
133
|
end
|
134
134
|
|
135
135
|
begin
|
136
|
-
application = MarathonDeploy::Application.new(
|
136
|
+
application = MarathonDeploy::Application.new(
|
137
|
+
:deployfile => deployfile,
|
138
|
+
:environment => environment,
|
139
|
+
:force => options[:force],
|
140
|
+
:remove_elements => remove_elements)
|
137
141
|
rescue MarathonDeploy::Error::IOError, MarathonDeploy::Error::UndefinedMacroError,MarathonDeploy::Error::MissingMarathonAttributesError,MarathonDeploy::Error::UnsupportedFileExtension => e
|
138
142
|
$LOG.debug(e)
|
139
143
|
$LOG.error(e.message)
|
@@ -2,6 +2,7 @@ require 'marathon_deploy/marathon_defaults'
|
|
2
2
|
require 'marathon_deploy/yaml_json'
|
3
3
|
require 'marathon_deploy/error'
|
4
4
|
require 'marathon_deploy/utils'
|
5
|
+
require 'deep_merge'
|
5
6
|
|
6
7
|
module MarathonDeploy
|
7
8
|
|
@@ -13,35 +14,25 @@ module MarathonDeploy
|
|
13
14
|
# @param [Hash] options hash for the application object
|
14
15
|
# @option options [Boolean] :force force a deployment by including an environment variable containing a random string value in the json marathon payload
|
15
16
|
# @option options [String] :deployfile file template and path. default deploy.yml in current directory
|
16
|
-
|
17
|
+
# @option options [MarathonDeploy::Environment] :environment environment specified with -e parameter
|
18
|
+
def initialize(options={
|
19
|
+
:force => false,
|
20
|
+
:deployfile => 'deploy.yml',
|
21
|
+
:remove_elements => [],
|
22
|
+
:environment => nil,
|
23
|
+
})
|
17
24
|
|
18
25
|
deployfile = options[:deployfile]
|
19
|
-
|
20
|
-
if (!File.exist?(deployfile))
|
21
|
-
message = "\'#{File.expand_path(deployfile)}\' not found."
|
22
|
-
raise Error::IOError, message, caller
|
23
|
-
end
|
26
|
+
@json = readFile(deployfile)
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@json = YamlJson.read_json_w_macros(deployfile)
|
30
|
-
when '.yaml','.yml'
|
31
|
-
@json = YamlJson.yaml2json(deployfile)
|
32
|
-
else
|
33
|
-
message = "File extension #{extension} is not supported for deployment file #{deployfile}"
|
34
|
-
raise Error::UnsupportedFileExtension, message, caller
|
35
|
-
end
|
28
|
+
if (!options[:environment].nil?)
|
29
|
+
overrides = env_overrides(
|
30
|
+
File.dirname(deployfile),
|
31
|
+
options[:environment].name)
|
36
32
|
|
37
|
-
|
38
|
-
# marathon require ENV variables to be quoted
|
39
|
-
@json['env'].each do |key, value|
|
40
|
-
if (value.is_a? Numeric)
|
41
|
-
@json['env'][key] = value.to_json
|
42
|
-
end
|
33
|
+
@json = @json.deep_merge!(overrides)
|
43
34
|
end
|
44
|
-
|
35
|
+
|
45
36
|
missing_attributes = MarathonDefaults.missing_attributes(@json)
|
46
37
|
|
47
38
|
if(!missing_attributes.empty?)
|
@@ -69,7 +60,8 @@ module MarathonDeploy
|
|
69
60
|
def overlay_preproduction_settings
|
70
61
|
@json = MarathonDefaults.overlay_preproduction_settings(@json)
|
71
62
|
end
|
72
|
-
|
63
|
+
|
64
|
+
# @return [Array]
|
73
65
|
def health_checks
|
74
66
|
@json[:healthChecks]
|
75
67
|
end
|
@@ -120,7 +112,51 @@ module MarathonDeploy
|
|
120
112
|
|
121
113
|
def instances
|
122
114
|
@json[:instances]
|
123
|
-
end
|
124
|
-
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
def readFile(f)
|
119
|
+
$LOG.debug "Reading file #{f}"
|
120
|
+
if (!File.exist?(f))
|
121
|
+
message = "\'#{File.expand_path(f)}\' not found."
|
122
|
+
raise Error::IOError, message, caller
|
123
|
+
end
|
124
|
+
|
125
|
+
extension = File.extname(f)
|
126
|
+
|
127
|
+
case extension
|
128
|
+
when '.json'
|
129
|
+
json = YamlJson.read_json_w_macros(f)
|
130
|
+
when '.yaml','.yml'
|
131
|
+
json = YamlJson.yaml2json(f)
|
132
|
+
else
|
133
|
+
message = "File extension #{extension} is not supported for deployment file #{f}"
|
134
|
+
raise Error::UnsupportedFileExtension, message, caller
|
135
|
+
end
|
136
|
+
|
137
|
+
# JSON fix for marathon
|
138
|
+
# marathon require ENV variables to be quoted
|
139
|
+
json['env'].each do |key, value|
|
140
|
+
if (value.is_a? Numeric)
|
141
|
+
json['env'][key] = value.to_json
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
return json
|
146
|
+
end
|
147
|
+
|
148
|
+
def env_overrides(dir, env)
|
149
|
+
yml = "#{dir}/#{env}.yml"
|
150
|
+
if (File.exist?(yml))
|
151
|
+
return readFile(yml)
|
152
|
+
end
|
153
|
+
|
154
|
+
json = "#{dir}/#{env}.json"
|
155
|
+
if (File.exist?(json))
|
156
|
+
return readFile(json)
|
157
|
+
end
|
158
|
+
|
159
|
+
return {}
|
160
|
+
end
|
125
161
|
end
|
126
162
|
end
|
@@ -50,7 +50,10 @@ module MarathonDeploy
|
|
50
50
|
end
|
51
51
|
|
52
52
|
if ((300..999).include?(response.code.to_i))
|
53
|
-
|
53
|
+
rspjson = JSON.parse(response.body)
|
54
|
+
$LOG.error('Deployment error: ' + rspjson['message']) if rspjson.has_key?('message')
|
55
|
+
$LOG.error("With details: #{rspjson}")
|
56
|
+
$LOG.error("Deployment response body => " + JSON.pretty_generate(rspjson))
|
54
57
|
raise Error::DeploymentError, "Deployment returned response code #{response.code}", caller
|
55
58
|
end
|
56
59
|
|
@@ -85,4 +88,5 @@ module MarathonDeploy
|
|
85
88
|
end
|
86
89
|
|
87
90
|
end
|
91
|
+
|
88
92
|
end
|
data/marathon_deploy.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.add_dependency "logger"
|
26
26
|
spec.add_dependency "json"
|
27
|
+
spec.add_dependency "deep_merge", '~> 1.0', '>= 1.0.1'
|
27
28
|
|
28
29
|
spec.add_development_dependency "bundler", "~> 1.7"
|
29
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/test/application_test.rb
CHANGED
@@ -43,5 +43,27 @@ class ApplicationTest < Minitest::Test
|
|
43
43
|
refute_nil(app.health_checks, "health checks returned nil")
|
44
44
|
refute_empty(app.health_checks, "health checks returned empty")
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
|
+
def test_overwriting_from_environment_file
|
48
|
+
application = MarathonDeploy::Application.new(
|
49
|
+
:deployfile => File.expand_path('../fixtures/env/deploy.yml', __FILE__),
|
50
|
+
:environment => MarathonDeploy::Environment.new("STAGING")
|
51
|
+
)
|
52
|
+
assert_instance_of(MarathonDeploy::Application,application)
|
53
|
+
refute_empty(application.id)
|
54
|
+
assert_equal(@release_version,application.env[:RELEASE_VERSION])
|
55
|
+
# should stay unchanged since they are not overwritten
|
56
|
+
assert_equal("default-settings-overriden-by-environment-example", application.id)
|
57
|
+
assert_equal("python", application.env[:SERVICE_NAME])
|
58
|
+
# should be overwritten by STAGING.yml
|
59
|
+
assert_equal(16, application.json[:mem])
|
60
|
+
assert_equal(2, application.json[:cpus])
|
61
|
+
assert_equal(5, application.json[:instances])
|
62
|
+
assert_equal("1024m", application.env[:JAVA_XMX])
|
63
|
+
# should be appended from STAGING.yml to already defined health checks
|
64
|
+
assert(application.health_checks.one? { |hc| hc[:path] == "/prod/health/check" }, "new environment-specific health-check should be added")
|
65
|
+
assert(application.health_checks.one? { |hc| hc[:path] == "/default/health/check" }, "default health check should be kept")
|
66
|
+
end
|
67
|
+
|
68
|
+
|
47
69
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
---
|
2
|
+
id: default-settings-overriden-by-environment-example
|
3
|
+
cmd: echo python stable `hostname` > index.html; python3 -m http.server 8080
|
4
|
+
mem: 2
|
5
|
+
cpus: 0.1
|
6
|
+
instances: 1
|
7
|
+
env:
|
8
|
+
SERVICE_TAGS: python,webapp,http,weight=100
|
9
|
+
SERVICE_NAME: python
|
10
|
+
RELEASE_VERSION: %%RELEASE_VERSION%%
|
11
|
+
JAVA_XMX: 256m
|
12
|
+
healthChecks:
|
13
|
+
- portIndex: 0
|
14
|
+
protocol: TCP
|
15
|
+
gracePeriodSeconds: 30
|
16
|
+
intervalSeconds: 10
|
17
|
+
timeoutSeconds: 30
|
18
|
+
maxConsecutiveFailures: 3
|
19
|
+
- path: "/default/health/check"
|
20
|
+
portIndex: 0
|
21
|
+
protocol: HTTP
|
22
|
+
gracePeriodSeconds: 30
|
23
|
+
intervalSeconds: 10
|
24
|
+
timeoutSeconds: 30
|
25
|
+
maxConsecutiveFailures: 3
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marathon_deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.51
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Colby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logger
|
@@ -38,6 +38,26 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: deep_merge
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.0.1
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '1.0'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.0.1
|
41
61
|
- !ruby/object:Gem::Dependency
|
42
62
|
name: bundler
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,12 +183,14 @@ files:
|
|
163
183
|
- doc/js/jquery.js
|
164
184
|
- doc/method_list.html
|
165
185
|
- doc/top-level-namespace.html
|
186
|
+
- examples/CUSTOM_ENV.yml
|
166
187
|
- examples/deploy.json
|
167
188
|
- examples/deploy.yml
|
168
189
|
- examples/jondeploy.yml
|
169
190
|
- examples/jondeploy2.yml
|
170
191
|
- examples/nohealthchecks.yml
|
171
192
|
- examples/public-search-germany-webapp.pre.json
|
193
|
+
- examples/run-with-env-overrides.sh
|
172
194
|
- examples/run.sh
|
173
195
|
- examples/simple-python-example.yml
|
174
196
|
- examples/testout.json
|
@@ -190,6 +212,8 @@ files:
|
|
190
212
|
- test/environment_test.rb
|
191
213
|
- test/fixtures/deploy.json
|
192
214
|
- test/fixtures/deploy.yml
|
215
|
+
- test/fixtures/env/STAGING.yml
|
216
|
+
- test/fixtures/env/deploy.yml
|
193
217
|
- test/fixtures/macros.yml
|
194
218
|
- test/macro_test.rb
|
195
219
|
- test/test_helper.rb
|
@@ -222,6 +246,8 @@ test_files:
|
|
222
246
|
- test/environment_test.rb
|
223
247
|
- test/fixtures/deploy.json
|
224
248
|
- test/fixtures/deploy.yml
|
249
|
+
- test/fixtures/env/STAGING.yml
|
250
|
+
- test/fixtures/env/deploy.yml
|
225
251
|
- test/fixtures/macros.yml
|
226
252
|
- test/macro_test.rb
|
227
253
|
- test/test_helper.rb
|