prima-twig 0.54.235 → 0.55.0

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