prima-twig 0.58.3 → 0.58.500

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