prima-twig 0.5.27 → 0.6.0

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