conan_deploy 0.0.9 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/conan +39 -21
- data/lib/conan/application.rb +164 -0
- data/lib/conan/application_helper.rb +2 -1
- data/lib/conan/deploy.rb +12 -10
- data/lib/conan/deployment.rb +93 -0
- data/lib/conan/environment.rb +24 -0
- data/lib/conan/has_options.rb +15 -0
- data/lib/conan/jvm_app.rb +16 -0
- data/lib/conan/manifest.rb +120 -0
- data/lib/conan/manifest_builder.rb +3 -530
- data/lib/conan/output.rb +24 -24
- data/lib/conan/pipeline.rb +130 -0
- data/lib/conan/rails_zip_app.rb +10 -0
- data/lib/conan/stackato.rb +65 -11
- data/lib/conan/version.rb +2 -2
- metadata +18 -6
- checksums.yaml +0 -15
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'conan/application'
|
2
|
+
class JvmApp < Application
|
3
|
+
attr_accessor :sha1, :artifact_repo
|
4
|
+
|
5
|
+
def initialize(id, project_name, artifact_repo, options, url_segment=nil)
|
6
|
+
super(id, project_name, :jvm, options, url_segment)
|
7
|
+
@sha1 = nil
|
8
|
+
@artifact_repo = artifact_repo
|
9
|
+
end
|
10
|
+
|
11
|
+
def download(location)
|
12
|
+
super
|
13
|
+
puts "- Provision NewRelic Agent jar"
|
14
|
+
@artifact_repo.downloadNewRelicAgent(File.join(location, @artifact_id), '3.2.3', 'c07cd82e033af9628cd7f90df874daee7000e471')
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
class Manifest
|
2
|
+
|
3
|
+
def initialize(options, artifact_repo, output)
|
4
|
+
@pipelines = {}
|
5
|
+
@environments = {}
|
6
|
+
@options = options
|
7
|
+
@artifact_repo = artifact_repo
|
8
|
+
@output = output
|
9
|
+
end
|
10
|
+
|
11
|
+
# select a pipeline and environment to do operations on
|
12
|
+
def select(pipeline_id, env_id)
|
13
|
+
env = @environments[env_id]
|
14
|
+
raise ArgumentError.new "Invalid environment id: '#{env_id}'. Valid options are #{@environments.keys.join(", ")}" if env.nil?
|
15
|
+
@current_environment = env
|
16
|
+
pl = @pipelines[pipeline_id]
|
17
|
+
raise ArgumentError.new "Invalid pipeline id: '#{pipeline_id}'. Valid options are #{@pipelines.keys.join(", ")}" if pl.nil?
|
18
|
+
@current_pipeline = pl
|
19
|
+
pl.load!(env, @options[:'deploy-shipcloud'])
|
20
|
+
end
|
21
|
+
|
22
|
+
def pipeline(pipeline_id, &block)
|
23
|
+
pl = Pipeline.new(pipeline_id, @artifact_repo, @output, @options)
|
24
|
+
pl.instance_eval(&block)
|
25
|
+
@pipelines[pipeline_id] = pl
|
26
|
+
pl
|
27
|
+
end
|
28
|
+
|
29
|
+
def environment(env_id, &block)
|
30
|
+
e = Environment.new(env_id)
|
31
|
+
e.instance_eval(&block)
|
32
|
+
@environments[env_id] = e
|
33
|
+
e
|
34
|
+
end
|
35
|
+
|
36
|
+
def appVersion(pipeline_id, app_id)
|
37
|
+
@pipelines[pipeline_id].appVersion(app_id)
|
38
|
+
end
|
39
|
+
|
40
|
+
def provision
|
41
|
+
validateThatEnvironmentIsSelected
|
42
|
+
# TODO banners
|
43
|
+
puts "Update #{@current_environment.id} manifest files for #{@current_pipeline.id} pipeline"
|
44
|
+
@current_pipeline.update(@current_environment, @environments[@current_environment.upstream_env])
|
45
|
+
end
|
46
|
+
|
47
|
+
def configure
|
48
|
+
validateThatEnvironmentIsSelected
|
49
|
+
puts "Configure #{@current_environment.id} manifest files for #{@current_pipeline.id} pipeline"
|
50
|
+
@current_pipeline.configure(@current_environment)
|
51
|
+
end
|
52
|
+
|
53
|
+
def bg_configure
|
54
|
+
validateThatEnvironmentIsSelected
|
55
|
+
puts "Blue/green configure #{@current_environment.id} manifest files for #{@current_pipeline.id} pipeline"
|
56
|
+
@current_pipeline.configure(@current_environment, true)
|
57
|
+
end
|
58
|
+
|
59
|
+
def paas
|
60
|
+
paas_user = @options[:'paas-user'] || ENV['PAAS_USER']
|
61
|
+
paas_pwd = @options[:'paas-password'] || ENV['PAAS_PASSWORD']
|
62
|
+
dry_run = @options[:'dry-run'] || false
|
63
|
+
trace = @options[:'verbose'] || false
|
64
|
+
|
65
|
+
Stackato.new(paas_user, paas_pwd, trace, dry_run)
|
66
|
+
end
|
67
|
+
|
68
|
+
def deploy
|
69
|
+
validateThatEnvironmentIsSelected
|
70
|
+
puts "Deploy #{@current_environment.id} for #{@current_pipeline.id} pipeline"
|
71
|
+
|
72
|
+
nr_api_key = @options[:'new-relic-api-key'] || ENV['NEWRELIC_API_KEY']
|
73
|
+
force = @options[:'force-deploy'] || false
|
74
|
+
|
75
|
+
@current_pipeline.deploy(@current_environment, paas, force) { |app_name|
|
76
|
+
if (nr_api_key)
|
77
|
+
puts 'Reporting Deployment to New Relic'
|
78
|
+
job = @options[:'job-url'] || 'nexus-app-manifest'
|
79
|
+
NewRelic.alertDeployment(nr_api_key, app_name, "Deployed by #{job}")
|
80
|
+
else
|
81
|
+
puts "WARNING: Skipping New Relic alert. No API defined"
|
82
|
+
end
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def bg_deploy
|
87
|
+
validateThatEnvironmentIsSelected
|
88
|
+
puts "Blue/green deploy #{@current_environment.id} for #{@current_pipeline.id} pipeline"
|
89
|
+
|
90
|
+
force = @options[:'force-deploy'] || false
|
91
|
+
|
92
|
+
@current_pipeline.bg_deploy(@current_environment, paas, force)
|
93
|
+
end
|
94
|
+
|
95
|
+
def is_inactive_node_operational?
|
96
|
+
validateThatEnvironmentIsSelected
|
97
|
+
puts "Blue/green smoke test #{@current_environment.id} for #{@current_pipeline.id} pipeline"
|
98
|
+
@current_pipeline.is_inactive_node_operational?(@current_environment, paas)
|
99
|
+
end
|
100
|
+
|
101
|
+
def bg_switch
|
102
|
+
validateThatEnvironmentIsSelected
|
103
|
+
puts "Blue/green switch #{@current_environment.id} for #{@current_pipeline.id} pipeline"
|
104
|
+
|
105
|
+
@current_pipeline.bg_switch(@current_environment, paas)
|
106
|
+
end
|
107
|
+
|
108
|
+
def bg_clean
|
109
|
+
validateThatEnvironmentIsSelected
|
110
|
+
puts "Blue/green clean #{@current_environment.id} for #{@current_pipeline.id} pipeline"
|
111
|
+
|
112
|
+
@current_pipeline.bg_clean(@current_environment, paas)
|
113
|
+
end
|
114
|
+
|
115
|
+
def validateThatEnvironmentIsSelected
|
116
|
+
unless @current_environment && @current_pipeline
|
117
|
+
raise ScriptError, 'Environment and Pipeline must be selected'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -1,541 +1,14 @@
|
|
1
|
-
require 'rest_client'
|
2
|
-
require 'rexml/document'
|
3
|
-
require 'json'
|
4
|
-
require 'securerandom'
|
5
|
-
require 'daphne_util'
|
6
|
-
|
7
|
-
require 'conan/output'
|
8
|
-
require 'conan/repository'
|
9
|
-
require 'conan/stackato'
|
10
|
-
require 'conan/newrelic'
|
11
|
-
require 'conan/application_helper'
|
12
|
-
|
13
1
|
module ManifestBuilder
|
14
|
-
def self.build(options,
|
2
|
+
def self.build(options, artifact_repo=nil, outthingy=nil, &block)
|
15
3
|
manifest_dir = options[:directory]
|
16
4
|
output_type = options[:format]
|
17
5
|
|
18
6
|
artifact_repo ||= DefaultArtifactRepository.new
|
19
7
|
outthingy ||= StackatoOutThingy.new(manifest_dir)
|
20
|
-
|
8
|
+
|
21
9
|
manifest = Manifest.new(options, artifact_repo, outthingy)
|
22
10
|
manifest.instance_eval(&block)
|
23
|
-
manifest.select(
|
11
|
+
manifest.select(options[:pipeline], options[:environment])
|
24
12
|
manifest
|
25
13
|
end
|
26
14
|
end
|
27
|
-
|
28
|
-
class Manifest
|
29
|
-
|
30
|
-
def initialize(options, artifact_repo, output)
|
31
|
-
@pipelines = {}
|
32
|
-
@environments = {}
|
33
|
-
@options = options
|
34
|
-
@artifact_repo = artifact_repo
|
35
|
-
@output = output
|
36
|
-
end
|
37
|
-
|
38
|
-
# select a pipeline and environment to do operations on
|
39
|
-
def select(pipeline_id, env_id)
|
40
|
-
env = @environments[env_id]
|
41
|
-
raise ArgumentError.new "Invalid environment id: '#{env_id}'. Valid options are #{@environments.keys.join(", ")}" if env.nil?
|
42
|
-
@current_environment = env
|
43
|
-
pl = @pipelines[pipeline_id]
|
44
|
-
raise ArgumentError.new "Invalid pipeline id: '#{pipeline_id}'. Valid options are #{@pipelines.keys.join(", ")}" if pl.nil?
|
45
|
-
@current_pipeline = pl
|
46
|
-
pl.load!(env, @options[:'deploy-shipcloud'])
|
47
|
-
end
|
48
|
-
|
49
|
-
def pipeline(pipeline_id, &block)
|
50
|
-
pl = Pipeline.new(pipeline_id, @artifact_repo, @output, @options)
|
51
|
-
pl.instance_eval(&block)
|
52
|
-
@pipelines[pipeline_id] = pl
|
53
|
-
pl
|
54
|
-
end
|
55
|
-
|
56
|
-
def environment(env_id, &block)
|
57
|
-
e = Environment.new(env_id)
|
58
|
-
e.instance_eval(&block)
|
59
|
-
@environments[env_id] = e
|
60
|
-
e
|
61
|
-
end
|
62
|
-
|
63
|
-
def appVersion(pipeline_id, app_id)
|
64
|
-
@pipelines[pipeline_id].appVersion(app_id)
|
65
|
-
end
|
66
|
-
|
67
|
-
def provision
|
68
|
-
validateThatEnvironmentIsSelected
|
69
|
-
# TODO banners
|
70
|
-
puts "Update #{@current_environment.id} manifest files for #{@current_pipeline.id} pipeline"
|
71
|
-
@current_pipeline.update(@current_environment, @environments[@current_environment.upstream_env])
|
72
|
-
end
|
73
|
-
|
74
|
-
def configure
|
75
|
-
validateThatEnvironmentIsSelected
|
76
|
-
puts "Configure #{@current_environment.id} manifest files for #{@current_pipeline.id} pipeline"
|
77
|
-
@current_pipeline.configure(@current_environment)
|
78
|
-
end
|
79
|
-
|
80
|
-
def bg_configure
|
81
|
-
validateThatEnvironmentIsSelected
|
82
|
-
puts "Blue/green configure #{@current_environment.id} manifest files for #{@current_pipeline.id} pipeline"
|
83
|
-
@current_pipeline.configure(@current_environment, true)
|
84
|
-
end
|
85
|
-
|
86
|
-
def paas
|
87
|
-
paas_user = @options[:'paas-user'] || ENV['PAAS_USER']
|
88
|
-
paas_pwd = @options[:'paas-password'] || ENV['PAAS_PASSWORD']
|
89
|
-
dry_run = @options[:'dry-run'] || false
|
90
|
-
trace = @options[:'verbose'] || false
|
91
|
-
|
92
|
-
Stackato.new(paas_user, paas_pwd, trace, dry_run)
|
93
|
-
end
|
94
|
-
|
95
|
-
def deploy
|
96
|
-
validateThatEnvironmentIsSelected
|
97
|
-
puts "Deploy #{@current_environment.id} for #{@current_pipeline.id} pipeline"
|
98
|
-
|
99
|
-
nr_api_key = @options[:'new-relic-api-key'] || ENV['NEWRELIC_API_KEY']
|
100
|
-
force = @options[:'force-deploy'] || false
|
101
|
-
|
102
|
-
@current_pipeline.deploy(@current_environment, paas, force) { |app_name|
|
103
|
-
if (nr_api_key)
|
104
|
-
puts 'Reporting Deployment to New Relic'
|
105
|
-
job = @options[:'job-url'] || 'nexus-app-manifest'
|
106
|
-
NewRelic.alertDeployment(nr_api_key, app_name, "Deployed by #{job}")
|
107
|
-
else
|
108
|
-
puts "WARNING: Skipping New Relic alert. No API defined"
|
109
|
-
end
|
110
|
-
}
|
111
|
-
end
|
112
|
-
|
113
|
-
def bg_deploy
|
114
|
-
validateThatEnvironmentIsSelected
|
115
|
-
puts "Blue/green deploy #{@current_environment.id} for #{@current_pipeline.id} pipeline"
|
116
|
-
|
117
|
-
force = @options[:'force-deploy'] || false
|
118
|
-
|
119
|
-
@current_pipeline.bg_deploy(@current_environment, paas, force)
|
120
|
-
end
|
121
|
-
|
122
|
-
def is_inactive_node_operational?
|
123
|
-
validateThatEnvironmentIsSelected
|
124
|
-
puts "Blue/green smoke test #{@current_environment.id} for #{@current_pipeline.id} pipeline"
|
125
|
-
@current_pipeline.is_inactive_node_operational?(@current_environment, paas)
|
126
|
-
end
|
127
|
-
|
128
|
-
def bg_switch
|
129
|
-
validateThatEnvironmentIsSelected
|
130
|
-
puts "Blue/green switch #{@current_environment.id} for #{@current_pipeline.id} pipeline"
|
131
|
-
|
132
|
-
@current_pipeline.bg_switch(@current_environment, paas)
|
133
|
-
end
|
134
|
-
|
135
|
-
def bg_clean
|
136
|
-
validateThatEnvironmentIsSelected
|
137
|
-
puts "Blue/green clean #{@current_environment.id} for #{@current_pipeline.id} pipeline"
|
138
|
-
|
139
|
-
@current_pipeline.bg_clean(@current_environment, paas)
|
140
|
-
end
|
141
|
-
|
142
|
-
def validateThatEnvironmentIsSelected
|
143
|
-
unless @current_environment && @current_pipeline
|
144
|
-
raise ScriptError, 'Environment and Pipeline must be selected'
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
class Pipeline
|
150
|
-
include ApiHelper
|
151
|
-
|
152
|
-
attr_accessor :id, :apps
|
153
|
-
|
154
|
-
def initialize(id, artifact_repo, output, options)
|
155
|
-
@id = id
|
156
|
-
@artifact_repo = artifact_repo
|
157
|
-
@output = output
|
158
|
-
@apps = {}
|
159
|
-
@options = options
|
160
|
-
end
|
161
|
-
|
162
|
-
def app(app_id, project_name, platform_type, url_segment=nil)
|
163
|
-
if (@options[:'deploy-app-name'].nil?) || (@options[:'deploy-app-name'] == app_id.to_s)
|
164
|
-
puts "No app specified, or we matched the specified app: #{@options[:'deploy-app-name']}"
|
165
|
-
@apps[app_id] = case platform_type
|
166
|
-
when :jvm
|
167
|
-
JvmApp.new(app_id, project_name, @artifact_repo, url_segment)
|
168
|
-
when :rails_zip
|
169
|
-
RailsZipApp.new(app_id, project_name, @artifact_repo, url_segment)
|
170
|
-
else
|
171
|
-
raise "unknown platform type: #{platform_type}"
|
172
|
-
end
|
173
|
-
else
|
174
|
-
puts "App #{app_id} doesn't match specified app #{@options[:'deploy-app-name']}, skipping"
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def appVersion(app_id)
|
179
|
-
@apps[app_id].version
|
180
|
-
end
|
181
|
-
|
182
|
-
def load!(environment, deploy_shipcloud)
|
183
|
-
eachAppDeployment(environment) { |app, deploy|
|
184
|
-
# load the persisted meta-data
|
185
|
-
@output.loadAppMetadataFromDeploymentIfExists(app, deploy)
|
186
|
-
}
|
187
|
-
@deploy_shipcloud = deploy_shipcloud
|
188
|
-
end
|
189
|
-
|
190
|
-
def update(environment, from_upstream_env)
|
191
|
-
@apps.values.each { |app|
|
192
|
-
puts ''
|
193
|
-
if !(@options[:'deploy-app-version'].nil?)
|
194
|
-
puts "Using version from options: #{@options[:'deploy-app-version']}"
|
195
|
-
app.findRequestedVersion(@options[:'deploy-app-version'])
|
196
|
-
elsif (from_upstream_env)
|
197
|
-
# promote versions from an upstream deploy
|
198
|
-
# TODO: this needs improving
|
199
|
-
puts "Promote #{app.id} from #{from_upstream_env.id} to #{environment.id}"
|
200
|
-
upstream_deploy = from_upstream_env.deployments.select { |d| d.app_ids.select {|x| x == app.id }.size > 0 }.first
|
201
|
-
@output.loadAppMetadataFromDeployment(app, upstream_deploy)
|
202
|
-
else
|
203
|
-
puts "Find latest #{app.artifact_id}"
|
204
|
-
# lookup most recent from repo
|
205
|
-
app.findRequestedVersion('LATEST')
|
206
|
-
end
|
207
|
-
@output.clean(app, environment)
|
208
|
-
# download artifacts
|
209
|
-
@output.provision(app)
|
210
|
-
}
|
211
|
-
|
212
|
-
# write out deployment artifact meta-data
|
213
|
-
eachAppDeployment(environment) { |app, deploy| @output.writeArtifactMetadata(app, deploy) }
|
214
|
-
end
|
215
|
-
|
216
|
-
def configure(environment, bg=false)
|
217
|
-
eachAppDeployment(environment) { |app, deploy| @output.writeConfiguration(app, deploy, bg) }
|
218
|
-
end
|
219
|
-
|
220
|
-
def deploy(environment, paas, force=false)
|
221
|
-
eachAppDeployment(environment) { |app, deploy|
|
222
|
-
work_dir = @output.workingDir(app)
|
223
|
-
if (force)
|
224
|
-
paas.deploy(work_dir, app, deploy, true)
|
225
|
-
else
|
226
|
-
paas.deploy(work_dir, app, deploy) unless app.isDeployedAt(deploy.manifest_url(app))
|
227
|
-
end
|
228
|
-
}
|
229
|
-
end
|
230
|
-
|
231
|
-
def bg_deploy(environment, paas, force=false)
|
232
|
-
eachAppDeployment(environment) { |app, deploy|
|
233
|
-
if (force or !app.isDeployedAt(deploy.manifest_url(app)))
|
234
|
-
paas.bg_deploy(@output.workingDir(app), app, deploy)
|
235
|
-
end
|
236
|
-
}
|
237
|
-
end
|
238
|
-
|
239
|
-
def is_inactive_node_operational?(environment, paas)
|
240
|
-
eachAppDeployment(environment) { |app, deploy|
|
241
|
-
response = ApiHelper.smoke_test(deploy.inactive_smoke_test_url(app), 60)
|
242
|
-
|
243
|
-
if(response.code != 200)
|
244
|
-
puts "Smoke test failed for inactive (Blue) node. Here is the entire response: #{response.inspect}"
|
245
|
-
return false
|
246
|
-
else
|
247
|
-
return true
|
248
|
-
end
|
249
|
-
}
|
250
|
-
end
|
251
|
-
|
252
|
-
def bg_switch(environment, paas)
|
253
|
-
eachAppDeployment(environment) { |app, deploy| paas.bg_switch(app, deploy) }
|
254
|
-
end
|
255
|
-
|
256
|
-
def bg_clean(environment, paas)
|
257
|
-
eachAppDeployment(environment) { |app, deploy| paas.bg_clean(app, deploy) }
|
258
|
-
end
|
259
|
-
|
260
|
-
def eachAppDeployment(environment)
|
261
|
-
selected_deployments = environment.deployments.select{ |d| @deploy_shipcloud.nil? || d.shipcloud == @deploy_shipcloud }
|
262
|
-
puts "WARNING no deploys selected: #{@deploy_shipcloud}" if selected_deployments.empty?
|
263
|
-
selected_deployments.each { |d|
|
264
|
-
d.app_ids.each { |a|
|
265
|
-
app = @apps[a]
|
266
|
-
yield app, d if app
|
267
|
-
}
|
268
|
-
}
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
class Application
|
273
|
-
|
274
|
-
attr_accessor :id, :platform_type, :group_id, :artifact_id, :version, :extension, :sha1, :artifact_meta_data, :url_segment
|
275
|
-
|
276
|
-
def initialize(id, project_name, platform_type, url_segment=nil)
|
277
|
-
@id = id
|
278
|
-
@platform_type = platform_type
|
279
|
-
@url_segment = url_segment || id
|
280
|
-
mvn_id = project_name.split(':')
|
281
|
-
@group_id = mvn_id[0]
|
282
|
-
@artifact_id = mvn_id[1]
|
283
|
-
end
|
284
|
-
|
285
|
-
def findRequestedVersion(requested_version='LATEST')
|
286
|
-
puts("Finding requested version: #{requested_version}")
|
287
|
-
extension = case platform_type
|
288
|
-
when :jvm
|
289
|
-
"jar"
|
290
|
-
when :rails_zip
|
291
|
-
"tar.gz"
|
292
|
-
else
|
293
|
-
raise "Unsupported platform type: #{platform_type}"
|
294
|
-
end
|
295
|
-
readArtifactMetadata(@artifact_repo.resolveArtifact(group_id, artifact_id, extension, requested_version))
|
296
|
-
puts "- Found version #{version} #{@id} artifact\n"+
|
297
|
-
" Artifact: #{self}\n" +
|
298
|
-
" Checksum: #{@sha1}"
|
299
|
-
end
|
300
|
-
|
301
|
-
def readArtifactMetadata(xml)
|
302
|
-
@artifact_meta_data = xml
|
303
|
-
begin
|
304
|
-
doc = REXML::Document.new(xml)
|
305
|
-
rescue Exception => e
|
306
|
-
puts "Failed to parse meta-data: #{e}"
|
307
|
-
puts "--------------------------------"
|
308
|
-
puts xml
|
309
|
-
puts "--------------------------------"
|
310
|
-
raise "Unreadable artifact meta-data for #{self}"
|
311
|
-
end
|
312
|
-
|
313
|
-
meta_data = doc.elements['/artifact-resolution/data']
|
314
|
-
@version = meta_data.elements['version'].text
|
315
|
-
@sha1 = meta_data.elements['sha1'].text
|
316
|
-
@extension = meta_data.elements['extension'].text
|
317
|
-
end
|
318
|
-
|
319
|
-
def download(location)
|
320
|
-
puts "- Provision #{group_id}:#{artifact_id}:#{extension}:#{version}"
|
321
|
-
@artifact_repo.downloadArtifact(location, group_id, artifact_id, extension, version, sha1)
|
322
|
-
end
|
323
|
-
|
324
|
-
def isDeployedAt(url)
|
325
|
-
# only deploy if an older version is found, or no app found
|
326
|
-
res = false
|
327
|
-
begin
|
328
|
-
response = RestClient::Request.new(
|
329
|
-
:method => :get,
|
330
|
-
:url => url,
|
331
|
-
:headers => {
|
332
|
-
'accept' => :json,
|
333
|
-
'content_type' => :json
|
334
|
-
},
|
335
|
-
:timeout => 5,
|
336
|
-
:open_timeout => 5
|
337
|
-
).execute
|
338
|
-
if (response.code == 200)
|
339
|
-
build_metadata = JSON.parse(response.to_str)
|
340
|
-
puts ''
|
341
|
-
puts "+- Currently at #{url}:"
|
342
|
-
printM = ->(s) {
|
343
|
-
puts " | #{s}: #{build_metadata[s]}"
|
344
|
-
}
|
345
|
-
printM.call 'Implementation-Title'
|
346
|
-
printM.call 'Build-Version'
|
347
|
-
printM.call 'Build-Url'
|
348
|
-
printM.call 'Git-Commit'
|
349
|
-
current_ver = build_metadata["Build-Version"]
|
350
|
-
end
|
351
|
-
#TODO make sure the artifact id matches too, currently finding "Implementation-Title": "apollo" in build metadata
|
352
|
-
if (compareVersion(@version, current_ver))
|
353
|
-
puts "#{@artifact_id} #{@version} is newer than version found at #{url}: #{current_ver}"
|
354
|
-
else
|
355
|
-
puts "#{@artifact_id} #{@version} found at #{url}. (skipping deployment)"
|
356
|
-
res = true
|
357
|
-
end
|
358
|
-
rescue => e
|
359
|
-
puts "#{@artifact_id} not found at #{url}: #{e}"
|
360
|
-
end
|
361
|
-
res
|
362
|
-
end
|
363
|
-
|
364
|
-
|
365
|
-
def compareVersion(target_version, deployed_version)
|
366
|
-
target = Gem::Version.new(target_version)
|
367
|
-
begin
|
368
|
-
found = Gem::Version.new(deployed_version)
|
369
|
-
target > found
|
370
|
-
rescue => e
|
371
|
-
puts "Error parsing version number: #{e}"
|
372
|
-
false
|
373
|
-
end
|
374
|
-
end
|
375
|
-
|
376
|
-
def to_s
|
377
|
-
"#{artifact_id}-#{version}.#{extension}"
|
378
|
-
end
|
379
|
-
end
|
380
|
-
|
381
|
-
class JvmApp < Application
|
382
|
-
attr_accessor :sha1, :artifact_repo
|
383
|
-
|
384
|
-
def initialize(id, project_name, artifact_repo, url_segment=nil)
|
385
|
-
super(id, project_name, :jvm, url_segment)
|
386
|
-
@sha1 = nil
|
387
|
-
@artifact_repo = artifact_repo
|
388
|
-
end
|
389
|
-
|
390
|
-
def download(location)
|
391
|
-
super
|
392
|
-
puts "- Provision NewRelic Agent jar"
|
393
|
-
@artifact_repo.downloadNewRelicAgent(File.join(location, @artifact_id), '3.2.3', 'c07cd82e033af9628cd7f90df874daee7000e471')
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
|
-
class RailsZipApp < Application
|
398
|
-
attr_accessor :sha1, :artifact_repo
|
399
|
-
|
400
|
-
def initialize(id, project_name, artifact_repo, url_segment=nil)
|
401
|
-
super(id, project_name, :rails_zip, url_segment)
|
402
|
-
@sha1 = nil
|
403
|
-
@artifact_repo = artifact_repo
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
class HasOptions
|
408
|
-
attr_accessor :options
|
409
|
-
|
410
|
-
def initialize(options)
|
411
|
-
@options = options
|
412
|
-
end
|
413
|
-
|
414
|
-
def option(key, value)
|
415
|
-
if @options[key].nil?
|
416
|
-
@options[key] = [value]
|
417
|
-
else
|
418
|
-
@options[key] << value
|
419
|
-
end
|
420
|
-
end
|
421
|
-
end
|
422
|
-
|
423
|
-
class Environment #< HasOptions
|
424
|
-
attr_accessor :id, :upstream_env, :deployments
|
425
|
-
|
426
|
-
def initialize(env_id)
|
427
|
-
#super({})
|
428
|
-
@id = env_id
|
429
|
-
@deployments = []
|
430
|
-
@org_holder = nil
|
431
|
-
end
|
432
|
-
|
433
|
-
def promotes_from(env_id)
|
434
|
-
@upstream_env = env_id
|
435
|
-
end
|
436
|
-
|
437
|
-
def org(org_name, &block)
|
438
|
-
@org_holder = org_name
|
439
|
-
self.instance_eval(&block)
|
440
|
-
end
|
441
|
-
|
442
|
-
def deploy(ship, &block)
|
443
|
-
d = Deployment.new(self, @org_holder, ship)
|
444
|
-
d.instance_eval(&block)
|
445
|
-
@deployments << d
|
446
|
-
end
|
447
|
-
end
|
448
|
-
|
449
|
-
class Deployment < HasOptions
|
450
|
-
|
451
|
-
@@paas_domain = 'mtnsatcloud.com'
|
452
|
-
|
453
|
-
attr_accessor :environment, :org, :ship, :shipcloud, :app_ids, :facility_id, :additional_mappings, :custom_smoke_test_path
|
454
|
-
|
455
|
-
def initialize(environment, org, ship)
|
456
|
-
# inherit options from the environment
|
457
|
-
#super(environment.options) # TODO: copy?!
|
458
|
-
super({})
|
459
|
-
@environment = environment
|
460
|
-
@org = org
|
461
|
-
@ship = ship
|
462
|
-
@shipcloud = "#{org}-#{ship}"
|
463
|
-
@app_ids = []
|
464
|
-
@additional_mappings = []
|
465
|
-
@facility_id = nil
|
466
|
-
@enabled = true
|
467
|
-
@randomid = SecureRandom.hex(3)
|
468
|
-
@custom_smoke_test_path = nil
|
469
|
-
end
|
470
|
-
|
471
|
-
def apps(*app_ids)
|
472
|
-
@app_ids = app_ids
|
473
|
-
end
|
474
|
-
|
475
|
-
def facility(facility_id)
|
476
|
-
@facility_id = facility_id
|
477
|
-
end
|
478
|
-
|
479
|
-
def hostnames(*hostnames)
|
480
|
-
hostnames.each do |hostname|
|
481
|
-
@additional_mappings.push(hostname) unless hostname.empty?
|
482
|
-
end
|
483
|
-
end
|
484
|
-
|
485
|
-
def enabled(b)
|
486
|
-
@enabled = b
|
487
|
-
end
|
488
|
-
|
489
|
-
def enabled?
|
490
|
-
@enabled
|
491
|
-
end
|
492
|
-
|
493
|
-
def name(app)
|
494
|
-
"#{app.id}-#{@environment.id}-#{@ship}"
|
495
|
-
end
|
496
|
-
|
497
|
-
def unique_name(app)
|
498
|
-
"#{name(app)}-#{@randomid}"
|
499
|
-
end
|
500
|
-
|
501
|
-
def dns_name(app)
|
502
|
-
"#{@environment.id}.#{app.url_segment}.#{@ship}.#{@org}.#{@@paas_domain}"
|
503
|
-
end
|
504
|
-
|
505
|
-
def agnostic_dns_name(app)
|
506
|
-
"#{@environment.id}.#{app.url_segment}.#{@@paas_domain}"
|
507
|
-
end
|
508
|
-
|
509
|
-
def active_urls(app)
|
510
|
-
[ dns_name(app), agnostic_dns_name(app) ] + @additional_mappings
|
511
|
-
end
|
512
|
-
|
513
|
-
def inactive_urls(app)
|
514
|
-
active_urls(app).map{ |url| "inactive.#{url}" }
|
515
|
-
end
|
516
|
-
|
517
|
-
def manifest_url(app)
|
518
|
-
"http://#{dns_name(app)}/status/manifest"
|
519
|
-
end
|
520
|
-
|
521
|
-
def active_smoke_test_url(app)
|
522
|
-
"http://#{dns_name(app)}/#{@custom_smoke_test_path || 'status/healthcheck'}"
|
523
|
-
end
|
524
|
-
|
525
|
-
def inactive_smoke_test_url(app)
|
526
|
-
"http://inactive.#{dns_name(app)}/#{@custom_smoke_test_path || 'status/healthcheck'}"
|
527
|
-
end
|
528
|
-
|
529
|
-
def paas_target
|
530
|
-
"https://api.paas.#{@ship}.#{@org}.#{@@paas_domain}"
|
531
|
-
end
|
532
|
-
|
533
|
-
def to_s
|
534
|
-
"#{org}-#{ship}"
|
535
|
-
end
|
536
|
-
|
537
|
-
def smoke_test_path(path=nil)
|
538
|
-
@custom_smoke_test_path = path
|
539
|
-
end
|
540
|
-
end
|
541
|
-
|