prima-twig 0.54.44 → 0.54.232

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68c48db5eab64c4ca2fae6bcf92e7d6e6510123813d13688c6cbd3660c217947
4
- data.tar.gz: f0e929753245e1118836587c50bb2520df3233946a187e2d1ab6a3c31c56f1c2
3
+ metadata.gz: afd98e8c8a5420620a68baaab651083aae7d1c571cdbe1cc9d627a18e871b265
4
+ data.tar.gz: 56725194808b56ec07eb842df060b7b64f21eeb6434ac02d7f26ba387bbedd13
5
5
  SHA512:
6
- metadata.gz: edf7533dbd3c635ee5c517c77555c572173a58f71249c1c7f6059bd2d974c81e5abfc311f5fd0e5b0dff3f7d08c0816c51f7e92ec8de0fe824f678597f910dad
7
- data.tar.gz: cd1cdf5a9de3b9d6cd7388f52e6a16b6bca13a4db65031700216f871b65857335afbdfe3121e0186abaeb9aa1831f2dbfd15863b3386a2387ebf44f30d31008d
6
+ metadata.gz: 3b6bfb95a41aee1c2cf84b85f5f5c9087bf80394791cf1dd0bc8f75bc25f2ff0e744e90ed4d52a1a93ec8f4ea3685a198e1bc16911c5d200ea0193853d27ade2
7
+ data.tar.gz: 25f695f38dd3c08be79b759c94319c5049c8737e413ffdbec39c0e9c9e31ee01749155b2ceaf42afa9a4800f5ac4c0a68b616badd26b935974eca712a3b2bd1e
@@ -0,0 +1,2088 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require_relative '../lib/prima_twig.rb'
5
+ require_relative '../lib/prima_aws_client.rb'
6
+ require 'digest'
7
+ require 'json'
8
+ require 'launchy'
9
+ require 'pp'
10
+ require 'redis'
11
+
12
+ class Build
13
+ include Command
14
+ include PrimaAwsClient
15
+
16
+ def initialize()
17
+ @prima = Prima.new
18
+ @batch = Aws::Batch::Client.new
19
+ @s3 = Aws::S3::Client.new
20
+ @s3_bucket = 'prima-artifacts'
21
+ @artifact_path = '/tmp/prima-artifact.zip'
22
+ @import_db_task = 'arn:aws:ecs:eu-west-1:001575623345:task-definition/ecs-task-db-restore2-TaskDefinitionDbRestore-4UBHMCZBE5WM:1'
23
+ @cf_role = 'arn:aws:iam::001575623345:role/qainit-service-role-cloudformat-CloudformationRole-18KBZQIS148R9'
24
+ @ecs_cluster_name = nil
25
+ @deploy_update = false
26
+ @qainit = false
27
+ @qainit_host_folder = "/var/ci/#{ENV['DRONE_REPO']}/#{ENV['DRONE_BRANCH']}/#{ENV['DRONE_BUILD_NUMBER']}"
28
+ @qainit_folder = "/drone/src/github.com/project/primait/qainit"
29
+ @projects = {
30
+ 'prima' => {},
31
+ 'urania' => {},
32
+ 'ermes' => {},
33
+ 'bburago' => {},
34
+ 'hal9000' => {},
35
+ 'fidaty' => {},
36
+ 'peano' => {},
37
+ 'assange' => {},
38
+ 'borat' => {},
39
+ 'crash' => {},
40
+ 'activia' => {},
41
+ 'skynet' => {},
42
+ 'roger' => {},
43
+ 'rachele' => {},
44
+ 'leftorium' => {},
45
+ 'pyxis-npm' => {},
46
+ 'starsky' => {},
47
+ 'hutch' => {},
48
+ 'maia' => {},
49
+ 'legion' => {},
50
+ 'vianello' => {}
51
+ 'domus' => {}
52
+ # 'toretto' => {}
53
+ }
54
+ @base_stack_name_alb = 'ecs-alb-http-public-qa-'
55
+ @base_stack_name_alb_ws = 'ecs-alb-ws-public-qa-'
56
+ @git_branch = ENV['DRONE_BRANCH']
57
+ @cloudflare = Rubyflare.connect_with(ENV['CLOUDFLARE_EMAIL'], ENV['CLOUDFLARE_APIKEY'])
58
+ end
59
+
60
+ def execute!(args)
61
+ qainit_read_config!
62
+ abort('Non sei nella cartella di qainit') unless Dir.pwd.match 'qainit$' or Dir.pwd.match '/drone/src'
63
+ case args[0]
64
+ when 'infrastructure'
65
+ create_infrastructure_stacks! unless is_shutdown?
66
+ when 'project'
67
+ set_tags()
68
+ proj_method = "create_#{args[1]}_stack"
69
+ self.send(proj_method.to_sym) unless is_shutdown?
70
+ when 'complete'
71
+ if is_shutdown?
72
+ output 'Shutting down'.green
73
+ qainit_drone_shutdown!
74
+ else
75
+ complete_qa_setup!
76
+ end
77
+ end
78
+ end
79
+
80
+ def is_shutdown?
81
+ return ENV['DRONE_COMMIT_MESSAGE'] == 'shutdown'
82
+ end
83
+
84
+ def qainit_drone_shutdown!
85
+ output "Recupero le informazioni sui QA attivi..."
86
+ stack_list, envs = get_stacks
87
+
88
+ env_hash = "qa-" + get_deploy_id
89
+
90
+ cluster_stack_name = nil
91
+ stacks_to_delete = []
92
+ stack_list.each do |stack|
93
+ if stack.stack_name.match(/#{env_hash}$/)
94
+ if stack.stack_name.match(/ecs-cluster/)
95
+ cluster_stack_name = stack.stack_name
96
+ else
97
+ break unless stack.stack_name.match(/#{env_hash}$/)
98
+ stacks_to_delete.push(stack.stack_name)
99
+ delete_stack(stack.stack_name)
100
+ end
101
+ end
102
+ end
103
+
104
+ cluster_stack_name = "ecs-cluster-#{env_hash}"
105
+ if stack_exists?(cluster_stack_name)
106
+ aggregator_enabled = get_stack_tags(cluster_stack_name).detect do |tag|
107
+ tag.key === "hostname_pattern_priority" and tag.value === "1"
108
+ end.is_a?(Aws::CloudFormation::Types::Tag)
109
+
110
+ if aggregator_enabled
111
+ dns_to_staging(env_hash)
112
+ end
113
+ end
114
+
115
+ # Se non ha finito di cancellare le altre non si puo' cancellare il cluster
116
+ output "Attendo 10 secondi per poter eliminare il cluster ECS"
117
+
118
+ while stacks_to_delete.length > 0
119
+ sleep 13
120
+ stacks_to_delete.each do |stack_name|
121
+ stacks_to_delete = stacks_to_delete - [stack_name] unless stack_exists?(stack_name)
122
+ end
123
+ output "Stack ancora attivi: #{stacks_to_delete.length.to_s}. Attendo altri 10 secondi per eliminare il cluster ECS"
124
+ end
125
+
126
+ delete_stack(cluster_stack_name) if stack_exists?(cluster_stack_name)
127
+ delete_stack(@base_stack_name_alb + env_hash[3..8]) if stack_exists?(@base_stack_name_alb + env_hash[3..8])
128
+ delete_stack(@base_stack_name_alb_ws + env_hash[3..8]) if stack_exists?(@base_stack_name_alb_ws + env_hash[3..8])
129
+ `git checkout master && git push origin --delete ${DRONE_BRANCH}`
130
+ output "Cancello il record DNS utilizzato da Lighthouse"
131
+ delete_lighthouse_dns()
132
+ output "Finito!".green
133
+
134
+ if @qainit
135
+ qainit_write_output("QA #{ENV["DRONE_BRANCH"]} spento.", 'Indirizzi scritti su ')
136
+ end
137
+ end
138
+
139
+ def qainit_write_output(file_message, output_message)
140
+ `mkdir -p /etc/qainit-output`
141
+ qa_file_name = "/etc/qainit-output/url_qa"
142
+ File.open(qa_file_name + '.txt', 'w') { |file| file.write(file_message) }
143
+ output "#{output_message} #{qa_file_name}".green
144
+ end
145
+
146
+ def qainit_read_config!()
147
+ projects = ''
148
+
149
+ File.open('branch_names', 'r') do |file|
150
+ file.each_line do |line|
151
+ projects = JSON.parse(line)
152
+ end
153
+ end
154
+
155
+ projects.each do |key, project|
156
+ @projects[key] = project
157
+ end
158
+
159
+ get_s3_config_files
160
+ @qainit = true
161
+ end
162
+
163
+ def get_s3_config_files
164
+ # manteniamo la struttura per lanciarlo facilmente anche da locale
165
+ `mkdir -p cloudformation/stacks/task cloudformation/stacks/route53 cloudformation/stacks/asg cloudformation/stacks/elb`
166
+ @s3.get_object({bucket: "prima-deploy", key: 'cloudformation/stacks/task/db.yml', response_target: 'cloudformation/stacks/task/db.yml'})
167
+ @s3.get_object({bucket: "prima-deploy", key: 'cloudformation/stacks/task/otel-agent.yml', response_target: 'cloudformation/stacks/task/otel-agent.yml'})
168
+ @s3.get_object({bucket: "prima-deploy", key: 'cloudformation/stacks/route53/qa.yml', response_target: 'cloudformation/stacks/route53/qa.yml'})
169
+ @s3.get_object({bucket: "prima-deploy", key: 'cloudformation/stacks/asg/ecs-asg-allinone.yml', response_target: 'cloudformation/stacks/asg/ecs-asg-allinone.yml'})
170
+ @s3.get_object({bucket: "prima-deploy", key: 'cloudformation/stacks/ecs-cluster.yml', response_target: 'cloudformation/stacks/ecs-cluster.yml'})
171
+ @s3.get_object({bucket: "prima-deploy", key: 'cloudformation/stacks/elb/alb-public-qa.yml', response_target: 'cloudformation/stacks/elb/alb-public-qa.yml'})
172
+ end
173
+
174
+ def get_deploy_id
175
+ if @deploy_id
176
+ @deploy_id
177
+ else
178
+ @deploy_id = Digest::MD5.hexdigest(ENV['DRONE_BRANCH'])
179
+ @deploy_id
180
+ end
181
+ end
182
+
183
+ def get_ecs_cluster_name
184
+ if @ecs_cluster_name
185
+ @ecs_cluster_name
186
+ else
187
+ cluster_stack_name = "ecs-cluster-qa-#{get_deploy_id}"
188
+ resp = describe_stack_resource(cluster_stack_name, 'ECSCluster')
189
+ @ecs_cluster_name = resp.stack_resource_detail.physical_resource_id
190
+ @ecs_cluster_name
191
+ end
192
+ end
193
+
194
+ def get_asg_stack_name
195
+ "ecs-asg-allinone-qa-#{get_deploy_id}"
196
+ end
197
+
198
+ def get_stack_name(service)
199
+ "ecs-task-#{service}-qa-#{get_deploy_id}"
200
+ end
201
+
202
+ def set_tags()
203
+ @tags = [
204
+ {
205
+ key: "qainit",
206
+ value: @git_branch
207
+ },
208
+ {
209
+ key: "hostname_pattern_priority",
210
+ value: hostname_pattern_priority
211
+ }
212
+ ]
213
+ @projects.each do |key, value|
214
+ @tags << { key: key, value: value['name'] }
215
+ end
216
+ end
217
+
218
+ def create_infrastructure_stacks!
219
+ `git pull && git submodule init && git submodule update`
220
+ @ami_id = get_ami_id("ecs-fleet-allinone-staging")
221
+ deploy_id = get_deploy_id
222
+ stack_name_alb = 'ecs-alb-http-public-qa-' + deploy_id[0..5]
223
+ stack_name_alb_ws = 'ecs-alb-ws-public-qa-' + deploy_id[0..5]
224
+ unless @qainit
225
+ @projects.each_key do |project_key|
226
+ if @projects[project_key]['revision']
227
+ git_checkout_version(project_key, @projects[project_key]['revision'])
228
+ end
229
+ end
230
+ end
231
+ hostname_pattern_priority = hostname_pattern_priority()
232
+
233
+ set_tags()
234
+
235
+ cluster_stack_name = "ecs-cluster-qa-#{deploy_id}"
236
+
237
+ if stack_exists?(cluster_stack_name)
238
+ @tags = get_stack_tags(cluster_stack_name)
239
+ hostname_pattern_priority = @tags.detect do |tag|
240
+ tag.key == 'hostname_pattern_priority'
241
+ end.value
242
+ end
243
+
244
+ create_cluster_stack(cluster_stack_name, @tags) unless stack_exists?(cluster_stack_name)
245
+ wait_for_stack_ready(cluster_stack_name) unless stack_ready?(cluster_stack_name)
246
+
247
+ create_alb_stack(stack_name_alb, "http", deploy_id) unless stack_exists?(stack_name_alb)
248
+ create_alb_stack(stack_name_alb_ws, "websocket", deploy_id) unless stack_exists?(stack_name_alb_ws)
249
+
250
+ create_asg_stack(get_asg_stack_name, @tags) unless stack_exists?(get_asg_stack_name)
251
+
252
+ stack_name_db = "ecs-task-db-qa-#{deploy_id}"
253
+ stack_body = IO.read('cloudformation/stacks/task/db.yml')
254
+ parameters = [
255
+ {
256
+ parameter_key: "Environment",
257
+ parameter_value: "qa"
258
+ },
259
+ {
260
+ parameter_key: "ECSClusterName",
261
+ parameter_value: get_ecs_cluster_name
262
+ }
263
+ ]
264
+ create_stack(stack_name_db, stack_body, parameters, @tags, @cf_role) unless stack_exists?(stack_name_db) # creazione asincrona stack dei db (~4 min)
265
+
266
+ output "check pyxis \n".yellow
267
+
268
+ wait_for_stack_ready(stack_name_db) unless stack_ready?(stack_name_db) # dovrebbe essere istantaneo
269
+ db_task = ''
270
+ db_task = import_dbs(get_ec2_ip_address) unless stack_exists?("ecs-route53-qa-#{deploy_id}") # import asincrono dei dati
271
+
272
+ wait_for_db_import(db_task) unless stack_exists?("ecs-route53-qa-#{deploy_id}") # dovrebbe essere istantaneo
273
+
274
+ import_redis_crash(get_ec2_ip_address) if !stack_exists?("ecs-task-web-qa-#{deploy_id}")
275
+
276
+ wait_for_stack_ready(stack_name_alb) unless stack_ready?(stack_name_alb)
277
+ wait_for_stack_ready(stack_name_alb_ws) unless stack_ready?(stack_name_alb_ws)
278
+
279
+ stack_name_route53 = "ecs-route53-qa-#{deploy_id}"
280
+ stack_body = IO.read('cloudformation/stacks/route53/qa.yml')
281
+ parameters = [
282
+ {
283
+ parameter_key: "DnsRecordIdentifier",
284
+ parameter_value: get_deploy_id
285
+ },
286
+ {
287
+ parameter_key: "PrimaElbHostname",
288
+ parameter_value: get_alb_host(stack_name_alb)
289
+ },
290
+ {
291
+ parameter_key: "UraniaIp",
292
+ parameter_value: get_ec2_ip_address
293
+ },
294
+ {
295
+ parameter_key: "BburagoIp",
296
+ parameter_value: get_ec2_ip_address
297
+ },
298
+ {
299
+ parameter_key: "Hal9000Ip",
300
+ parameter_value: get_ec2_ip_address
301
+ },
302
+ {
303
+ parameter_key: "FidatyIp",
304
+ parameter_value: get_ec2_ip_address
305
+ },
306
+ {
307
+ parameter_key: "PeanoIp",
308
+ parameter_value: get_ec2_ip_address
309
+ },
310
+ {
311
+ parameter_key: "ErmesIp",
312
+ parameter_value: get_ec2_ip_address
313
+ },
314
+ {
315
+ parameter_key: "ActiviaIp",
316
+ parameter_value: get_ec2_ip_address
317
+ },
318
+ {
319
+ parameter_key: "SkynetIp",
320
+ parameter_value: get_ec2_ip_address
321
+ },
322
+ {
323
+ parameter_key: "RogerIp",
324
+ parameter_value: get_ec2_ip_address
325
+ },
326
+ {
327
+ parameter_key: "LeftoriumIp",
328
+ parameter_value: get_ec2_ip_address
329
+ },
330
+ {
331
+ parameter_key: "RacheleIp",
332
+ parameter_value: get_ec2_ip_address
333
+ },
334
+ {
335
+ parameter_key: "RedisIp",
336
+ parameter_value: get_ec2_ip_address
337
+ },
338
+ {
339
+ parameter_key: "LegionIp",
340
+ parameter_value: get_ec2_ip_address
341
+ },
342
+ {
343
+ parameter_key: "AssangeElbHostname",
344
+ parameter_value: get_alb_host(stack_name_alb)
345
+ },
346
+ {
347
+ parameter_key: "BoratElbHostname",
348
+ parameter_value: get_alb_host(stack_name_alb_ws)
349
+ },
350
+ {
351
+ parameter_key: 'CrashElbHostname',
352
+ parameter_value: get_alb_host(stack_name_alb_ws)
353
+ },
354
+ {
355
+ parameter_key: 'StarskyElbHostname',
356
+ parameter_value: get_alb_host(stack_name_alb)
357
+ },
358
+ {
359
+ parameter_key: 'HutchElbHostname',
360
+ parameter_value: get_alb_host(stack_name_alb)
361
+ },
362
+ {
363
+ parameter_key: 'MaiaElbHostname',
364
+ parameter_value: get_alb_host(stack_name_alb)
365
+ },
366
+ {
367
+ parameter_key: 'VianelloElbHostname',
368
+ parameter_value: get_alb_host(stack_name_alb)
369
+ }
370
+ ]
371
+
372
+ create_stack(stack_name_route53, stack_body, parameters, @tags, @cf_role) unless stack_exists?(stack_name_route53)
373
+ wait_for_stack_ready(stack_name_route53) unless stack_ready?(stack_name_route53)
374
+
375
+ stack_name_otel_agent = "ecs-task-otel-agent-qa-#{deploy_id}"
376
+ stack_body = IO.read('cloudformation/stacks/task/otel-agent.yml')
377
+ parameters = [
378
+ {
379
+ parameter_key: "Environment",
380
+ parameter_value: "qa"
381
+ },
382
+ {
383
+ parameter_key: "ClusterId",
384
+ parameter_value: get_ecs_cluster_name
385
+ },
386
+ {
387
+ parameter_key: "ConfigVersion",
388
+ parameter_value: "3.7.0"
389
+ }
390
+ ]
391
+ create_stack(stack_name_otel_agent, stack_body, parameters, @tags, @cf_role) unless stack_exists?(stack_name_otel_agent)
392
+ end
393
+
394
+ def create_skynet_stack()
395
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/skynet/#{@projects["skynet"]['revision']}-qa.tar.gz")
396
+ stack_name_skynet = get_stack_name("skynet")
397
+ git_checkout_version('skynet', @projects["skynet"]['revision'])
398
+ stack_body = File.read('projects/skynet/deploy/task.yml')
399
+ parameters = [
400
+ {
401
+ parameter_key: "Environment",
402
+ parameter_value: "qa"
403
+ },
404
+ {
405
+ parameter_key: "ReleaseVersion",
406
+ parameter_value: @projects["skynet"]['revision']
407
+ },
408
+ {
409
+ parameter_key: "TaskDesiredCount",
410
+ parameter_value: "1"
411
+ },
412
+ {
413
+ parameter_key: "ECSClusterName",
414
+ parameter_value: get_ecs_cluster_name
415
+ },
416
+ {
417
+ parameter_key: "HostnamePattern",
418
+ parameter_value: "skynet-#{get_deploy_id}.qa.colaster.com"
419
+ },
420
+ {
421
+ parameter_key: "HostnamePatternPriority",
422
+ parameter_value: hostname_pattern_priority
423
+ }
424
+ ]
425
+ if stack_exists?(stack_name_skynet)
426
+ cur_version = get_currently_deployed_version(stack_name_skynet)
427
+ update_stack(stack_name_skynet, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["skynet"]['revision'])
428
+ else
429
+ create_stack(stack_name_skynet, stack_body, parameters, @tags, @cf_role)
430
+ end
431
+ end
432
+
433
+ def create_legion_stack()
434
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/legion/#{@projects["legion"]['revision']}-qa.tar.gz")
435
+ stack_name_legion = get_stack_name("legion")
436
+ git_checkout_version('legion', @projects["legion"]['revision'])
437
+ stack_body = File.read('projects/legion/deploy/task.yml')
438
+ parameters = [
439
+ {
440
+ parameter_key: "Environment",
441
+ parameter_value: "qa"
442
+ },
443
+ {
444
+ parameter_key: "ReleaseVersion",
445
+ parameter_value: @projects["legion"]['revision']
446
+ },
447
+ {
448
+ parameter_key: "TaskDesiredCount",
449
+ parameter_value: "1"
450
+ },
451
+ {
452
+ parameter_key: "ECSClusterName",
453
+ parameter_value: get_ecs_cluster_name
454
+ },
455
+ {
456
+ parameter_key: "HostnamePattern",
457
+ parameter_value: "legion-#{get_deploy_id}.qa.colaster.com"
458
+ },
459
+ {
460
+ parameter_key: "HostnamePatternPriority",
461
+ parameter_value: hostname_pattern_priority
462
+ }
463
+ ]
464
+ if stack_exists?(stack_name_legion)
465
+ cur_version = get_currently_deployed_version(stack_name_legion)
466
+ update_stack(stack_name_legion, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["legion"]['revision'])
467
+ else
468
+ create_stack(stack_name_legion, stack_body, parameters, @tags, @cf_role)
469
+ end
470
+ end
471
+
472
+ def create_urania_stack()
473
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/urania/#{@projects["urania"]['revision']}-qa.tar.gz")
474
+ stack_name_urania = get_stack_name("urania")
475
+ git_checkout_version('urania', @projects["urania"]['revision'])
476
+ stack_body = File.read('projects/urania/deploy/task.yml')
477
+ parameters = [
478
+ {
479
+ parameter_key: "Environment",
480
+ parameter_value: "qa"
481
+ },
482
+ {
483
+ parameter_key: "ReleaseVersion",
484
+ parameter_value: @projects["urania"]['revision']
485
+ },
486
+ {
487
+ parameter_key: "TaskDesiredCount",
488
+ parameter_value: "1"
489
+ },
490
+ {
491
+ parameter_key: "ECSClusterName",
492
+ parameter_value: get_ecs_cluster_name
493
+ },
494
+ {
495
+ parameter_key: "HostnamePattern",
496
+ parameter_value: "urania-#{get_deploy_id}.qa.colaster.com"
497
+ },
498
+ {
499
+ parameter_key: "HostnamePatternPriority",
500
+ parameter_value: hostname_pattern_priority
501
+ }
502
+ ]
503
+ if stack_exists?(stack_name_urania)
504
+ cur_version = get_currently_deployed_version(stack_name_urania)
505
+ update_stack(stack_name_urania, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["urania"]['revision'])
506
+ else
507
+ create_stack(stack_name_urania, stack_body, parameters, @tags, @cf_role)
508
+ end
509
+ end
510
+
511
+ def create_ermes_stack()
512
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/ermes/#{@projects["ermes"]['revision']}-qa.tar.gz")
513
+ stack_name_ermes = get_stack_name("ermes")
514
+ git_checkout_version('ermes', @projects["ermes"]['revision'])
515
+ stack_body = File.read('projects/ermes/deploy/task.yml')
516
+ parameters = [
517
+ {
518
+ parameter_key: "Environment",
519
+ parameter_value: "qa"
520
+ },
521
+ {
522
+ parameter_key: "ReleaseVersion",
523
+ parameter_value: "#{@projects['ermes']['revision']}"
524
+ },
525
+ {
526
+ parameter_key: "TaskDesiredCount",
527
+ parameter_value: "1"
528
+ },
529
+ {
530
+ parameter_key: "ECSClusterName",
531
+ parameter_value: get_ecs_cluster_name
532
+ },
533
+ {
534
+ parameter_key: "HostnamePattern",
535
+ parameter_value: "ermes-#{get_deploy_id}.qa.colaster.com"
536
+ },
537
+ {
538
+ parameter_key: "HostnamePatternPriority",
539
+ parameter_value: hostname_pattern_priority
540
+ },
541
+ {
542
+ parameter_key: "WebHost",
543
+ parameter_value: get_route53_hostname('ecs-task-web-qa-notneeded')
544
+ },
545
+ {
546
+ parameter_key: "PeanoHost",
547
+ parameter_value: get_route53_hostname('ecs-task-peano-qa-notneeded')
548
+ }
549
+ ]
550
+ if stack_exists?(stack_name_ermes)
551
+ cur_version = get_currently_deployed_version(stack_name_ermes)
552
+ update_stack(stack_name_ermes, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["ermes"]['revision'])
553
+ else
554
+ create_stack(stack_name_ermes, stack_body, parameters, @tags, @cf_role)
555
+ end
556
+
557
+ stack_name_ermes = get_stack_name("worker-ermes")
558
+ stack_body = File.read('projects/ermes/deploy/task-worker.yml')
559
+ parameters = [
560
+ {
561
+ parameter_key: "Environment",
562
+ parameter_value: "qa"
563
+ },
564
+ {
565
+ parameter_key: "ReleaseVersion",
566
+ parameter_value: "#{@projects['ermes']['revision']}"
567
+ },
568
+ {
569
+ parameter_key: "TaskDesiredCount",
570
+ parameter_value: "1"
571
+ },
572
+ {
573
+ parameter_key: "ECSClusterName",
574
+ parameter_value: get_ecs_cluster_name
575
+ },
576
+ {
577
+ parameter_key: "WebHost",
578
+ parameter_value: get_route53_hostname('ecs-task-web-qa-notneeded')
579
+ },
580
+ {
581
+ parameter_key: "PeanoHost",
582
+ parameter_value: get_route53_hostname('ecs-task-peano-qa-notneeded')
583
+ }
584
+ ]
585
+ if stack_exists?(stack_name_ermes)
586
+ cur_version = get_currently_deployed_version(stack_name_ermes)
587
+ update_stack(stack_name_ermes, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["ermes"]['revision'])
588
+ else
589
+ create_stack(stack_name_ermes, stack_body, parameters, @tags, @cf_role)
590
+ end
591
+ end
592
+
593
+ def create_bburago_stack()
594
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/bburago/#{@projects["bburago"]['revision']}-qa.tar.gz")
595
+
596
+ stack_name_bburago = get_stack_name("bburago")
597
+ git_checkout_version('bburago', @projects["bburago"]['revision'])
598
+ stack_body = File.read('projects/bburago/deploy/task.yml')
599
+ parameters = [
600
+ {
601
+ parameter_key: "Environment",
602
+ parameter_value: "qa"
603
+ },
604
+ {
605
+ parameter_key: "ReleaseVersion",
606
+ parameter_value: @projects["bburago"]['revision']
607
+ },
608
+ {
609
+ parameter_key: "ECSClusterName",
610
+ parameter_value: get_ecs_cluster_name
611
+ },
612
+ {
613
+ parameter_key: "TaskDesiredCount",
614
+ parameter_value: "1"
615
+ },
616
+ {
617
+ parameter_key: "HostnamePattern",
618
+ parameter_value: "bburago-#{get_deploy_id}.qa.colaster.com"
619
+ },
620
+ {
621
+ parameter_key: "HostnamePatternPriority",
622
+ parameter_value: hostname_pattern_priority
623
+ }
624
+ ]
625
+ if stack_exists?(stack_name_bburago)
626
+ cur_version = get_currently_deployed_version(stack_name_bburago)
627
+ update_stack(stack_name_bburago, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["bburago"]['revision'])
628
+ else
629
+ create_stack(stack_name_bburago, stack_body, parameters, @tags, @cf_role)
630
+ end
631
+ end
632
+
633
+ def create_hal9000_stack()
634
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/hal9000/#{@projects["hal9000"]['revision']}-qa.tar.gz")
635
+
636
+ stack_name_hal9000 = get_stack_name("hal9000")
637
+ git_checkout_version('hal9000', @projects["hal9000"]['revision'])
638
+ stack_body = File.read('projects/hal9000/deploy/task.yml')
639
+ parameters = [
640
+ {
641
+ parameter_key: "Environment",
642
+ parameter_value: "qa"
643
+ },
644
+ {
645
+ parameter_key: "ReleaseVersion",
646
+ parameter_value: @projects["hal9000"]['revision']
647
+ },
648
+ {
649
+ parameter_key: "ECSClusterName",
650
+ parameter_value: get_ecs_cluster_name
651
+ },
652
+ {
653
+ parameter_key: "TaskDesiredCount",
654
+ parameter_value: "1"
655
+ },
656
+ {
657
+ parameter_key: "HostnamePattern",
658
+ parameter_value: "hal9000-#{get_deploy_id}.qa.colaster.com"
659
+ },
660
+ {
661
+ parameter_key: "HostnamePatternPriority",
662
+ parameter_value: hostname_pattern_priority
663
+ }
664
+ ]
665
+ if stack_exists?(stack_name_hal9000)
666
+ cur_version = get_currently_deployed_version(stack_name_hal9000)
667
+ update_stack(stack_name_hal9000, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["hal9000"]['revision'])
668
+ else
669
+ create_stack(stack_name_hal9000, stack_body, parameters, @tags, @cf_role)
670
+ end
671
+ end
672
+
673
+ def create_fidaty_stack()
674
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/fidaty/#{@projects["fidaty"]['revision']}-qa.tar.gz")
675
+
676
+ stack_name_fidaty = get_stack_name("fidaty")
677
+ git_checkout_version('fidaty', @projects["fidaty"]['revision'])
678
+ stack_body = File.read('projects/fidaty/deploy/task.yml')
679
+ parameters = [
680
+ {
681
+ parameter_key: "Environment",
682
+ parameter_value: "qa"
683
+ },
684
+ {
685
+ parameter_key: "ReleaseVersion",
686
+ parameter_value: "#{@projects["fidaty"]['revision']}"
687
+ },
688
+ {
689
+ parameter_key: "ECSClusterName",
690
+ parameter_value: get_ecs_cluster_name
691
+ },
692
+ {
693
+ parameter_key: "TaskDesiredCount",
694
+ parameter_value: "1"
695
+ },
696
+ {
697
+ parameter_key: "HostnamePattern",
698
+ parameter_value: "fidaty-#{get_deploy_id}.qa.colaster.com"
699
+ },
700
+ {
701
+ parameter_key: "HostnamePatternPriority",
702
+ parameter_value: hostname_pattern_priority
703
+ },
704
+ {
705
+ parameter_key: "PeanoHost",
706
+ parameter_value: get_route53_hostname("ecs-task-peano-qa-notneeded")
707
+ }
708
+ ]
709
+ if stack_exists?(stack_name_fidaty)
710
+ cur_version = get_currently_deployed_version(stack_name_fidaty)
711
+ update_stack(stack_name_fidaty, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["fidaty"]['revision'])
712
+ else
713
+ create_stack(stack_name_fidaty, stack_body, parameters, @tags, @cf_role)
714
+ end
715
+ end
716
+
717
+ def create_peano_stack()
718
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/peano/#{@projects["peano"]['revision']}-qa.tar.gz")
719
+
720
+ stack_name_peano = get_stack_name("peano")
721
+ git_checkout_version('peano', @projects["peano"]['revision'])
722
+ stack_body = File.read('projects/peano/deploy/task.yml')
723
+ parameters = [
724
+ {
725
+ parameter_key: "Environment",
726
+ parameter_value: "qa"
727
+ },
728
+ {
729
+ parameter_key: "ReleaseVersion",
730
+ parameter_value: "#{@projects['peano']['revision']}"
731
+ },
732
+ {
733
+ parameter_key: "ECSClusterName",
734
+ parameter_value: get_ecs_cluster_name
735
+ },
736
+ {
737
+ parameter_key: "TaskDesiredCount",
738
+ parameter_value: "1"
739
+ },
740
+ {
741
+ parameter_key: "HostnamePattern",
742
+ parameter_value: "peano-#{get_deploy_id}.qa.colaster.com"
743
+ },
744
+ {
745
+ parameter_key: "HostnamePatternPriority",
746
+ parameter_value: hostname_pattern_priority
747
+ },
748
+ {
749
+ parameter_key: "WebHost",
750
+ parameter_value: "www-#{get_deploy_id}.qa.colaster.com"
751
+ }
752
+ ]
753
+ if stack_exists?(stack_name_peano)
754
+ cur_version = get_currently_deployed_version(stack_name_peano)
755
+ update_stack(stack_name_peano, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["peano"]['revision'])
756
+ else
757
+ create_stack(stack_name_peano, stack_body, parameters, @tags, @cf_role)
758
+ end
759
+ end
760
+
761
+ def create_assange_stack()
762
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/assange/#{@projects["assange"]['revision']}-qa.tar.gz")
763
+
764
+ stack_name_assange = get_stack_name("assange")
765
+ git_checkout_version('assange', @projects["assange"]['revision'])
766
+ stack_body = IO.read('projects/assange/deploy/task.yml')
767
+ parameters = [
768
+ {
769
+ parameter_key: "Environment",
770
+ parameter_value: "qa"
771
+ },
772
+ {
773
+ parameter_key: "ReleaseVersion",
774
+ parameter_value: "#{@projects["assange"]['revision']}"
775
+ },
776
+ {
777
+ parameter_key: "ECSClusterName",
778
+ parameter_value: get_ecs_cluster_name
779
+ },
780
+ {
781
+ parameter_key: "TaskDesiredCount",
782
+ parameter_value: "1"
783
+ },
784
+ {
785
+ parameter_key: "ALBShortName",
786
+ parameter_value: "assange-qa-#{get_deploy_id}"[0..27]
787
+ },
788
+ {
789
+ parameter_key: "HostnamePattern",
790
+ parameter_value: "assange-#{get_deploy_id}.qa.colaster.com"
791
+ },
792
+ {
793
+ parameter_key: "HostnamePatternPriority",
794
+ parameter_value: (hostname_pattern_priority.to_i + 20).to_s
795
+ },
796
+ {
797
+ parameter_key: "EnvHash",
798
+ parameter_value: get_deploy_id
799
+ },
800
+ {
801
+ parameter_key: "WebHost",
802
+ parameter_value: "www-#{get_deploy_id}.qa.colaster.com"
803
+ },
804
+ {
805
+ parameter_key: "AssangeHost",
806
+ parameter_value: "assange-#{get_deploy_id}.qa.colaster.com"
807
+ }
808
+ ]
809
+ if stack_exists?(stack_name_assange)
810
+ cur_version = get_currently_deployed_version(stack_name_assange)
811
+ update_stack(stack_name_assange, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["assange"]['revision'])
812
+ else
813
+ create_stack(stack_name_assange, stack_body, parameters, @tags, @cf_role)
814
+ end
815
+
816
+ stack_name_assange_worker = get_stack_name("assange-worker")
817
+ git_checkout_version('assange', @projects["assange"]['revision'])
818
+ stack_body = IO.read('projects/assange/deploy/task-worker.yml')
819
+ parameters = [
820
+ {
821
+ parameter_key: "Environment",
822
+ parameter_value: "qa"
823
+ },
824
+ {
825
+ parameter_key: "ReleaseVersion",
826
+ parameter_value: "#{@projects["assange"]['revision']}"
827
+ },
828
+ {
829
+ parameter_key: "ECSClusterName",
830
+ parameter_value: get_ecs_cluster_name
831
+ },
832
+ {
833
+ parameter_key: "TaskDesiredCount",
834
+ parameter_value: "1"
835
+ },
836
+ {
837
+ parameter_key: "WebHost",
838
+ parameter_value: "www-#{get_deploy_id}.qa.colaster.com"
839
+ },
840
+ {
841
+ parameter_key: "AssangeHost",
842
+ parameter_value: "assange-#{get_deploy_id}.qa.colaster.com"
843
+ }
844
+ ]
845
+ if stack_exists?(stack_name_assange_worker)
846
+ cur_version = get_currently_deployed_version(stack_name_assange_worker)
847
+ update_stack(stack_name_assange_worker, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["assange"]['revision'])
848
+ else
849
+ create_stack(stack_name_assange_worker, stack_body, parameters, @tags, @cf_role)
850
+ end
851
+ end
852
+
853
+ def create_leftorium_stack()
854
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/leftorium/#{@projects["leftorium"]['revision']}-qa.tar.gz")
855
+
856
+ stack_name_leftorium = get_stack_name("leftorium")
857
+ git_checkout_version('leftorium', @projects["leftorium"]['revision'])
858
+ stack_body = File.read('projects/leftorium/deploy/task.yml')
859
+ parameters = [
860
+ {
861
+ parameter_key: "Environment",
862
+ parameter_value: "qa"
863
+ },
864
+ {
865
+ parameter_key: "ReleaseVersion",
866
+ parameter_value: "#{@projects["leftorium"]['revision']}"
867
+ },
868
+ {
869
+ parameter_key: "ECSClusterName",
870
+ parameter_value: get_ecs_cluster_name
871
+ },
872
+ {
873
+ parameter_key: "TaskDesiredCount",
874
+ parameter_value: "1"
875
+ },
876
+ {
877
+ parameter_key: "HostnamePattern",
878
+ parameter_value: "leftorium-#{get_deploy_id}.qa.colaster.com"
879
+ },
880
+ {
881
+ parameter_key: "HostnamePatternPriority",
882
+ parameter_value: hostname_pattern_priority
883
+ }
884
+ ]
885
+ if stack_exists?(stack_name_leftorium)
886
+ cur_version = get_currently_deployed_version(stack_name_leftorium)
887
+ update_stack(stack_name_leftorium, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["leftorium"]['revision'])
888
+ else
889
+ create_stack(stack_name_leftorium, stack_body, parameters, @tags, @cf_role)
890
+ end
891
+ end
892
+
893
+ def create_rachele_stack()
894
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/rachele/#{@projects["rachele"]['revision']}-qa.tar.gz")
895
+
896
+ stack_name_rachele = get_stack_name("rachele")
897
+ git_checkout_version('rachele', @projects["rachele"]['revision'])
898
+ stack_body = File.read('projects/rachele/deploy/task.yml')
899
+ parameters = [
900
+ {
901
+ parameter_key: "Environment",
902
+ parameter_value: "qa"
903
+ },
904
+ {
905
+ parameter_key: "ReleaseVersion",
906
+ parameter_value: "#{@projects["rachele"]['revision']}"
907
+ },
908
+ {
909
+ parameter_key: "ECSClusterName",
910
+ parameter_value: get_ecs_cluster_name
911
+ },
912
+ {
913
+ parameter_key: "TaskDesiredCount",
914
+ parameter_value: "1"
915
+ },
916
+ {
917
+ parameter_key: "EnvHash",
918
+ parameter_value: get_deploy_id
919
+ },
920
+ {
921
+ parameter_key: "WebHost",
922
+ parameter_value: "www-#{get_deploy_id}.qa.colaster.com"
923
+ },
924
+ {
925
+ parameter_key: "HostnamePattern",
926
+ parameter_value: "rachele-#{get_deploy_id}.qa.colaster.com"
927
+ },
928
+ {
929
+ parameter_key: "HostnamePatternPriority",
930
+ parameter_value: hostname_pattern_priority
931
+ }
932
+ ]
933
+ if stack_exists?(stack_name_rachele)
934
+ cur_version = get_currently_deployed_version(stack_name_rachele)
935
+ unless cur_version.include?(@projects["rachele"]['revision'])
936
+ delete_stack(stack_name_rachele)
937
+ wait_for_stack_removal(stack_name_rachele)
938
+ create_stack(stack_name_rachele, stack_body, parameters, @tags, @cf_role)
939
+ end
940
+ else
941
+ create_stack(stack_name_rachele, stack_body, parameters, @tags, @cf_role)
942
+ end
943
+ end
944
+
945
+ def create_borat_stack()
946
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/borat/#{@projects["borat"]['revision']}-qa.tar.gz")
947
+
948
+ stack_name_borat = get_stack_name("borat")
949
+ git_checkout_version('borat', @projects["borat"]['revision'])
950
+ stack_body = IO.read('projects/borat/deploy/task.yml')
951
+ parameters = [
952
+ {
953
+ parameter_key: "Environment",
954
+ parameter_value: "qa"
955
+ },
956
+ {
957
+ parameter_key: "ReleaseVersion",
958
+ parameter_value: "#{@projects["borat"]['revision']}"
959
+ },
960
+ {
961
+ parameter_key: "ECSClusterName",
962
+ parameter_value: get_ecs_cluster_name
963
+ },
964
+ {
965
+ parameter_key: "TaskDesiredCount",
966
+ parameter_value: "1"
967
+ },
968
+ {
969
+ parameter_key: "ALBShortName",
970
+ parameter_value: "borat-qa-#{get_deploy_id}"[0..27]
971
+ },
972
+ {
973
+ parameter_key: "HostnamePattern",
974
+ parameter_value: "backoffice-#{get_deploy_id}.qa.colaster.com"
975
+ },
976
+ {
977
+ parameter_key: "HostnamePatternPriority",
978
+ parameter_value: (hostname_pattern_priority.to_i + 30).to_s
979
+ },
980
+ {
981
+ parameter_key: "EnvHash",
982
+ parameter_value: get_deploy_id
983
+ },
984
+ {
985
+ parameter_key: "WsEndpoint",
986
+ parameter_value: "wss://backoffice-#{get_deploy_id}.qa.colaster.com/socket/websocket?vsn=1.0.0"
987
+ },
988
+ {
989
+ parameter_key: "GraphqlEndpoint",
990
+ parameter_value: "https://backoffice-#{get_deploy_id}.qa.colaster.com/graphql"
991
+ },
992
+ {
993
+ parameter_key: "GraphqlInsuranceEndpoint",
994
+ parameter_value: "https://backoffice-#{get_deploy_id}.qa.colaster.com/graphql/insurance"
995
+ },
996
+ {
997
+ parameter_key: "AuthEndpoint",
998
+ parameter_value: "https://backoffice-#{get_deploy_id}.qa.colaster.com/auth"
999
+ },
1000
+ {
1001
+ parameter_key: "FrontendEndpoint",
1002
+ parameter_value: "https://www-#{get_deploy_id}.qa.colaster.com/"
1003
+ }
1004
+ ]
1005
+ if stack_exists?(stack_name_borat)
1006
+ cur_version = get_currently_deployed_version(stack_name_borat)
1007
+ update_stack(stack_name_borat, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["borat"]['revision'])
1008
+ else
1009
+ create_stack(stack_name_borat, stack_body, parameters, @tags, @cf_role)
1010
+ end
1011
+ end
1012
+
1013
+ def create_crash_stack()
1014
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/crash/#{@projects['crash']['revision']}-qa.tar.gz")
1015
+
1016
+ stack_name_crash = get_stack_name("crash")
1017
+ git_checkout_version('crash', @projects['crash']['revision'])
1018
+ stack_body = IO.read('projects/crash/deploy/task.yml')
1019
+ parameters = [
1020
+ {
1021
+ parameter_key: 'Environment',
1022
+ parameter_value: 'qa'
1023
+ },
1024
+ {
1025
+ parameter_key: 'ReleaseVersion',
1026
+ parameter_value: "#{@projects['crash']['revision']}"
1027
+ },
1028
+ {
1029
+ parameter_key: 'TaskDesiredCount',
1030
+ parameter_value: '1'
1031
+ },
1032
+ {
1033
+ parameter_key: 'ECSClusterName',
1034
+ parameter_value: get_ecs_cluster_name
1035
+ },
1036
+ {
1037
+ parameter_key: 'ALBShortName',
1038
+ parameter_value: "crash-qa-#{get_deploy_id}"[0..27]
1039
+ },
1040
+ {
1041
+ parameter_key: 'HostnamePattern',
1042
+ parameter_value: "crash-#{get_deploy_id}.qa.colaster.com"
1043
+ },
1044
+ {
1045
+ parameter_key: 'HostnamePatternPriority',
1046
+ parameter_value: (hostname_pattern_priority.to_i + 10).to_s
1047
+ },
1048
+ {
1049
+ parameter_key: "EnvHash",
1050
+ parameter_value: get_deploy_id
1051
+ },
1052
+ {
1053
+ parameter_key: "WsEndpoint",
1054
+ parameter_value: "wss://crash-#{get_deploy_id}.qa.colaster.com/socket/websocket?vsn=1.0.0"
1055
+ },
1056
+ {
1057
+ parameter_key: "GraphqlEndpoint",
1058
+ parameter_value: "https://crash-#{get_deploy_id}.qa.colaster.com/graphql"
1059
+ },
1060
+ {
1061
+ parameter_key: "AuthDomain",
1062
+ parameter_value: "https://www-#{get_deploy_id}.qa.colaster.com/"
1063
+ },
1064
+ ]
1065
+ if stack_exists?(stack_name_crash)
1066
+ cur_version = get_currently_deployed_version(stack_name_crash)
1067
+ update_stack(stack_name_crash, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["crash"]['revision'])
1068
+ else
1069
+ create_stack(stack_name_crash, stack_body, parameters, @tags, @cf_role)
1070
+ end
1071
+ end
1072
+
1073
+ def create_starsky_stack()
1074
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/starsky/#{@projects["starsky"]['revision']}-qa.tar.gz")
1075
+
1076
+ git_checkout_version('starsky', @projects["starsky"]['revision'])
1077
+ stack_name_starsky = get_stack_name("starsky")
1078
+ stack_body = IO.read('projects/starsky/deploy/task.yml')
1079
+ parameters = [
1080
+ {
1081
+ parameter_key: "Environment",
1082
+ parameter_value: "qa"
1083
+ },
1084
+ {
1085
+ parameter_key: "ReleaseVersion",
1086
+ parameter_value: "#{@projects["starsky"]['revision']}"
1087
+ },
1088
+ {
1089
+ parameter_key: "TaskDesiredCount",
1090
+ parameter_value: "1"
1091
+ },
1092
+ {
1093
+ parameter_key: "ECSClusterName",
1094
+ parameter_value: get_ecs_cluster_name
1095
+ },
1096
+ {
1097
+ parameter_key: "ALBShortName",
1098
+ parameter_value: "starsky-qa-#{get_deploy_id}"[0..27]
1099
+ },
1100
+ {
1101
+ parameter_key: "EnvHash",
1102
+ parameter_value: get_deploy_id
1103
+ },
1104
+ {
1105
+ parameter_key: "HostnamePattern",
1106
+ parameter_value: "starsky-#{get_deploy_id}.qa.colaster.com"
1107
+ },
1108
+ {
1109
+ parameter_key: "HostnamePatternPriority",
1110
+ parameter_value: (hostname_pattern_priority.to_i + 74).to_s
1111
+ }
1112
+ ]
1113
+ if stack_exists?(stack_name_starsky)
1114
+ cur_version = get_currently_deployed_version(stack_name_starsky)
1115
+ unless cur_version.include?(@projects["starsky"]['revision'])
1116
+ delete_stack(stack_name_starsky)
1117
+ wait_for_stack_removal(stack_name_starsky)
1118
+ create_stack(stack_name_starsky, stack_body, parameters, @tags, @cf_role)
1119
+ end
1120
+ else
1121
+ create_stack(stack_name_starsky, stack_body, parameters, @tags, @cf_role)
1122
+ end
1123
+ end
1124
+
1125
+ def create_activia_stack()
1126
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/activia/#{@projects["activia"]['revision']}-qa.tar.gz")
1127
+
1128
+ stack_name_activia = get_stack_name("activia")
1129
+ git_checkout_version('activia', @projects["activia"]['revision'])
1130
+ stack_body = File.read('projects/activia/deploy/task.yml')
1131
+ parameters = [
1132
+ {
1133
+ parameter_key: "Environment",
1134
+ parameter_value: "qa"
1135
+ },
1136
+ {
1137
+ parameter_key: "ReleaseVersion",
1138
+ parameter_value: "#{@projects["activia"]['revision']}"
1139
+ },
1140
+ {
1141
+ parameter_key: "ECSClusterName",
1142
+ parameter_value: get_ecs_cluster_name
1143
+ },
1144
+ {
1145
+ parameter_key: "TaskDesiredCount",
1146
+ parameter_value: "1"
1147
+ },
1148
+ {
1149
+ parameter_key: "HostnamePattern",
1150
+ parameter_value: "activia-#{get_deploy_id}.qa.colaster.com"
1151
+ },
1152
+ {
1153
+ parameter_key: "HostnamePatternPriority",
1154
+ parameter_value: hostname_pattern_priority
1155
+ },
1156
+ {
1157
+ parameter_key: "WebHost",
1158
+ parameter_value: get_route53_hostname('ecs-task-web-qa-notneeded')
1159
+ },
1160
+ {
1161
+ parameter_key: "PeanoHost",
1162
+ parameter_value: get_route53_hostname('ecs-task-peano-qa-notneeded')
1163
+ }
1164
+ ]
1165
+ if stack_exists?(stack_name_activia)
1166
+ cur_version = get_currently_deployed_version(stack_name_activia)
1167
+ update_stack(stack_name_activia, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["activia"]['revision'])
1168
+ else
1169
+ create_stack(stack_name_activia, stack_body, parameters, @tags, @cf_role)
1170
+ end
1171
+ end
1172
+
1173
+ def create_web_stack()
1174
+ wait_for_artifact('prima-artifacts-encrypted', "prima/#{@projects["prima"]['revision']}.tar.gz")
1175
+ # Waiting for prima healtcheck dependencies
1176
+ wait_for_stack_ready(get_stack_name("skynet")) unless stack_ready?(get_stack_name("skynet"))
1177
+ wait_for_stack_ready(get_stack_name("urania")) unless stack_ready?(get_stack_name("urania"))
1178
+ wait_for_stack_ready(get_stack_name("bburago")) unless stack_ready?(get_stack_name("bburago"))
1179
+ wait_for_stack_ready(get_stack_name("hal9000")) unless stack_ready?(get_stack_name("hal9000"))
1180
+ wait_for_stack_ready(get_stack_name("assange")) unless stack_ready?(get_stack_name("assange"))
1181
+ wait_for_stack_ready(get_stack_name("fidaty")) unless stack_ready?(get_stack_name("fidaty"))
1182
+ wait_for_stack_ready(get_stack_name("leftorium")) unless stack_ready?(get_stack_name("leftorium"))
1183
+ wait_for_stack_ready(get_stack_name("rachele")) unless stack_ready?(get_stack_name("rachele"))
1184
+ stack_name_web = get_stack_name("web")
1185
+ git_checkout_version('prima', @projects["prima"]['revision'])
1186
+ stack_body = IO.read('projects/prima/app/cloudformation/tasks/web.yml')
1187
+ parameters = [
1188
+ {
1189
+ parameter_key: "Environment",
1190
+ parameter_value: "qa"
1191
+ },
1192
+ {
1193
+ parameter_key: "ReleaseVersion",
1194
+ parameter_value: "#{@projects["prima"]['revision']}"
1195
+ },
1196
+ {
1197
+ parameter_key: "TaskDesiredCount",
1198
+ parameter_value: "1"
1199
+ },
1200
+ {
1201
+ parameter_key: "ECSClusterName",
1202
+ parameter_value: get_ecs_cluster_name
1203
+ },
1204
+ {
1205
+ parameter_key: "ALBShortName",
1206
+ parameter_value: "web-qa-#{get_deploy_id}"[0..27]
1207
+ },
1208
+ {
1209
+ parameter_key: "HostnamePatternPriority",
1210
+ parameter_value: hostname_pattern_priority
1211
+ },
1212
+ {
1213
+ parameter_key: "HostnamePatternAggregatorPriority",
1214
+ parameter_value: (hostname_pattern_priority.to_i + 1).to_s
1215
+ },
1216
+ {
1217
+ parameter_key: "EnvHash",
1218
+ parameter_value: get_deploy_id
1219
+ },
1220
+ {
1221
+ parameter_key: "HostnamePattern",
1222
+ parameter_value: "www-#{get_deploy_id}.*"
1223
+ }
1224
+ ]
1225
+ if stack_exists?(stack_name_web)
1226
+ cur_version = get_currently_deployed_version(stack_name_web)
1227
+ update_stack(stack_name_web, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["prima"]['revision'])
1228
+ else
1229
+ create_stack(stack_name_web, stack_body, parameters, @tags, @cf_role)
1230
+ end
1231
+ end
1232
+
1233
+ def create_consumer_stack()
1234
+ wait_for_artifact('prima-artifacts-encrypted', "prima/#{@projects["prima"]['revision']}.tar.gz")
1235
+ # Waiting for prima healtcheck dependencies
1236
+ wait_for_stack_ready(get_stack_name("skynet")) unless stack_ready?(get_stack_name("skynet"))
1237
+ wait_for_stack_ready(get_stack_name("urania")) unless stack_ready?(get_stack_name("urania"))
1238
+ wait_for_stack_ready(get_stack_name("bburago")) unless stack_ready?(get_stack_name("bburago"))
1239
+ wait_for_stack_ready(get_stack_name("hal9000")) unless stack_ready?(get_stack_name("hal9000"))
1240
+ wait_for_stack_ready(get_stack_name("assange")) unless stack_ready?(get_stack_name("assange"))
1241
+ wait_for_stack_ready(get_stack_name("fidaty")) unless stack_ready?(get_stack_name("fidaty"))
1242
+ wait_for_stack_ready(get_stack_name("leftorium")) unless stack_ready?(get_stack_name("leftorium"))
1243
+ wait_for_stack_ready(get_stack_name("rachele")) unless stack_ready?(get_stack_name("rachele"))
1244
+ stack_name_consumer = get_stack_name("consumer")
1245
+ git_checkout_version('prima', @projects["prima"]['revision'])
1246
+ stack_body = IO.read('projects/prima/app/cloudformation/tasks/consumer.yml')
1247
+ parameters = [
1248
+ {
1249
+ parameter_key: "Environment",
1250
+ parameter_value: "qa"
1251
+ },
1252
+ {
1253
+ parameter_key: "ReleaseVersion",
1254
+ parameter_value: "#{@projects["prima"]['revision']}"
1255
+ },
1256
+ {
1257
+ parameter_key: "ECSClusterName",
1258
+ parameter_value: get_ecs_cluster_name
1259
+ },
1260
+ {
1261
+ parameter_key: "EnvHash",
1262
+ parameter_value: get_deploy_id
1263
+ }
1264
+ ]
1265
+ if stack_exists?(stack_name_consumer)
1266
+ cur_version = get_currently_deployed_version(stack_name_consumer)
1267
+ update_stack(stack_name_consumer, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["prima"]['revision'])
1268
+ else
1269
+ create_stack(stack_name_consumer, stack_body, parameters, @tags, @cf_role)
1270
+ end
1271
+
1272
+ stack_name_consumer_api = get_stack_name("consumer-api")
1273
+ stack_body = IO.read('projects/prima/app/cloudformation/tasks/consumer-api.yml')
1274
+ parameters = [
1275
+ {
1276
+ parameter_key: "Environment",
1277
+ parameter_value: "qa"
1278
+ },
1279
+ {
1280
+ parameter_key: "ReleaseVersion",
1281
+ parameter_value: "#{@projects["prima"]['revision']}"
1282
+ },
1283
+ {
1284
+ parameter_key: "ECSClusterName",
1285
+ parameter_value: get_ecs_cluster_name
1286
+ },
1287
+ {
1288
+ parameter_key: "EnvHash",
1289
+ parameter_value: get_deploy_id
1290
+ },
1291
+ {
1292
+ parameter_key: "HostnamePattern",
1293
+ parameter_value: "consumer-#{get_deploy_id}.qa.colaster.com"
1294
+ }
1295
+ ]
1296
+ if stack_exists?(stack_name_consumer_api)
1297
+ cur_version = get_currently_deployed_version(stack_name_consumer_api)
1298
+ update_stack(stack_name_consumer_api, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["prima"]['revision'])
1299
+ else
1300
+ create_stack(stack_name_consumer_api, stack_body, parameters, @tags, @cf_role)
1301
+ end
1302
+ end
1303
+
1304
+ def create_roger_stack()
1305
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/roger/#{@projects["roger"]['revision']}-qa.tar.gz")
1306
+ wait_for_stack_ready(get_stack_name("consumer")) unless stack_ready?(get_stack_name("consumer"))
1307
+ stack_name_roger = "ecs-task-roger-qa-#{get_deploy_id}"
1308
+ git_checkout_version('roger', @projects["roger"]['revision'])
1309
+ stack_body = File.read('projects/roger/deploy/task.yml')
1310
+ parameters = [
1311
+ {
1312
+ parameter_key: "Environment",
1313
+ parameter_value: "qa"
1314
+ },
1315
+ {
1316
+ parameter_key: "ReleaseVersion",
1317
+ parameter_value: @projects["roger"]['revision']
1318
+ },
1319
+ {
1320
+ parameter_key: "ECSClusterName",
1321
+ parameter_value: get_ecs_cluster_name
1322
+ },
1323
+ {
1324
+ parameter_key: "TaskDesiredCount",
1325
+ parameter_value: '1'
1326
+ }
1327
+ ]
1328
+ if stack_exists?(stack_name_roger)
1329
+ cur_version = get_currently_deployed_version(stack_name_roger)
1330
+ update_stack(stack_name_roger, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["roger"]['revision'])
1331
+ else
1332
+ create_stack(stack_name_roger, stack_body, parameters, @tags, @cf_role)
1333
+ end
1334
+ end
1335
+
1336
+ def create_hutch_stack()
1337
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/hutch/#{@projects["hutch"]['revision']}-#{get_deploy_id[0..7]}-qa.tar.gz")
1338
+ wait_for_stack_ready(get_stack_name("starsky")) unless stack_ready?(get_stack_name("starsky"))
1339
+
1340
+ stack_name_hutch = get_stack_name("hutch")
1341
+ git_checkout_version('hutch', @projects["hutch"]['revision'])
1342
+ stack_body = File.read('projects/hutch/deploy/task.yml')
1343
+ parameters = [
1344
+ {
1345
+ parameter_key: "Environment",
1346
+ parameter_value: "qa"
1347
+ },
1348
+ {
1349
+ parameter_key: "ReleaseVersion",
1350
+ parameter_value: "#{@projects["hutch"]['revision']}-#{get_deploy_id[0..7]}"
1351
+ },
1352
+ {
1353
+ parameter_key: "ALBShortName",
1354
+ parameter_value: "hutch-qa-#{get_deploy_id}"[0..27]
1355
+ },
1356
+ {
1357
+ parameter_key: "ECSClusterName",
1358
+ parameter_value: get_ecs_cluster_name
1359
+ },
1360
+ {
1361
+ parameter_key: "EnvHash",
1362
+ parameter_value: get_deploy_id
1363
+ },
1364
+ {
1365
+ parameter_key: "HostnamePattern",
1366
+ parameter_value: "hutch-#{get_deploy_id}.qa.colaster.com"
1367
+ },
1368
+ {
1369
+ parameter_key: "HostnamePatternPriority",
1370
+ parameter_value: (hostname_pattern_priority.to_i + 254).to_s
1371
+ },
1372
+ {
1373
+ parameter_key: "ApiUrl",
1374
+ parameter_value: "https://#{get_route53_hostname('maia-intermediari')}"
1375
+ }
1376
+ ]
1377
+ if stack_exists?(stack_name_hutch)
1378
+ cur_version = get_currently_deployed_version(stack_name_hutch)
1379
+ update_stack(stack_name_hutch, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["hutch"]['revision'])
1380
+ else
1381
+ create_stack(stack_name_hutch, stack_body, parameters, @tags, @cf_role)
1382
+ end
1383
+ end
1384
+
1385
+ def create_maia_stack()
1386
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/maia/#{@projects["maia"]['revision']}-qa.tar.gz")
1387
+ stack_name_maia = get_stack_name("maia")
1388
+ git_checkout_version('maia', @projects["maia"]['revision'])
1389
+ stack_body = File.read('projects/maia/deploy/task.yml')
1390
+ parameters = [
1391
+ {
1392
+ parameter_key: "Environment",
1393
+ parameter_value: "qa"
1394
+ },
1395
+ {
1396
+ parameter_key: "ReleaseVersion",
1397
+ parameter_value: "#{@projects["maia"]['revision']}"
1398
+ },
1399
+ {
1400
+ parameter_key: "ALBShortName",
1401
+ parameter_value: "maia-qa-#{get_deploy_id}"[0..15]
1402
+ },
1403
+ {
1404
+ parameter_key: "ECSClusterName",
1405
+ parameter_value: get_ecs_cluster_name
1406
+ },
1407
+ {
1408
+ parameter_key: "EnvHash",
1409
+ parameter_value: get_deploy_id
1410
+ },
1411
+ {
1412
+ parameter_key: "HostnamePatternPublic",
1413
+ parameter_value: "api*-#{get_deploy_id}.qa.colaster.com"
1414
+ },
1415
+ {
1416
+ parameter_key: "HostnamePatternPriority",
1417
+ parameter_value: (hostname_pattern_priority.to_i + 128).to_s
1418
+ },
1419
+ {
1420
+ parameter_key: "ProxyHostnameIntermediari",
1421
+ parameter_value: "api-intermediari-#{get_deploy_id}.qa.colaster.com"
1422
+ },
1423
+ {
1424
+ parameter_key: "ProxyHostnameApp",
1425
+ parameter_value: "api-#{get_deploy_id}.qa.colaster.com"
1426
+ }
1427
+ ]
1428
+ if stack_exists?(stack_name_maia)
1429
+ cur_version = get_currently_deployed_version(stack_name_maia)
1430
+ update_stack(stack_name_maia, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["maia"]['revision'])
1431
+ else
1432
+ create_stack(stack_name_maia, stack_body, parameters, @tags, @cf_role)
1433
+ end
1434
+ end
1435
+
1436
+ def create_vianello_stack()
1437
+ if deploy_vianello_or_domus?
1438
+ wait_for_artifact('prima-artifacts-encrypted', "microservices/vianello/#{@projects["vianello"]['revision']}-qa.tar.gz")
1439
+ stack_name_vianello = "ecs-task-vianello-qa-#{get_deploy_id}"
1440
+ git_checkout_version('vianello', @projects["vianello"]['revision'])
1441
+ stack_body = File.read('projects/vianello/deploy/task.yml')
1442
+ parameters = [
1443
+ {
1444
+ parameter_key: "Environment",
1445
+ parameter_value: "qa"
1446
+ },
1447
+ {
1448
+ parameter_key: "ReleaseVersion",
1449
+ parameter_value: @projects["vianello"]['revision']
1450
+ },
1451
+ {
1452
+ parameter_key: "ECSClusterName",
1453
+ parameter_value: get_ecs_cluster_name
1454
+ },
1455
+ {
1456
+ parameter_key: "TaskDesiredCount",
1457
+ parameter_value: '1'
1458
+ },
1459
+ {
1460
+ parameter_key: "HostnamePattern",
1461
+ parameter_value: "vianello-#{get_deploy_id}.qa.colaster.com"
1462
+ },
1463
+ {
1464
+ parameter_key: "HostnamePatternPriority",
1465
+ parameter_value: (hostname_pattern_priority.to_i + 254).to_s
1466
+ },
1467
+ {
1468
+ parameter_key: "ECSClusterName",
1469
+ parameter_value: get_ecs_cluster_name
1470
+ },
1471
+ {
1472
+ parameter_key: "ALBShortName",
1473
+ parameter_value: "vianello-qa-#{get_deploy_id}"[0..27]
1474
+ },
1475
+ {
1476
+ parameter_key: "EnvHash",
1477
+ parameter_value: get_deploy_id
1478
+ }
1479
+ ]
1480
+ if stack_exists?(stack_name_vianello)
1481
+ cur_version = get_currently_deployed_version(stack_name_vianello)
1482
+ update_stack(stack_name_vianello, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["vianello"]['revision'])
1483
+ else
1484
+ create_stack(stack_name_vianello, stack_body, parameters, @tags, @cf_role)
1485
+ end
1486
+ else
1487
+ true
1488
+ end
1489
+ end
1490
+
1491
+ def create_domus_stack()
1492
+ true
1493
+ end
1494
+
1495
+ def create_rogoreport_stack()
1496
+ true
1497
+ end
1498
+
1499
+ def complete_qa_setup!()
1500
+ wait_for_stack_ready(get_stack_name("web")) unless stack_ready?(get_stack_name("web"))
1501
+ wait_for_stack_ready(get_stack_name("consumer")) unless stack_ready?(get_stack_name("consumer"))
1502
+ wait_for_stack_ready(get_stack_name("worker-ermes")) unless stack_ready?(get_stack_name("worker-ermes"))
1503
+ wait_for_stack_ready(get_stack_name("ermes")) unless stack_ready?(get_stack_name("ermes"))
1504
+ wait_for_stack_ready(get_stack_name("peano")) unless stack_ready?(get_stack_name("peano"))
1505
+ wait_for_stack_ready(get_stack_name("legion")) unless stack_ready?(get_stack_name("legion"))
1506
+ wait_for_stack_ready(get_stack_name("borat")) unless stack_ready?(get_stack_name("borat"))
1507
+ wait_for_stack_ready(get_stack_name("activia")) unless stack_ready?(get_stack_name("activia"))
1508
+ wait_for_stack_ready(get_stack_name("maia")) unless stack_ready?(get_stack_name("maia"))
1509
+ wait_for_stack_ready(get_stack_name("crash")) unless stack_ready?(get_stack_name("crash"))
1510
+ wait_for_stack_ready(get_stack_name("hutch")) unless stack_ready?(get_stack_name("hutch"))
1511
+ if deploy_vianello_or_domus?
1512
+ wait_for_stack_ready(get_stack_name("vianello")) unless stack_ready?(get_stack_name("vianello"))
1513
+ end
1514
+
1515
+ update_service_defaults(get_stack_name("web"))
1516
+ update_service_defaults(get_stack_name("consumer-api"))
1517
+ update_service_defaults(get_stack_name("urania"))
1518
+ update_service_defaults(get_stack_name("worker-ermes"))
1519
+ update_service_defaults(get_stack_name("ermes"))
1520
+ update_service_defaults(get_stack_name("bburago"))
1521
+ update_service_defaults(get_stack_name("hal9000"))
1522
+ update_service_defaults(get_stack_name("fidaty"))
1523
+ update_service_defaults(get_stack_name("peano"))
1524
+ # update_service_defaults(get_stack_name("legion")) TODO UNCOMMENT
1525
+ update_service_defaults(get_stack_name("assange"))
1526
+ update_service_defaults(get_stack_name("borat"))
1527
+ update_service_defaults(get_stack_name("activia"))
1528
+ update_service_defaults(get_stack_name("skynet"))
1529
+ update_service_defaults(get_stack_name("leftorium"))
1530
+ update_service_defaults(get_stack_name("rachele"))
1531
+ update_service_defaults(get_stack_name("maia"))
1532
+ update_service_defaults(get_stack_name("starsky"))
1533
+ update_service_defaults(get_stack_name("hutch"))
1534
+ update_service_defaults(get_stack_name("crash"))
1535
+ if deploy_vianello_or_domus?
1536
+ update_service_defaults(get_stack_name("vianello"))
1537
+ end
1538
+
1539
+ activia_hostname = get_route53_hostname("activia")
1540
+ assange_hostname = get_route53_hostname("assange")
1541
+ bburago_hostname = get_route53_hostname("bburago")
1542
+ borat_hostname = get_route53_hostname("borat")
1543
+ ermes_hostname = get_route53_hostname("ermes")
1544
+ fidaty_hostname = get_route53_hostname("fidaty")
1545
+ hal9000_hostname = get_route53_hostname("hal9000")
1546
+ prima_hostname = get_route53_hostname("web")
1547
+ peano_hostname = get_route53_hostname("peano")
1548
+ skynet_hostname = get_route53_hostname("skynet")
1549
+ urania_hostname = get_route53_hostname("urania")
1550
+ roger_hostname = get_route53_hostname("roger")
1551
+ leftorium_hostname = get_route53_hostname("leftorium")
1552
+ rachele_hostname = get_route53_hostname("rachele")
1553
+ maia_app_hostname = get_route53_hostname("maia-app")
1554
+ maia_intermediari_hostname = get_route53_hostname("maia-intermediari")
1555
+ crash_hostname = get_route53_hostname("crash")
1556
+ starsky_hostname = get_route53_hostname("starsky")
1557
+ hutch_hostname = get_route53_hostname("hutch")
1558
+ legion_hostname = get_route53_hostname("legion")
1559
+ vianello_hostname = get_route53_hostname("vianello")
1560
+
1561
+ #launch_mimo(get_deploy_id)
1562
+
1563
+ projects_text = "
1564
+ > Prima url: https://#{prima_hostname}
1565
+ > Backoffice (Borat) url: https://#{borat_hostname}
1566
+ > Urania url: http://#{urania_hostname}:81
1567
+ > Bburago url: http://#{bburago_hostname}:83
1568
+ > Ermes url: http://#{ermes_hostname}:10002
1569
+ > Hal9000 url: http://#{hal9000_hostname}:10031
1570
+ > Fidaty url: http://#{fidaty_hostname}:10021
1571
+ > Peano url: http://#{peano_hostname}:10039
1572
+ > Assange url: https://#{assange_hostname}
1573
+ > Activia url: http://#{activia_hostname}:10041
1574
+ > Skynet url: http://#{skynet_hostname}:8050
1575
+ > Roger url: http://#{roger_hostname}:10051
1576
+ > Leftorium url: http://#{leftorium_hostname}:10061
1577
+ > Rachele url: http://#{rachele_hostname}:10040
1578
+ > Maia App url: https://#{maia_app_hostname}
1579
+ > Maia Intermediari url: https://#{maia_intermediari_hostname}
1580
+ > Legion url: http://#{legion_hostname}:8051
1581
+ > Crash url: https://#{crash_hostname}
1582
+ > Starsky url: https://#{starsky_hostname}
1583
+ > Hutch url: https://#{hutch_hostname}"
1584
+ projects_text.concat "
1585
+ > Vianello url: https://#{vianello_hostname}" if deploy_vianello_or_domus?
1586
+ projects_text.concat "
1587
+ > RabbitMQ url: http://#{get_ec2_ip_address}:15672
1588
+ > Elasticsearch url: http://#{get_ec2_ip_address}:9200
1589
+ > Git branch: #{@git_branch}
1590
+ > SSH connection: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no githubUsername@#{get_ec2_ip_address}\n"
1591
+ output projects_text.cyan
1592
+ output "Deploy effettuato, everything is awesome!\n".green
1593
+
1594
+ if @projects['prima']['name'] != 'master' then
1595
+ output "Lancio il batch job per la visual regression..."
1596
+ launch_bocelli_test(prima_hostname)
1597
+ output "Visual regression lanciata con successo!"
1598
+
1599
+ output "Lancio i test con Lighthouse..."
1600
+ launch_lighthouse_test(prima_hostname, "mobile")
1601
+ launch_lighthouse_test(prima_hostname, "desktop")
1602
+ output "Test con Lighthouse lanciati con successo..."
1603
+ end
1604
+
1605
+ qainit_write_output(projects_text, 'Indirizzi scritti su ')
1606
+ end
1607
+
1608
+ def get_route53_hostname(project)
1609
+ case
1610
+ when project.include?('web')
1611
+ host = "www-#{get_deploy_id}.qa.colaster.com"
1612
+ when project.include?('urania')
1613
+ host = "urania-#{get_deploy_id}.qa.colaster.com"
1614
+ when project.include?('bburago')
1615
+ host = "bburago-#{get_deploy_id}.qa.colaster.com"
1616
+ when project.include?('hal9000')
1617
+ host = "hal9000-#{get_deploy_id}.qa.colaster.com"
1618
+ when project.include?('fidaty')
1619
+ host = "fidaty-#{get_deploy_id}.qa.colaster.com"
1620
+ when project.include?('peano')
1621
+ host = "peano-#{get_deploy_id}.qa.colaster.com"
1622
+ when project.include?('assange')
1623
+ host = "assange-#{get_deploy_id}.qa.colaster.com"
1624
+ when project.include?('borat')
1625
+ host = "backoffice-#{get_deploy_id}.qa.colaster.com"
1626
+ when project.include?('crash')
1627
+ host = "crash-#{get_deploy_id}.qa.colaster.com"
1628
+ when project.include?('ermes')
1629
+ host = "ermes-#{get_deploy_id}.qa.colaster.com"
1630
+ when project.include?('activia')
1631
+ host = "activia-#{get_deploy_id}.qa.colaster.com"
1632
+ when project.include?('skynet')
1633
+ host = "skynet-#{get_deploy_id}.qa.colaster.com"
1634
+ when project.include?('roger')
1635
+ host = "roger-#{get_deploy_id}.qa.colaster.com"
1636
+ when project.include?('leftorium')
1637
+ host = "leftorium-#{get_deploy_id}.qa.colaster.com"
1638
+ when project.include?('rachele')
1639
+ host = "rachele-#{get_deploy_id}.qa.colaster.com"
1640
+ when project.include?('starsky')
1641
+ host = "starsky-#{get_deploy_id}.qa.colaster.com"
1642
+ when project.include?('hutch')
1643
+ host = "hutch-#{get_deploy_id}.qa.colaster.com"
1644
+ when project.include?('maia-app')
1645
+ host = "api-#{get_deploy_id}.qa.colaster.com"
1646
+ when project.include?('legion')
1647
+ host = "legion-#{get_deploy_id}.qa.colaster.com"
1648
+ when project.include?('maia-intermediari')
1649
+ host = "api-intermediari-#{get_deploy_id}.qa.colaster.com"
1650
+ when project.include?('vianello')
1651
+ host = "vianello-#{get_deploy_id}.qa.colaster.com"
1652
+ end
1653
+ host
1654
+ end
1655
+
1656
+ def get_ec2_ip_address()
1657
+ if @ec2_ip_address
1658
+ @ec2_ip_address
1659
+ else
1660
+ resp = describe_stack_resource(get_asg_stack_name, 'ECSAutoScalingGroup')
1661
+ resp = describe_auto_scaling_groups([resp.stack_resource_detail.physical_resource_id], 1)
1662
+ instance_id = resp.auto_scaling_groups[0].instances[0].instance_id
1663
+ resp = describe_instances([instance_id])
1664
+ @ec2_ip_address = resp.reservations[0].instances[0].private_ip_address
1665
+ @ec2_ip_address
1666
+ end
1667
+ end
1668
+
1669
+ def get_alb_host(stack_name)
1670
+ case
1671
+ when stack_name.include?('web')
1672
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1673
+ when stack_name.include?('urania')
1674
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1675
+ when stack_name.include?('backoffice')
1676
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1677
+ when stack_name.include?('bburago')
1678
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1679
+ when stack_name.include?('hal9000')
1680
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1681
+ when stack_name.include?('fidaty')
1682
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1683
+ when stack_name.include?('activia')
1684
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1685
+ when stack_name.include?('skynet')
1686
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1687
+ when stack_name.include?('roger')
1688
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1689
+ when stack_name.include?('alb-http-public')
1690
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1691
+ when stack_name.include?('alb-ws-public')
1692
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1693
+ when stack_name.include?('peano')
1694
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1695
+ when stack_name.include?('leftorium')
1696
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1697
+ when stack_name.include?('assange')
1698
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1699
+ when stack_name.include?('borat')
1700
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1701
+ when stack_name.include?('crash')
1702
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1703
+ when stack_name.include?('rachele')
1704
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1705
+ when stack_name.include?('starsky')
1706
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1707
+ when stack_name.include?('hutch')
1708
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1709
+ when stack_name.include?('maia')
1710
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1711
+ when stack_name.include?('legion')
1712
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1713
+ when stack_name.include?('vianello')
1714
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1715
+ end
1716
+ resp = describe_stack_resource(stack_name, logical_resource_id)
1717
+ resp = describe_load_balancers([resp.stack_resource_detail.physical_resource_id])
1718
+ resp.load_balancers[0].dns_name
1719
+ end
1720
+
1721
+ def update_service_defaults(stack_name)
1722
+ case
1723
+ when stack_name.include?('web')
1724
+ logical_resource_id = 'ECSServiceWebQA'
1725
+ when stack_name.include?('consumer')
1726
+ logical_resource_id = 'ECSServiceConsumerApiQa'
1727
+ when stack_name.include?('urania')
1728
+ logical_resource_id = 'ECSServiceUraniaQA'
1729
+ when stack_name.include?('backoffice')
1730
+ logical_resource_id = 'ECSServiceBackoffice'
1731
+ when stack_name.include?('worker-ermes')
1732
+ logical_resource_id = 'ECSServiceErmesWorker'
1733
+ when stack_name.include?('ermes')
1734
+ logical_resource_id = 'ECSServiceErmesQA'
1735
+ when stack_name.include?('bburago')
1736
+ logical_resource_id = 'ECSServiceBburagoQA'
1737
+ when stack_name.include?('hal9000')
1738
+ logical_resource_id = 'ECSServiceHal9000QA'
1739
+ when stack_name.include?('fidaty')
1740
+ logical_resource_id = 'ECSServiceFidatyQA'
1741
+ when stack_name.include?('skynet')
1742
+ logical_resource_id = 'ECSServiceSkynetQA'
1743
+ when stack_name.include?('roger')
1744
+ logical_resource_id = 'ECSServiceRogerQA'
1745
+ when stack_name.include?('activia')
1746
+ logical_resource_id = 'ECSServiceActiviaQA'
1747
+ when stack_name.include?('peano')
1748
+ logical_resource_id = 'ECSServicePeanoQA'
1749
+ when stack_name.include?('assange')
1750
+ logical_resource_id = 'ECSServiceAssangeQA'
1751
+ when stack_name.include?('borat')
1752
+ logical_resource_id = 'ECSServiceBorat'
1753
+ when stack_name.include?('leftorium')
1754
+ logical_resource_id = 'ECSServiceLeftoriumQA'
1755
+ when stack_name.include?('rachele')
1756
+ logical_resource_id = 'ECSServiceRacheleQA'
1757
+ when stack_name.include?('crash')
1758
+ logical_resource_id = 'ECSServiceCrashQA'
1759
+ when stack_name.include?('starsky')
1760
+ logical_resource_id = 'ECSServiceStarskyQA'
1761
+ when stack_name.include?('hutch')
1762
+ logical_resource_id = 'ECSServiceHutch'
1763
+ when stack_name.include?('maia')
1764
+ logical_resource_id = 'ECSServiceMaia'
1765
+ when stack_name.include?('legion')
1766
+ logical_resource_id = 'ECSServiceLegionQA'
1767
+ when stack_name.include?('vianello')
1768
+ logical_resource_id = 'ECSServiceVianelloQA'
1769
+ else
1770
+ raise "Service name non gestito per lo stack #{stack_name}"
1771
+ end
1772
+ resp = describe_stack_resource(stack_name, logical_resource_id)
1773
+ update_ecs_service(get_ecs_cluster_name, resp.stack_resource_detail.physical_resource_id, {minimum_healthy_percent: 0, maximum_percent: 100})
1774
+ end
1775
+
1776
+ def launch_lighthouse_test(url, device)
1777
+ @cloudflare.post("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records", {type: 'CNAME', name: "www-#{get_deploy_id}", content: url, proxied: true, ttl: 1}) unless get_lighthouse_dns()
1778
+
1779
+ @batch.submit_job({
1780
+ job_name: "lighthouse-#{device}-#{get_deploy_id}",
1781
+ job_queue: "tools-production",
1782
+ job_definition: describe_stack_resource('batch-job-lighthouse-production', 'JobDefinition').stack_resource_detail.physical_resource_id,
1783
+ container_overrides: {
1784
+ environment: [
1785
+ {
1786
+ name: "URL_TO_TEST",
1787
+ value: "https://www-#{get_deploy_id}.prima.it/?superprima"
1788
+ },
1789
+ {
1790
+ name: "DEVICE",
1791
+ value: device
1792
+ },
1793
+ {
1794
+ name: "BRANCH_NAME",
1795
+ value: @projects['prima']['name']
1796
+ },
1797
+ {
1798
+ name: "COMMITTER_EMAIL",
1799
+ value: @projects['prima']['committer']
1800
+ }
1801
+ ]
1802
+ }
1803
+ })
1804
+ end
1805
+
1806
+ def get_lighthouse_dns()
1807
+ dns_records = @cloudflare.get("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records", {per_page: 100, type: 'CNAME', name: "www-#{get_deploy_id}.prima.it"})
1808
+ if dns_records.body[:result_info][:count] > 0
1809
+ return dns_records.body[:result][0][:id]
1810
+ end
1811
+ false
1812
+ end
1813
+
1814
+ def delete_lighthouse_dns()
1815
+ dns_id = get_lighthouse_dns()
1816
+ @cloudflare.delete("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records/#{dns_id}") if dns_id
1817
+ end
1818
+
1819
+ def launch_bocelli_test(url)
1820
+ @batch.submit_job({
1821
+ job_name: "bocelli-test-#{get_deploy_id}",
1822
+ job_queue: "tools-production",
1823
+ job_definition: describe_stack_resource('batch-job-bocelli-production', 'JobDefinition').stack_resource_detail.physical_resource_id,
1824
+ container_overrides: {
1825
+ environment: [
1826
+ {
1827
+ name: "BATCH_COMMAND",
1828
+ value: "test"
1829
+ },
1830
+ {
1831
+ name: "QA_HOSTNAME",
1832
+ value: url
1833
+ },
1834
+ {
1835
+ name: "BRANCH_NAME",
1836
+ value: @projects['prima']['name']
1837
+ },
1838
+ {
1839
+ name: "COMMITTER_EMAIL",
1840
+ value: @projects['prima']['committer']
1841
+ }
1842
+ ]
1843
+ }
1844
+ })
1845
+ end
1846
+
1847
+ def deploy_vianello_or_domus?
1848
+ vianello_present = !@projects['vianello'].empty? && @projects['vianello'][:name] != 'master' && !@projects['vianello'][:default_branch]
1849
+ domus_present = !@projects['domus'].empty? && @projects['domus'][:name] != 'master' && !@projects['domus'][:default_branch]
1850
+ vianello_present || domus_present
1851
+ end
1852
+
1853
+ def git_checkout_version(project, revision)
1854
+ Dir.chdir "projects/#{project}"
1855
+ exec_step "git checkout -- . && git checkout #{revision}"
1856
+ Dir.chdir "../../"
1857
+ end
1858
+
1859
+ def create_asg_stack(stack_name, tags = [])
1860
+ stack_body = IO.read('cloudformation/stacks/asg/ecs-asg-allinone.yml')
1861
+ parameters = [
1862
+ {
1863
+ parameter_key: "Environment",
1864
+ parameter_value: "qa"
1865
+ },
1866
+ {
1867
+ parameter_key: "InstanceType",
1868
+ parameter_value: "t3a.xlarge"
1869
+ },
1870
+ {
1871
+ parameter_key: "ECSClusterName",
1872
+ parameter_value: get_ecs_cluster_name
1873
+ },
1874
+ {
1875
+ parameter_key: "AMIID",
1876
+ parameter_value: @ami_id
1877
+ }
1878
+ ]
1879
+ create_stack(stack_name, stack_body, parameters, tags, @cf_role)
1880
+ end
1881
+
1882
+ def create_cluster_stack(stack_name, tags = [])
1883
+ stack_body = IO.read('cloudformation/stacks/ecs-cluster.yml')
1884
+ create_stack(stack_name, stack_body, [], tags)
1885
+ end
1886
+
1887
+ def update_cluster_stack(stack_name, tags = [])
1888
+ stack_body = IO.read('cloudformation/stacks/ecs-cluster.yml')
1889
+ update_stack(stack_name, stack_body, [], tags)
1890
+ end
1891
+
1892
+ def create_alb_stack(stack_name, role, hash, environment = 'qa')
1893
+ stack_body = IO.read('cloudformation/stacks/elb/alb-public-qa.yml')
1894
+ parameters = [
1895
+ {
1896
+ parameter_key: "Environment",
1897
+ parameter_value: environment
1898
+ },
1899
+ {
1900
+ parameter_key: "Role",
1901
+ parameter_value: role
1902
+ },
1903
+ {
1904
+ parameter_key: "EnvHash",
1905
+ parameter_value: hash
1906
+ }
1907
+ ]
1908
+ create_stack(stack_name, stack_body, parameters, [], @cf_role)
1909
+ end
1910
+
1911
+ def import_redis_crash(qa_ip_address)
1912
+ output "Importo chiavi di Redis da staging\n".yellow
1913
+
1914
+ prefixes = ['CODICI', 'fun_with_flags']
1915
+ redis_qa = Redis.new(:url => "redis://#{qa_ip_address}:6379/10")
1916
+ redis_staging = Redis.new(:url => 'redis://staging.cache-1.prima.it:6379/10')
1917
+
1918
+ prefixes.each do |prefix|
1919
+ redis_staging.keys("#{prefix}*").each do |key|
1920
+ next unless redis_qa.keys(key).empty?
1921
+ output "Importo #{key} dal Redis di staging\n".yellow
1922
+ dump_staging = redis_staging.dump key
1923
+ redis_qa.restore key, 0, dump_staging
1924
+ end
1925
+ end
1926
+ end
1927
+
1928
+ def import_dbs(ip_address)
1929
+ overrides = {
1930
+ container_overrides: [
1931
+ {
1932
+ name: 'dbrestore',
1933
+ environment: [
1934
+ {
1935
+ name: 'EC2_IP_ADDRESS',
1936
+ value: ip_address
1937
+ }
1938
+ ]
1939
+ }
1940
+ ]
1941
+ }
1942
+ resp = run_ecs_task(get_ecs_cluster_name, @import_db_task, overrides, 1)
1943
+ return resp
1944
+ end
1945
+
1946
+ def wait_for_db_import(task)
1947
+ output "Attendo che i DB vengano importati...\n".yellow
1948
+ stopped_at = nil
1949
+ sleep 15 # altrimenti non trova il task appena avviato...
1950
+ while stopped_at.nil?
1951
+ if task.tasks[0].nil?
1952
+ pp get_ecs_cluster_name
1953
+ pp task
1954
+ stop_if true, "Task di import DB lanciato, ma risposta vuota!".red
1955
+ end
1956
+ task = describe_ecs_tasks(task.tasks[0].cluster_arn, [task.tasks[0].task_arn])
1957
+ stopped_at = task.tasks[0].stopped_at unless task.tasks[0].nil?
1958
+ sleep_seconds = 10
1959
+ seconds_elapsed = 0
1960
+ while true && stopped_at.nil?
1961
+ break if seconds_elapsed >= sleep_seconds
1962
+ print '.'.yellow; STDOUT.flush
1963
+ sleep 1
1964
+ seconds_elapsed += 1
1965
+ end
1966
+ end
1967
+ print "\n"
1968
+ end
1969
+
1970
+ def get_stacks()
1971
+ envs = {}
1972
+ stack_list = stack_list()
1973
+ stack_list.each do |stack|
1974
+ unless stack.stack_name.match(/spotfleet-allinone-qa-(\w+)$/)
1975
+ env_hash = stack.stack_name.match(/qa-(\w+)$/)[0]
1976
+ envs[env_hash] = stack.tags unless envs.has_key?(env_hash) || stack.tags.empty?
1977
+ end
1978
+ end
1979
+ return stack_list, envs
1980
+ end
1981
+
1982
+ def get_clusters()
1983
+ envs = {}
1984
+ cluster_list = cluster_list()
1985
+ cluster_list.each do |stack|
1986
+ unless stack.stack_name.match(/spotfleet-allinone-qa-(\w+)$/)
1987
+ env_hash = stack.stack_name.match(/qa-(\w+)$/)[0]
1988
+ envs[env_hash] = stack.tags unless envs.has_key?(env_hash) || stack.tags.empty?
1989
+ end
1990
+ end
1991
+ return cluster_list, envs
1992
+ end
1993
+
1994
+ def hostname_pattern_priority()
1995
+ (Time.now.to_i.to_s[-4..-1].to_i + Random.rand(40000)).to_s
1996
+ end
1997
+
1998
+ def launch_mimo(env_hash)
1999
+ resp = describe_stack_resource('batch-job-mimo', 'JobDefinition')
2000
+
2001
+ @batch.submit_job({
2002
+ job_name: "mimo-#{get_deploy_id}", # required
2003
+ job_queue: "tools-production", # required
2004
+ job_definition: resp.stack_resource_detail.physical_resource_id, # required
2005
+ container_overrides: {
2006
+ environment: [
2007
+ {
2008
+ name: 'ENV_HASH',
2009
+ value: env_hash
2010
+ },
2011
+ {
2012
+ name: 'APP_ENV',
2013
+ value: 'qa'
2014
+ },
2015
+ {
2016
+ name: 'CYPRESS_BASE_URL',
2017
+ value: "https://hutch-#{env_hash}.qa.colaster.com"
2018
+ },
2019
+ {
2020
+ name: 'CYPRESS_PEANO_BASE_URL',
2021
+ value: "http://peano-#{env_hash}.qa.colaster.com:10039/quotation"
2022
+ },
2023
+ {
2024
+ name: 'CYPRESS_API_BASE_URL',
2025
+ value: "https://#{get_route53_hostname("starsky")}/graphql"
2026
+ },
2027
+ {
2028
+ name: 'QA_NAME',
2029
+ value: @git_branch
2030
+ }
2031
+ ]
2032
+ }
2033
+ })
2034
+
2035
+ output "Mimo lanciato con successo!\n".green
2036
+ end
2037
+
2038
+ def get_currently_deployed_version(stack_name)
2039
+ parameters = get_stack_parameters(stack_name)
2040
+ currently_deployed_version = nil
2041
+ parameters.each do |parameter|
2042
+ if parameter.parameter_key == "ReleaseVersion"
2043
+ currently_deployed_version = parameter.parameter_value
2044
+ end
2045
+ end
2046
+ currently_deployed_version
2047
+ end
2048
+
2049
+ def get_ami_id(stack_name)
2050
+ get_stack_parameters(stack_name).each do |param|
2051
+ if param.parameter_key == "AMIID"
2052
+ return param.parameter_value
2053
+ end
2054
+ end
2055
+ end
2056
+ end
2057
+
2058
+ def help_content
2059
+ <<-HELP
2060
+
2061
+ twig-buils
2062
+ ===========
2063
+
2064
+ Manage qa cloudformation stack creation
2065
+
2066
+ Synopsis
2067
+ --------
2068
+
2069
+ twig build #command
2070
+
2071
+ Description
2072
+ -----------
2073
+
2074
+ #command #command description
2075
+
2076
+ HELP
2077
+ end
2078
+
2079
+ args = ARGV.dup
2080
+
2081
+ if args.include?('--help')
2082
+ puts help_content
2083
+ exit
2084
+ end
2085
+
2086
+ args.delete('no-gem-update')
2087
+
2088
+ Build.new().execute!(args)