prima-twig 0.54.46 → 0.54.230

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: fdbc54d884ff44acd5b72bde1de750778b3487f085a187766d8093f298bc77b1
4
- data.tar.gz: 225bc6500fd240bd46651c2384088338f79bfd74627f60d6f472d63caeed6286
3
+ metadata.gz: 85a887eb9ac67339e922932d0d711c3e526765e358ecf47afb069c56e9d28da9
4
+ data.tar.gz: 829c0ac921e6561274e1a9084bdf0ecd5b53f317cf74a1dc9bf0b293e1cf938f
5
5
  SHA512:
6
- metadata.gz: 636bdeb287ef5b5e13f37bfd05902f99d866a29f9a6115396d83ac1317f69618dbb81e161e85bd37473d6f1e7962a33e67480722cc52dc36541ff1f057d26bf5
7
- data.tar.gz: f7fea9cea687aaf974f3dfa6e4f8db444d031ddaa58e1a95e24e9ddde12af9d92cc20a5a26ddfc6361d413575ca1563e529ca889a3b4481302f9a00880089a98
6
+ metadata.gz: 7223c3b1d81012a0ea3c552372f7a2cb9053aecee1bb66ab3d5982e23cd2d72955c12f30852bff3dd1d834fd7df2ae73ca06aaef78766b3d91b8cd871731fa90
7
+ data.tar.gz: 830241918eacd60281052b590368b7ef53b39a4dd3428c186586cd3544ad25bf81cab12dded5103f67aa54b7900b571f876567b1639c424edeb9962146129585
@@ -0,0 +1,2072 @@
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
+ if stack_exists?(stack_name_vianello)
1469
+ cur_version = get_currently_deployed_version(stack_name_vianello)
1470
+ update_stack(stack_name_vianello, stack_body, parameters, @tags, @cf_role) unless cur_version.include?(@projects["vianello"]['revision'])
1471
+ else
1472
+ create_stack(stack_name_vianello, stack_body, parameters, @tags, @cf_role)
1473
+ end
1474
+ else
1475
+ true
1476
+ end
1477
+ end
1478
+
1479
+ def create_rogoreport_stack()
1480
+ true
1481
+ end
1482
+
1483
+ def complete_qa_setup!()
1484
+ wait_for_stack_ready(get_stack_name("web")) unless stack_ready?(get_stack_name("web"))
1485
+ wait_for_stack_ready(get_stack_name("consumer")) unless stack_ready?(get_stack_name("consumer"))
1486
+ wait_for_stack_ready(get_stack_name("worker-ermes")) unless stack_ready?(get_stack_name("worker-ermes"))
1487
+ wait_for_stack_ready(get_stack_name("ermes")) unless stack_ready?(get_stack_name("ermes"))
1488
+ wait_for_stack_ready(get_stack_name("peano")) unless stack_ready?(get_stack_name("peano"))
1489
+ wait_for_stack_ready(get_stack_name("legion")) unless stack_ready?(get_stack_name("legion"))
1490
+ wait_for_stack_ready(get_stack_name("borat")) unless stack_ready?(get_stack_name("borat"))
1491
+ wait_for_stack_ready(get_stack_name("activia")) unless stack_ready?(get_stack_name("activia"))
1492
+ wait_for_stack_ready(get_stack_name("maia")) unless stack_ready?(get_stack_name("maia"))
1493
+ wait_for_stack_ready(get_stack_name("crash")) unless stack_ready?(get_stack_name("crash"))
1494
+ wait_for_stack_ready(get_stack_name("hutch")) unless stack_ready?(get_stack_name("hutch"))
1495
+ if deploy_vianello_or_domus?
1496
+ wait_for_stack_ready(get_stack_name("vianello")) unless stack_ready?(get_stack_name("vianello"))
1497
+ end
1498
+
1499
+ update_service_defaults(get_stack_name("web"))
1500
+ update_service_defaults(get_stack_name("consumer-api"))
1501
+ update_service_defaults(get_stack_name("urania"))
1502
+ update_service_defaults(get_stack_name("worker-ermes"))
1503
+ update_service_defaults(get_stack_name("ermes"))
1504
+ update_service_defaults(get_stack_name("bburago"))
1505
+ update_service_defaults(get_stack_name("hal9000"))
1506
+ update_service_defaults(get_stack_name("fidaty"))
1507
+ update_service_defaults(get_stack_name("peano"))
1508
+ # update_service_defaults(get_stack_name("legion")) TODO UNCOMMENT
1509
+ update_service_defaults(get_stack_name("assange"))
1510
+ update_service_defaults(get_stack_name("borat"))
1511
+ update_service_defaults(get_stack_name("activia"))
1512
+ update_service_defaults(get_stack_name("skynet"))
1513
+ update_service_defaults(get_stack_name("leftorium"))
1514
+ update_service_defaults(get_stack_name("rachele"))
1515
+ update_service_defaults(get_stack_name("maia"))
1516
+ update_service_defaults(get_stack_name("starsky"))
1517
+ update_service_defaults(get_stack_name("hutch"))
1518
+ update_service_defaults(get_stack_name("crash"))
1519
+ if deploy_vianello_or_domus?
1520
+ update_service_defaults(get_stack_name("vianello"))
1521
+ end
1522
+
1523
+ activia_hostname = get_route53_hostname("activia")
1524
+ assange_hostname = get_route53_hostname("assange")
1525
+ bburago_hostname = get_route53_hostname("bburago")
1526
+ borat_hostname = get_route53_hostname("borat")
1527
+ ermes_hostname = get_route53_hostname("ermes")
1528
+ fidaty_hostname = get_route53_hostname("fidaty")
1529
+ hal9000_hostname = get_route53_hostname("hal9000")
1530
+ prima_hostname = get_route53_hostname("web")
1531
+ peano_hostname = get_route53_hostname("peano")
1532
+ skynet_hostname = get_route53_hostname("skynet")
1533
+ urania_hostname = get_route53_hostname("urania")
1534
+ roger_hostname = get_route53_hostname("roger")
1535
+ leftorium_hostname = get_route53_hostname("leftorium")
1536
+ rachele_hostname = get_route53_hostname("rachele")
1537
+ maia_app_hostname = get_route53_hostname("maia-app")
1538
+ maia_intermediari_hostname = get_route53_hostname("maia-intermediari")
1539
+ crash_hostname = get_route53_hostname("crash")
1540
+ starsky_hostname = get_route53_hostname("starsky")
1541
+ hutch_hostname = get_route53_hostname("hutch")
1542
+ legion_hostname = get_route53_hostname("legion")
1543
+ vianello_hostname = get_route53_hostname("vianello")
1544
+
1545
+ #launch_mimo(get_deploy_id)
1546
+
1547
+ projects_text = "
1548
+ > Prima url: https://#{prima_hostname}
1549
+ > Backoffice (Borat) url: https://#{borat_hostname}
1550
+ > Urania url: http://#{urania_hostname}:81
1551
+ > Bburago url: http://#{bburago_hostname}:83
1552
+ > Ermes url: http://#{ermes_hostname}:10002
1553
+ > Hal9000 url: http://#{hal9000_hostname}:10031
1554
+ > Fidaty url: http://#{fidaty_hostname}:10021
1555
+ > Peano url: http://#{peano_hostname}:10039
1556
+ > Assange url: https://#{assange_hostname}
1557
+ > Activia url: http://#{activia_hostname}:10041
1558
+ > Skynet url: http://#{skynet_hostname}:8050
1559
+ > Roger url: http://#{roger_hostname}:10051
1560
+ > Leftorium url: http://#{leftorium_hostname}:10061
1561
+ > Rachele url: http://#{rachele_hostname}:10040
1562
+ > Maia App url: https://#{maia_app_hostname}
1563
+ > Maia Intermediari url: https://#{maia_intermediari_hostname}
1564
+ > Legion url: http://#{legion_hostname}:8051
1565
+ > Crash url: https://#{crash_hostname}
1566
+ > Starsky url: https://#{starsky_hostname}
1567
+ > Hutch url: https://#{hutch_hostname}"
1568
+ projects_text.concat "
1569
+ > Vianello url: https://#{vianello_hostname}" if deploy_vianello_or_domus?
1570
+ projects_text.concat "
1571
+ > RabbitMQ url: http://#{get_ec2_ip_address}:15672
1572
+ > Elasticsearch url: http://#{get_ec2_ip_address}:9200
1573
+ > Git branch: #{@git_branch}
1574
+ > SSH connection: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no githubUsername@#{get_ec2_ip_address}\n"
1575
+ output projects_text.cyan
1576
+ output "Deploy effettuato, everything is awesome!\n".green
1577
+
1578
+ if @projects['prima']['name'] != 'master' then
1579
+ output "Lancio il batch job per la visual regression..."
1580
+ launch_bocelli_test(prima_hostname)
1581
+ output "Visual regression lanciata con successo!"
1582
+
1583
+ output "Lancio i test con Lighthouse..."
1584
+ launch_lighthouse_test(prima_hostname, "mobile")
1585
+ launch_lighthouse_test(prima_hostname, "desktop")
1586
+ output "Test con Lighthouse lanciati con successo..."
1587
+ end
1588
+
1589
+ qainit_write_output(projects_text, 'Indirizzi scritti su ')
1590
+ end
1591
+
1592
+ def get_route53_hostname(project)
1593
+ case
1594
+ when project.include?('web')
1595
+ host = "www-#{get_deploy_id}.qa.colaster.com"
1596
+ when project.include?('urania')
1597
+ host = "urania-#{get_deploy_id}.qa.colaster.com"
1598
+ when project.include?('bburago')
1599
+ host = "bburago-#{get_deploy_id}.qa.colaster.com"
1600
+ when project.include?('hal9000')
1601
+ host = "hal9000-#{get_deploy_id}.qa.colaster.com"
1602
+ when project.include?('fidaty')
1603
+ host = "fidaty-#{get_deploy_id}.qa.colaster.com"
1604
+ when project.include?('peano')
1605
+ host = "peano-#{get_deploy_id}.qa.colaster.com"
1606
+ when project.include?('assange')
1607
+ host = "assange-#{get_deploy_id}.qa.colaster.com"
1608
+ when project.include?('borat')
1609
+ host = "backoffice-#{get_deploy_id}.qa.colaster.com"
1610
+ when project.include?('crash')
1611
+ host = "crash-#{get_deploy_id}.qa.colaster.com"
1612
+ when project.include?('ermes')
1613
+ host = "ermes-#{get_deploy_id}.qa.colaster.com"
1614
+ when project.include?('activia')
1615
+ host = "activia-#{get_deploy_id}.qa.colaster.com"
1616
+ when project.include?('skynet')
1617
+ host = "skynet-#{get_deploy_id}.qa.colaster.com"
1618
+ when project.include?('roger')
1619
+ host = "roger-#{get_deploy_id}.qa.colaster.com"
1620
+ when project.include?('leftorium')
1621
+ host = "leftorium-#{get_deploy_id}.qa.colaster.com"
1622
+ when project.include?('rachele')
1623
+ host = "rachele-#{get_deploy_id}.qa.colaster.com"
1624
+ when project.include?('starsky')
1625
+ host = "starsky-#{get_deploy_id}.qa.colaster.com"
1626
+ when project.include?('hutch')
1627
+ host = "hutch-#{get_deploy_id}.qa.colaster.com"
1628
+ when project.include?('maia-app')
1629
+ host = "api-#{get_deploy_id}.qa.colaster.com"
1630
+ when project.include?('legion')
1631
+ host = "legion-#{get_deploy_id}.qa.colaster.com"
1632
+ when project.include?('maia-intermediari')
1633
+ host = "api-intermediari-#{get_deploy_id}.qa.colaster.com"
1634
+ when project.include?('vianello')
1635
+ host = "vianello-#{get_deploy_id}.qa.colaster.com"
1636
+ end
1637
+ host
1638
+ end
1639
+
1640
+ def get_ec2_ip_address()
1641
+ if @ec2_ip_address
1642
+ @ec2_ip_address
1643
+ else
1644
+ resp = describe_stack_resource(get_asg_stack_name, 'ECSAutoScalingGroup')
1645
+ resp = describe_auto_scaling_groups([resp.stack_resource_detail.physical_resource_id], 1)
1646
+ instance_id = resp.auto_scaling_groups[0].instances[0].instance_id
1647
+ resp = describe_instances([instance_id])
1648
+ @ec2_ip_address = resp.reservations[0].instances[0].private_ip_address
1649
+ @ec2_ip_address
1650
+ end
1651
+ end
1652
+
1653
+ def get_alb_host(stack_name)
1654
+ case
1655
+ when stack_name.include?('web')
1656
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1657
+ when stack_name.include?('urania')
1658
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1659
+ when stack_name.include?('backoffice')
1660
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1661
+ when stack_name.include?('bburago')
1662
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1663
+ when stack_name.include?('hal9000')
1664
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1665
+ when stack_name.include?('fidaty')
1666
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1667
+ when stack_name.include?('activia')
1668
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1669
+ when stack_name.include?('skynet')
1670
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1671
+ when stack_name.include?('roger')
1672
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1673
+ when stack_name.include?('alb-http-public')
1674
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1675
+ when stack_name.include?('alb-ws-public')
1676
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1677
+ when stack_name.include?('peano')
1678
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1679
+ when stack_name.include?('leftorium')
1680
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1681
+ when stack_name.include?('assange')
1682
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1683
+ when stack_name.include?('borat')
1684
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1685
+ when stack_name.include?('crash')
1686
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1687
+ when stack_name.include?('rachele')
1688
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1689
+ when stack_name.include?('starsky')
1690
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1691
+ when stack_name.include?('hutch')
1692
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1693
+ when stack_name.include?('maia')
1694
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1695
+ when stack_name.include?('legion')
1696
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1697
+ when stack_name.include?('vianello')
1698
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1699
+ end
1700
+ resp = describe_stack_resource(stack_name, logical_resource_id)
1701
+ resp = describe_load_balancers([resp.stack_resource_detail.physical_resource_id])
1702
+ resp.load_balancers[0].dns_name
1703
+ end
1704
+
1705
+ def update_service_defaults(stack_name)
1706
+ case
1707
+ when stack_name.include?('web')
1708
+ logical_resource_id = 'ECSServiceWebQA'
1709
+ when stack_name.include?('consumer')
1710
+ logical_resource_id = 'ECSServiceConsumerApiQa'
1711
+ when stack_name.include?('urania')
1712
+ logical_resource_id = 'ECSServiceUraniaQA'
1713
+ when stack_name.include?('backoffice')
1714
+ logical_resource_id = 'ECSServiceBackoffice'
1715
+ when stack_name.include?('worker-ermes')
1716
+ logical_resource_id = 'ECSServiceErmesWorker'
1717
+ when stack_name.include?('ermes')
1718
+ logical_resource_id = 'ECSServiceErmesQA'
1719
+ when stack_name.include?('bburago')
1720
+ logical_resource_id = 'ECSServiceBburagoQA'
1721
+ when stack_name.include?('hal9000')
1722
+ logical_resource_id = 'ECSServiceHal9000QA'
1723
+ when stack_name.include?('fidaty')
1724
+ logical_resource_id = 'ECSServiceFidatyQA'
1725
+ when stack_name.include?('skynet')
1726
+ logical_resource_id = 'ECSServiceSkynetQA'
1727
+ when stack_name.include?('roger')
1728
+ logical_resource_id = 'ECSServiceRogerQA'
1729
+ when stack_name.include?('activia')
1730
+ logical_resource_id = 'ECSServiceActiviaQA'
1731
+ when stack_name.include?('peano')
1732
+ logical_resource_id = 'ECSServicePeanoQA'
1733
+ when stack_name.include?('assange')
1734
+ logical_resource_id = 'ECSServiceAssangeQA'
1735
+ when stack_name.include?('borat')
1736
+ logical_resource_id = 'ECSServiceBorat'
1737
+ when stack_name.include?('leftorium')
1738
+ logical_resource_id = 'ECSServiceLeftoriumQA'
1739
+ when stack_name.include?('rachele')
1740
+ logical_resource_id = 'ECSServiceRacheleQA'
1741
+ when stack_name.include?('crash')
1742
+ logical_resource_id = 'ECSServiceCrashQA'
1743
+ when stack_name.include?('starsky')
1744
+ logical_resource_id = 'ECSServiceStarskyQA'
1745
+ when stack_name.include?('hutch')
1746
+ logical_resource_id = 'ECSServiceHutch'
1747
+ when stack_name.include?('maia')
1748
+ logical_resource_id = 'ECSServiceMaia'
1749
+ when stack_name.include?('legion')
1750
+ logical_resource_id = 'ECSServiceLegionQA'
1751
+ when stack_name.include?('vianello')
1752
+ logical_resource_id = 'ECSServiceVianelloQA'
1753
+ else
1754
+ raise "Service name non gestito per lo stack #{stack_name}"
1755
+ end
1756
+ resp = describe_stack_resource(stack_name, logical_resource_id)
1757
+ update_ecs_service(get_ecs_cluster_name, resp.stack_resource_detail.physical_resource_id, {minimum_healthy_percent: 0, maximum_percent: 100})
1758
+ end
1759
+
1760
+ def launch_lighthouse_test(url, device)
1761
+ @cloudflare.post("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records", {type: 'CNAME', name: "www-#{get_deploy_id}", content: url, proxied: true, ttl: 1}) unless get_lighthouse_dns()
1762
+
1763
+ @batch.submit_job({
1764
+ job_name: "lighthouse-#{device}-#{get_deploy_id}",
1765
+ job_queue: "tools-production",
1766
+ job_definition: describe_stack_resource('batch-job-lighthouse-production', 'JobDefinition').stack_resource_detail.physical_resource_id,
1767
+ container_overrides: {
1768
+ environment: [
1769
+ {
1770
+ name: "URL_TO_TEST",
1771
+ value: "https://www-#{get_deploy_id}.prima.it/?superprima"
1772
+ },
1773
+ {
1774
+ name: "DEVICE",
1775
+ value: device
1776
+ },
1777
+ {
1778
+ name: "BRANCH_NAME",
1779
+ value: @projects['prima']['name']
1780
+ },
1781
+ {
1782
+ name: "COMMITTER_EMAIL",
1783
+ value: @projects['prima']['committer']
1784
+ }
1785
+ ]
1786
+ }
1787
+ })
1788
+ end
1789
+
1790
+ def get_lighthouse_dns()
1791
+ dns_records = @cloudflare.get("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records", {per_page: 100, type: 'CNAME', name: "www-#{get_deploy_id}.prima.it"})
1792
+ if dns_records.body[:result_info][:count] > 0
1793
+ return dns_records.body[:result][0][:id]
1794
+ end
1795
+ false
1796
+ end
1797
+
1798
+ def delete_lighthouse_dns()
1799
+ dns_id = get_lighthouse_dns()
1800
+ @cloudflare.delete("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records/#{dns_id}") if dns_id
1801
+ end
1802
+
1803
+ def launch_bocelli_test(url)
1804
+ @batch.submit_job({
1805
+ job_name: "bocelli-test-#{get_deploy_id}",
1806
+ job_queue: "tools-production",
1807
+ job_definition: describe_stack_resource('batch-job-bocelli-production', 'JobDefinition').stack_resource_detail.physical_resource_id,
1808
+ container_overrides: {
1809
+ environment: [
1810
+ {
1811
+ name: "BATCH_COMMAND",
1812
+ value: "test"
1813
+ },
1814
+ {
1815
+ name: "QA_HOSTNAME",
1816
+ value: url
1817
+ },
1818
+ {
1819
+ name: "BRANCH_NAME",
1820
+ value: @projects['prima']['name']
1821
+ },
1822
+ {
1823
+ name: "COMMITTER_EMAIL",
1824
+ value: @projects['prima']['committer']
1825
+ }
1826
+ ]
1827
+ }
1828
+ })
1829
+ end
1830
+
1831
+ def deploy_vianello_or_domus?
1832
+ vianello_present = !@projects['vianello'].empty? && @projects['vianello'][:name] != 'master' && !@projects['vianello'][:default_branch]
1833
+ domus_present = !@projects['domus'].empty? && @projects['domus'][:name] != 'master' && !@projects['domus'][:default_branch]
1834
+ vianello_present || domus_present
1835
+ end
1836
+
1837
+ def git_checkout_version(project, revision)
1838
+ Dir.chdir "projects/#{project}"
1839
+ exec_step "git checkout -- . && git checkout #{revision}"
1840
+ Dir.chdir "../../"
1841
+ end
1842
+
1843
+ def create_asg_stack(stack_name, tags = [])
1844
+ stack_body = IO.read('cloudformation/stacks/asg/ecs-asg-allinone.yml')
1845
+ parameters = [
1846
+ {
1847
+ parameter_key: "Environment",
1848
+ parameter_value: "qa"
1849
+ },
1850
+ {
1851
+ parameter_key: "InstanceType",
1852
+ parameter_value: "t3a.xlarge"
1853
+ },
1854
+ {
1855
+ parameter_key: "ECSClusterName",
1856
+ parameter_value: get_ecs_cluster_name
1857
+ },
1858
+ {
1859
+ parameter_key: "AMIID",
1860
+ parameter_value: @ami_id
1861
+ }
1862
+ ]
1863
+ create_stack(stack_name, stack_body, parameters, tags, @cf_role)
1864
+ end
1865
+
1866
+ def create_cluster_stack(stack_name, tags = [])
1867
+ stack_body = IO.read('cloudformation/stacks/ecs-cluster.yml')
1868
+ create_stack(stack_name, stack_body, [], tags)
1869
+ end
1870
+
1871
+ def update_cluster_stack(stack_name, tags = [])
1872
+ stack_body = IO.read('cloudformation/stacks/ecs-cluster.yml')
1873
+ update_stack(stack_name, stack_body, [], tags)
1874
+ end
1875
+
1876
+ def create_alb_stack(stack_name, role, hash, environment = 'qa')
1877
+ stack_body = IO.read('cloudformation/stacks/elb/alb-public-qa.yml')
1878
+ parameters = [
1879
+ {
1880
+ parameter_key: "Environment",
1881
+ parameter_value: environment
1882
+ },
1883
+ {
1884
+ parameter_key: "Role",
1885
+ parameter_value: role
1886
+ },
1887
+ {
1888
+ parameter_key: "EnvHash",
1889
+ parameter_value: hash
1890
+ }
1891
+ ]
1892
+ create_stack(stack_name, stack_body, parameters, [], @cf_role)
1893
+ end
1894
+
1895
+ def import_redis_crash(qa_ip_address)
1896
+ output "Importo chiavi di Redis da staging\n".yellow
1897
+
1898
+ prefixes = ['CODICI', 'fun_with_flags']
1899
+ redis_qa = Redis.new(:url => "redis://#{qa_ip_address}:6379/10")
1900
+ redis_staging = Redis.new(:url => 'redis://staging.cache-1.prima.it:6379/10')
1901
+
1902
+ prefixes.each do |prefix|
1903
+ redis_staging.keys("#{prefix}*").each do |key|
1904
+ next unless redis_qa.keys(key).empty?
1905
+ output "Importo #{key} dal Redis di staging\n".yellow
1906
+ dump_staging = redis_staging.dump key
1907
+ redis_qa.restore key, 0, dump_staging
1908
+ end
1909
+ end
1910
+ end
1911
+
1912
+ def import_dbs(ip_address)
1913
+ overrides = {
1914
+ container_overrides: [
1915
+ {
1916
+ name: 'dbrestore',
1917
+ environment: [
1918
+ {
1919
+ name: 'EC2_IP_ADDRESS',
1920
+ value: ip_address
1921
+ }
1922
+ ]
1923
+ }
1924
+ ]
1925
+ }
1926
+ resp = run_ecs_task(get_ecs_cluster_name, @import_db_task, overrides, 1)
1927
+ return resp
1928
+ end
1929
+
1930
+ def wait_for_db_import(task)
1931
+ output "Attendo che i DB vengano importati...\n".yellow
1932
+ stopped_at = nil
1933
+ sleep 15 # altrimenti non trova il task appena avviato...
1934
+ while stopped_at.nil?
1935
+ if task.tasks[0].nil?
1936
+ pp get_ecs_cluster_name
1937
+ pp task
1938
+ stop_if true, "Task di import DB lanciato, ma risposta vuota!".red
1939
+ end
1940
+ task = describe_ecs_tasks(task.tasks[0].cluster_arn, [task.tasks[0].task_arn])
1941
+ stopped_at = task.tasks[0].stopped_at unless task.tasks[0].nil?
1942
+ sleep_seconds = 10
1943
+ seconds_elapsed = 0
1944
+ while true && stopped_at.nil?
1945
+ break if seconds_elapsed >= sleep_seconds
1946
+ print '.'.yellow; STDOUT.flush
1947
+ sleep 1
1948
+ seconds_elapsed += 1
1949
+ end
1950
+ end
1951
+ print "\n"
1952
+ end
1953
+
1954
+ def get_stacks()
1955
+ envs = {}
1956
+ stack_list = stack_list()
1957
+ stack_list.each do |stack|
1958
+ unless stack.stack_name.match(/spotfleet-allinone-qa-(\w+)$/)
1959
+ env_hash = stack.stack_name.match(/qa-(\w+)$/)[0]
1960
+ envs[env_hash] = stack.tags unless envs.has_key?(env_hash) || stack.tags.empty?
1961
+ end
1962
+ end
1963
+ return stack_list, envs
1964
+ end
1965
+
1966
+ def get_clusters()
1967
+ envs = {}
1968
+ cluster_list = cluster_list()
1969
+ cluster_list.each do |stack|
1970
+ unless stack.stack_name.match(/spotfleet-allinone-qa-(\w+)$/)
1971
+ env_hash = stack.stack_name.match(/qa-(\w+)$/)[0]
1972
+ envs[env_hash] = stack.tags unless envs.has_key?(env_hash) || stack.tags.empty?
1973
+ end
1974
+ end
1975
+ return cluster_list, envs
1976
+ end
1977
+
1978
+ def hostname_pattern_priority()
1979
+ (Time.now.to_i.to_s[-4..-1].to_i + Random.rand(40000)).to_s
1980
+ end
1981
+
1982
+ def launch_mimo(env_hash)
1983
+ resp = describe_stack_resource('batch-job-mimo', 'JobDefinition')
1984
+
1985
+ @batch.submit_job({
1986
+ job_name: "mimo-#{get_deploy_id}", # required
1987
+ job_queue: "tools-production", # required
1988
+ job_definition: resp.stack_resource_detail.physical_resource_id, # required
1989
+ container_overrides: {
1990
+ environment: [
1991
+ {
1992
+ name: 'ENV_HASH',
1993
+ value: env_hash
1994
+ },
1995
+ {
1996
+ name: 'APP_ENV',
1997
+ value: 'qa'
1998
+ },
1999
+ {
2000
+ name: 'CYPRESS_BASE_URL',
2001
+ value: "https://hutch-#{env_hash}.qa.colaster.com"
2002
+ },
2003
+ {
2004
+ name: 'CYPRESS_PEANO_BASE_URL',
2005
+ value: "http://peano-#{env_hash}.qa.colaster.com:10039/quotation"
2006
+ },
2007
+ {
2008
+ name: 'CYPRESS_API_BASE_URL',
2009
+ value: "https://#{get_route53_hostname("starsky")}/graphql"
2010
+ },
2011
+ {
2012
+ name: 'QA_NAME',
2013
+ value: @git_branch
2014
+ }
2015
+ ]
2016
+ }
2017
+ })
2018
+
2019
+ output "Mimo lanciato con successo!\n".green
2020
+ end
2021
+
2022
+ def get_currently_deployed_version(stack_name)
2023
+ parameters = get_stack_parameters(stack_name)
2024
+ currently_deployed_version = nil
2025
+ parameters.each do |parameter|
2026
+ if parameter.parameter_key == "ReleaseVersion"
2027
+ currently_deployed_version = parameter.parameter_value
2028
+ end
2029
+ end
2030
+ currently_deployed_version
2031
+ end
2032
+
2033
+ def get_ami_id(stack_name)
2034
+ get_stack_parameters(stack_name).each do |param|
2035
+ if param.parameter_key == "AMIID"
2036
+ return param.parameter_value
2037
+ end
2038
+ end
2039
+ end
2040
+ end
2041
+
2042
+ def help_content
2043
+ <<-HELP
2044
+
2045
+ twig-buils
2046
+ ===========
2047
+
2048
+ Manage qa cloudformation stack creation
2049
+
2050
+ Synopsis
2051
+ --------
2052
+
2053
+ twig build #command
2054
+
2055
+ Description
2056
+ -----------
2057
+
2058
+ #command #command description
2059
+
2060
+ HELP
2061
+ end
2062
+
2063
+ args = ARGV.dup
2064
+
2065
+ if args.include?('--help')
2066
+ puts help_content
2067
+ exit
2068
+ end
2069
+
2070
+ args.delete('no-gem-update')
2071
+
2072
+ Build.new().execute!(args)