prima-twig 0.34.5 → 0.34.124

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,7 +5,10 @@ require_relative '../lib/prima_twig.rb'
5
5
  require_relative '../lib/prima_aws_client.rb'
6
6
  require 'colorize'
7
7
  require 'highline/import'
8
- require 'aws-sdk'
8
+ require 'aws-sdk-batch'
9
+ require 'aws-sdk-cloudformation'
10
+ require 'aws-sdk-ecs'
11
+ require 'aws-sdk-s3'
9
12
  require 'redcarpet'
10
13
  require 'mail'
11
14
  require 'erb'
@@ -55,6 +58,7 @@ class Review
55
58
  @cf = Aws::CloudFormation::Client.new
56
59
  @ecs = Aws::ECS::Client.new
57
60
  @s3 = Aws::S3::Client.new
61
+ @batch = Aws::Batch::Client.new
58
62
  @s3_bucket = "prima-artifacts-encrypted"
59
63
  end
60
64
 
@@ -94,15 +98,6 @@ class Review
94
98
  artifact = artifacts.select {|v| v[:rev] == artifact_rev}.first
95
99
 
96
100
  do_deploy! artifact_rev
97
- exec_step "terminal-notifier -message 'Deploy terminato, vuoi lanciare paparatzinger?'" if which 'terminal-notifier'
98
-
99
- confirm_message = "Vuoi lanciare paparatzinger?"
100
- launch_paparatzinger = @prima.yesno confirm_message.blue
101
-
102
- if launch_paparatzinger
103
- output "Avvio paparatzinger per gli screenshot".yellow
104
- job_name = launch_paparatzinger(artifact[:commit_msg])
105
- end
106
101
 
107
102
  mail = Mail.new do
108
103
  from 'deploy@prima.it'
@@ -118,7 +113,6 @@ class Review
118
113
  body << "Revision: [#{artifact[:rev]}](https://github.com/primait/prima/commit/#{artifact[:rev]}) del #{artifact[:created_at].strftime('%d/%m/%Y %H:%M:%S')}\n\n"
119
114
  body << "Branch: [#{artifact[:branch]}](https://github.com/primait/prima/tree/#{artifact[:branch]})\n\n"
120
115
  body << "Commit: #{commit_msg.gsub(/_/, '\_')}\n\n"
121
- body << "Screenshots (tra qualche minuto): [BrowserStack](https://www.browserstack.com/automate) (Filtrare per: \"#{get_paparatzinger_job_name(commit_msg).gsub(/_/, '\_')}\")" if launch_paparatzinger
122
116
 
123
117
  htmlBody = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new).render body
124
118
 
@@ -137,17 +131,34 @@ class Review
137
131
  opts[:user_name] = @prima.config['aws_username']
138
132
  opts[:password] = @prima.config['aws_password']
139
133
 
134
+ exec_step "git checkout master"
135
+
140
136
  mail.delivery_method(:smtp, opts)
141
137
  mail.deliver
142
138
 
143
- exec_step "git checkout master"
139
+ invalidate_prismic_cache
140
+
141
+ launch_crawler
142
+
144
143
  exec_step "terminal-notifier -message 'Deploy terminato'" if which 'terminal-notifier'
145
144
  end
146
145
 
146
+ def invalidate_prismic_cache
147
+ [
148
+ "guarantee",
149
+ "glossary",
150
+ "guide",
151
+ "faq"
152
+ ].each do |page|
153
+
154
+ exec_step "curl -X POST -H \"Content-Type: application/json\" https://www.prima.it/api/cms/update/#{page}?apikey=#{@prima.config['prima_apikey']}"
155
+ end
156
+ end
157
+
147
158
  def reload_parameters!
148
159
  artifact_rev = ''
149
160
  resp = @cf.describe_stacks({
150
- stack_name: "ecs-task-web-production"
161
+ stack_name: "ecs-task-web-vpc-production"
151
162
  })
152
163
  resp.stacks[0].parameters.each do |param|
153
164
  if param.parameter_key == 'ReleaseVersion'
@@ -176,86 +187,42 @@ class Review
176
187
  exec_step "git checkout #{artifact_rev}"
177
188
  exec_step deploy_command
178
189
 
179
- stack_name_web = 'ecs-task-web-production'
180
- stack_name_consumer = 'ecs-task-consumer-production'
181
- stack_name_cron = 'ecs-task-consumer-production'
190
+ stack_name_web = 'ecs-task-web-vpc-production'
191
+ stack_name_consumer = 'ecs-task-consumer-vpc-production'
192
+ stack_name_cron = 'ecs-task-consumer-vpc-production'
193
+ stack_name_job = 'batch-job-php-production'
182
194
  wait_for_stack_ready(stack_name_web) unless stack_ready?(stack_name_web)
183
195
  wait_for_stack_ready(stack_name_consumer) unless stack_ready?(stack_name_consumer)
184
196
  wait_for_stack_ready(stack_name_cron) unless stack_ready?(stack_name_cron)
197
+ wait_for_stack_ready(stack_name_job) unless stack_ready?(stack_name_job)
185
198
  end
186
199
 
187
200
  def get_artifacts
188
201
  artifacts = []
189
202
  resp = @s3.list_objects(bucket: @s3_bucket, prefix: 'prima')
190
203
  resp.contents.each do |l|
204
+ # aggiungiamo solo gli artefatti prodotti a partire dal branch master, riconosciuti tramite i metadata
191
205
  rev = l.key.match(/^prima\/(\w{15}).tar.gz$/).captures.first if l.key.match(/^prima\/(\w{15}).tar.gz$/)
192
206
  if rev
193
207
  object = @s3.head_object(bucket: @s3_bucket, key: l.key)
194
208
  commit_msg = ''
195
209
  commit_msg = Base64.decode64(object.metadata['commit_msg']).strip if object.metadata.has_key? 'commit_msg'
196
- artifacts << {rev: rev, created_at: object.last_modified, branch: object.metadata['branch'], commit_msg: commit_msg } if object.metadata.has_key? 'branch'
210
+ artifacts << {rev: rev, created_at: object.last_modified, branch: object.metadata['branch'], commit_msg: commit_msg } if (object.metadata.has_key? 'branch') && (object.metadata['branch'] == 'master')
197
211
  end
198
212
  end
199
213
  artifacts.sort_by { |v| v[:created_at] }.reverse
200
214
  end
201
215
 
202
- def launch_paparatzinger(job_name)
203
- @s3.get_object(
204
- response_target: '/tmp/paparatzinger_twig.yml',
205
- bucket: 'prima-deploy',
206
- key: 'paparatzinger_twig.yml')
207
-
208
- paparatzinger_config = YAML.load_file '/tmp/paparatzinger_twig.yml'
209
-
210
- uri = URI.parse(paparatzinger_config['prima_api_search_url'])
211
- body = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
212
- req = Net::HTTP::Get.new(uri)
213
- req["x-apikey"] = paparatzinger_config['prima_api_token']
214
- response = http.request req
215
- response.body
216
- end
217
-
218
- saves = JSON.parse body
216
+ def launch_crawler()
217
+ resp = describe_stack_resource('batch-job-crawler-production', 'JobDefinition')
219
218
 
220
- save_code = saves.sample['unique_identifier']
221
- url_garanzie = "https://www.prima.it/preventivo/auto/#{save_code}/garanzie?browserstack=true"
222
- job_name = get_paparatzinger_job_name(clean_commit_message(job_name))
223
-
224
- logical_resource_id = 'TaskDefinitionPaparatzinger'
225
- resp = @cf.describe_stack_resource({
226
- stack_name: 'ecs-task-paparatzinger-production',
227
- logical_resource_id: logical_resource_id
228
- })
229
-
230
- resp = @ecs.run_task({
231
- cluster: 'ecs-cluster-tools-ECSCluster-1I4THZHRXOTO5',
232
- task_definition: resp.stack_resource_detail.physical_resource_id,
233
- overrides: {
234
- container_overrides: [
235
- {
236
- name: 'paparatzinger',
237
- environment: [
238
- {
239
- name: 'JOB_NAME',
240
- value: job_name,
241
- },
242
- {
243
- name: 'VERSION',
244
- value: paparatzinger_config['version'],
245
- },
246
- {
247
- name: 'URL_GARANZIE',
248
- value: url_garanzie
249
- }
250
- ]
251
- }
252
- ]
253
- },
254
- count: 1
219
+ @batch.submit_job({
220
+ job_name: "crawler", # required
221
+ job_queue: "tools-production", # required
222
+ job_definition: resp.stack_resource_detail.physical_resource_id # required
255
223
  })
256
- output "Paparatzinger lanciato con successo. URL: #{url_garanzie}\n".green
257
224
 
258
- job_name
225
+ output "Crawler lanciato con successo!\n".green
259
226
  end
260
227
 
261
228
  end
@@ -267,10 +234,6 @@ def clean_commit_message(commit_msg)
267
234
  commit_msg[0..99]
268
235
  end
269
236
 
270
- def get_paparatzinger_job_name(job_name)
271
- job_name.gsub /[^0-9a-z]/i, '-'
272
- end
273
-
274
237
  def which(cmd)
275
238
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
276
239
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
@@ -13,40 +13,48 @@ class Release
13
13
  include Command
14
14
  include PrimaAwsClient
15
15
 
16
- def initialize
16
+ def initialize(update_gem=true)
17
17
  @prima = Prima.new
18
- output 'Controllo se ci sono aggiornamenti da fare...'
19
- exec "gem update prima-twig && twig feature #{ARGV.join ' '}" unless `gem outdated`.lines.grep(/^prima-twig \(.*\)/).empty?
20
- @cf = Aws::CloudFormation::Client.new
21
- @alb = Aws::ElasticLoadBalancingV2::Client.new
22
- @ec2 = Aws::EC2::Client.new
23
- @ecs = Aws::ECS::Client.new
24
- @batch = Aws::Batch::Client.new
25
- @s3 = Aws::S3::Client.new
26
- @asg = Aws::AutoScaling::Client.new
27
- @s3_bucket = 'prima-artifacts'
28
- @artifact_path = '/tmp/prima-artifact.zip'
29
- @import_db_task = 'arn:aws:ecs:eu-west-1:001575623345:task-definition/ecs-task-db-restore-TaskDefinitionDbRestore-4T7F5EKR6DW1:1'
18
+ if update_gem
19
+ output 'Controllo se ci sono aggiornamenti da fare (potrebbe richiedere qualche minuto)'
20
+ unless `gem update prima-twig`=="Updating installed gems\nNothing to update\n"
21
+ output 'Gemma prima-twig aggiornata'
22
+ exec "twig feature #{ARGV.join ' '}"
23
+ end
24
+ end
30
25
  @dns_record_identifier = nil
31
26
  @ecs_cluster_name = nil
32
27
  @deploy_update = false
33
28
  @projects = {
34
29
  'prima' => {},
35
- 'backoffice' => {},
36
30
  'urania' => {},
37
31
  'ermes' => {},
38
32
  'bburago' => {},
39
33
  'hal9000' => {},
40
34
  'fidaty' => {},
41
35
  'peano' => {},
42
- 'rogoreport' => {},
36
+ # 'rogoreport' => {},
43
37
  'assange' => {},
44
38
  'borat' => {},
45
- 'bolla' => {},
46
- 'crash' => {}
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' => {}
47
53
  }
48
- @stack_name_alb = 'ecs-alb-http-public-qa'
49
- @stack_name_alb_ws = 'ecs-alb-ws-public-qa'
54
+ @base_stack_name_alb = 'ecs-alb-http-public-qa-'
55
+ @base_stack_name_alb_ws = 'ecs-alb-ws-public-qa-'
56
+ @git_branch = ''
57
+ @cloudflare = Rubyflare.connect_with(ENV['CLOUDFLARE_EMAIL'], ENV['CLOUDFLARE_APIKEY'])
50
58
  end
51
59
 
52
60
  def execute!(args)
@@ -55,21 +63,30 @@ class Release
55
63
  start_feature!
56
64
  when 'finish'
57
65
  finish_feature!
58
- when 'deploy'
59
- abort('Non sei nella cartella di artemide') unless Dir.pwd.match 'artemide$'
66
+ when 'qainit'
67
+ abort('Non sei nella cartella di qainit') unless Dir.pwd.match 'qainit$' or Dir.pwd.match '/drone/src'
60
68
  if ['terminate', 'stop', 'shutdown', 'halt', 'destroy'].include? args[1]
61
- deploy_shutdown!
69
+ qainit_deploy_shutdown!
62
70
  elsif 'update' == args[1]
63
- deploy_update!
64
- elsif 'lock' == args[1]
65
- deploy_lock!
71
+ qainit_deploy_update!
66
72
  else
67
73
  if args[1]
68
- select_branches(args[1])
74
+ select_branches(args[1..-1])
69
75
  else
70
76
  select_branches
71
77
  end
72
- deploy_feature!
78
+ qainit_deploy!
79
+ end
80
+ when 'suite'
81
+ abort('Non sei nella cartella di qainit') unless Dir.pwd.match 'qainit$'
82
+ if 'deploy' == args[1]
83
+ suite_py_branches(args[2])
84
+ qainit_deploy!(true)
85
+ end
86
+ when 'deploy'
87
+ abort('Non sei nella cartella di artemide') unless Dir.pwd.match 'artemide$'
88
+ if 'lock' == args[1]
89
+ deploy_lock!
73
90
  end
74
91
  when 'aggregator'
75
92
  if 'enable' == args[1]
@@ -85,6 +102,7 @@ class Release
85
102
  end
86
103
 
87
104
  def stop_for_wrong_args
105
+ puts help_content
88
106
  stop_if true, [:wrong_args, ['start', 'finish', 'deploy', 'deploy project_name', 'deploy stop', 'deploy update', 'aggregator enable', 'aggregator disable']]
89
107
  end
90
108
 
@@ -104,10 +122,6 @@ class Release
104
122
  output 'Disable aggregator'
105
123
 
106
124
  output "Recupero le informazioni relative al puntamento dei record DNS..."
107
- cloudflare = Rubyflare.connect_with(@prima.config['cloudflare_email'], @prima.config['cloudflare_apikey'])
108
- dns_records = cloudflare.get("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records", {per_page: 100, type: 'CNAME', content: get_alb_host(@stack_name_alb)})
109
- stop_if dns_records.body[:result].empty?, "I record DNS degli aggregatori non stanno puntando ad un QA".red
110
-
111
125
  output "Recupero le informazioni sui QA attivi..."
112
126
  stack_list, envs = get_stacks()
113
127
 
@@ -119,8 +133,10 @@ class Release
119
133
  end.is_a?(Aws::CloudFormation::Types::Tag)
120
134
  aggregator_enabled
121
135
  end[0]
136
+ dns_records = @cloudflare.get("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records", {per_page: 100, type: 'CNAME', content: get_alb_host(@base_stack_name_alb + env_hash[3..8])})
137
+ stop_if dns_records.body[:result].empty?, "I record DNS degli aggregatori non stanno puntando ad un QA".red
122
138
  change_hostname_priority(env_hash, hostname_pattern_priority())
123
- dns_to_staging()
139
+ dns_to_staging(env_hash)
124
140
  else
125
141
  output 'Nessun QA trovato'.red
126
142
  exit
@@ -133,8 +149,7 @@ class Release
133
149
  output 'Enable aggregator'
134
150
 
135
151
  output 'Recupero le informazioni relative al puntamento dei record DNS...'
136
- cloudflare = Rubyflare.connect_with(@prima.config['cloudflare_email'], @prima.config['cloudflare_apikey'])
137
- dns_records = cloudflare.get('zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records', { per_page: 100, type: 'CNAME', content: 'staging.prima.it' })
152
+ dns_records = @cloudflare.get('zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records', { per_page: 100, type: 'CNAME', content: 'staging.prima.it' })
138
153
  stop_if dns_records.body[:result].empty?, "I record DNS degli aggregatori stanno gia' puntando ad un QA".red
139
154
 
140
155
  output "Recupero le informazioni sui QA attivi..."
@@ -164,7 +179,7 @@ class Release
164
179
  dns_records.body[:result].each do |dns|
165
180
  if dns[:name] =~ /^\w+\-\w+\-staging\.prima\.it$/
166
181
  output "Changing #{dns[:name]} DNS record"
167
- cloudflare.put("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records/#{dns[:id]}", {type: 'CNAME', name: dns[:name], content: get_alb_host(@stack_name_alb), proxied: true, ttl: 1})
182
+ @cloudflare.put("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records/#{dns[:id]}", {type: 'CNAME', name: dns[:name], content: get_alb_host(@base_stack_name_alb + env_hash[3..8]), proxied: true, ttl: 1})
168
183
  end
169
184
  end
170
185
 
@@ -221,14 +236,13 @@ class Release
221
236
  wait_for_stack_ready(stack_name_web) unless stack_ready?(stack_name_web)
222
237
  end
223
238
 
224
- def dns_to_staging
239
+ def dns_to_staging(env_hash)
225
240
  output "Recupero le informazioni relative al puntamento dei record DNS..."
226
- cloudflare = Rubyflare.connect_with(@prima.config['cloudflare_email'], @prima.config['cloudflare_apikey'])
227
- dns_records = cloudflare.get("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records", {per_page: 100, type: 'CNAME', content: get_alb_host(@stack_name_alb)})
241
+ dns_records = @cloudflare.get("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records", {per_page: 100, type: 'CNAME', content: get_alb_host(@base_stack_name_alb + env_hash[3..8])})
228
242
  dns_records.body[:result].each do |dns|
229
243
  if dns[:name] =~ /^\w+\-\w+\-staging\.prima\.it$/
230
244
  output "Changing #{dns[:name]} DNS record"
231
- cloudflare.put("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records/#{dns[:id]}", {type: 'CNAME', name: dns[:name], content: 'staging.prima.it', proxied: true, ttl: 1})
245
+ @cloudflare.put("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records/#{dns[:id]}", {type: 'CNAME', name: dns[:name], content: 'staging.prima.it', proxied: true, ttl: 1})
232
246
  end
233
247
  end
234
248
  end
@@ -296,7 +310,7 @@ class Release
296
310
  end.is_a?(Aws::CloudFormation::Types::Tag)
297
311
 
298
312
  if aggregator_enabled
299
- dns_to_staging()
313
+ dns_to_staging(env_hash)
300
314
  end
301
315
 
302
316
  # Se non ha finito di cancellare le altre non si puo' cancellare il cluster
@@ -311,8 +325,8 @@ class Release
311
325
  end
312
326
 
313
327
  delete_stack(cluster_stack_name)
314
- delete_stack(@stack_name_alb) if envs.length < 2
315
- delete_stack(@stack_name_alb_ws) if envs.length < 2
328
+ delete_stack(@base_stack_name_alb + env_hash[3..8])
329
+ delete_stack(@base_stack_name_alb_ws + env_hash[3..8])
316
330
  output "Finito!".green
317
331
  end
318
332
 
@@ -323,7 +337,7 @@ class Release
323
337
  @deploy_update = true
324
338
 
325
339
  output "Recupero le informazioni sui QA attivi..."
326
- stack_list, envs = get_stacks()
340
+ stack_list, envs = get_clusters()
327
341
 
328
342
  env_hash = nil
329
343
  unless envs.empty?
@@ -333,7 +347,7 @@ class Release
333
347
  envs.each do |key, env|
334
348
  title = ""
335
349
  env.each do |e|
336
- title << "\n#{e.key.upcase}: #{e.value}"
350
+ title << "#{e.value}" if e.key == 'qainit'
337
351
  end
338
352
  msg = "#{@prima.reduce_size(title, 1000)}".light_blue
339
353
  menu.choice(msg) { key }
@@ -394,886 +408,210 @@ class Release
394
408
  output "Finito!".green
395
409
  end
396
410
 
397
- def deploy_feature!
398
- `git pull && git submodule init && git submodule update`
399
- if deploy_crash?
400
- deploy_id = Digest::MD5.hexdigest(
401
- @projects["prima"][:name] +
402
- @projects["backoffice"][:name] +
403
- @projects["urania"][:name] +
404
- @projects["ermes"][:name] +
405
- @projects["bburago"][:name] +
406
- @projects["hal9000"][:name] +
407
- @projects["fidaty"][:name] +
408
- @projects["peano"][:name] +
409
- @projects["rogoreport"][:name] +
410
- @projects["assange"][:name] +
411
- @projects["borat"][:name] +
412
- @projects["bolla"][:name] +
413
- @projects['crash'][:name]
414
- )
415
- else
416
- deploy_id = Digest::MD5.hexdigest(
417
- @projects["prima"][:name] +
418
- @projects["backoffice"][:name] +
419
- @projects["urania"][:name] +
420
- @projects["ermes"][:name] +
421
- @projects["bburago"][:name] +
422
- @projects["hal9000"][:name] +
423
- @projects["fidaty"][:name] +
424
- @projects["peano"][:name] +
425
- @projects["rogoreport"][:name] +
426
- @projects["assange"][:name] +
427
- @projects["borat"][:name] +
428
- @projects["bolla"][:name]
429
- )
411
+ def get_default_branch_name(projects)
412
+ projects.each_key do |project|
413
+ return projects[project]['name'] if not projects[project]['default_branch']
430
414
  end
431
- @dns_record_identifier = deploy_id
432
- hostname_pattern_priority = hostname_pattern_priority()
433
- tags = [
434
- {
435
- key: "prima",
436
- value: @projects["prima"][:name]
437
- },
438
- {
439
- key: "urania",
440
- value: @projects["urania"][:name]
441
- },
442
- {
443
- key: "backoffice",
444
- value: @projects["backoffice"][:name]
445
- },
446
- {
447
- key: "ermes",
448
- value: @projects["ermes"][:name]
449
- },
450
- {
451
- key: "bburago",
452
- value: @projects["bburago"][:name]
453
- },
454
- {
455
- key: "hal9000",
456
- value: @projects["hal9000"][:name]
457
- },
458
- {
459
- key: "fidaty",
460
- value: @projects["fidaty"][:name]
461
- },
462
- {
463
- key: "hostname_pattern_priority",
464
- value: hostname_pattern_priority
465
- },
466
- {
467
- key: "peano",
468
- value: @projects["peano"][:name]
469
- },
470
- {
471
- key: "rogoreport",
472
- value: @projects["rogoreport"][:name]
473
- },
474
- {
475
- key: "assange",
476
- value: @projects["assange"][:name]
477
- },
478
- {
479
- key: "borat",
480
- value: @projects["borat"][:name]
481
- },
482
- {
483
- key: "bolla",
484
- value: @projects["bolla"][:name]
485
- }
486
- ]
487
- tags << { key: 'crash', value: @projects['crash'][:name] } if deploy_crash?
488
-
489
- cluster_stack_name = "ecs-cluster-qa-#{deploy_id}"
415
+ end
490
416
 
491
- if stack_exists?(cluster_stack_name)
492
- tags = get_stack_tags(cluster_stack_name)
493
- hostname_pattern_priority = tags.detect do |tag|
494
- tag.key == 'hostname_pattern_priority'
495
- end.value
496
- end
417
+ def suite_py_branches(args_json)
418
+ arg_projects = JSON.parse(args_json)
497
419
 
498
- create_cluster_stack(cluster_stack_name, tags) unless stack_exists?(cluster_stack_name)
499
- wait_for_stack_ready(cluster_stack_name) unless stack_ready?(cluster_stack_name)
500
-
501
- create_alb_stack(@stack_name_alb, "http") unless stack_exists?(@stack_name_alb)
502
- create_alb_stack(@stack_name_alb_ws, "websocket") unless stack_exists?(@stack_name_alb_ws)
503
-
504
- resp = @cf.describe_stack_resource({stack_name: cluster_stack_name, logical_resource_id: 'ECSCluster'})
505
- @ecs_cluster_name = resp.stack_resource_detail.physical_resource_id
506
-
507
- asg_stack_name = "ecs-asg-allinone-qa-#{deploy_id}"
508
- create_asg_stack(asg_stack_name, tags) unless stack_exists?(asg_stack_name)
509
-
510
- stack_name_db = "ecs-task-db-qa-#{deploy_id}"
511
- stack_body = IO.read('cloudformation/stacks/task/db.yml')
512
- parameters = [
513
- {
514
- parameter_key: "Environment",
515
- parameter_value: "qa"
516
- },
517
- {
518
- parameter_key: "ECSClusterName",
519
- parameter_value: @ecs_cluster_name
520
- }
521
- ]
522
- create_stack(stack_name_db, stack_body, parameters, tags) unless stack_exists?(stack_name_db)
523
-
524
- create_prima_artifact(@projects["prima"][:revision], @projects["prima"][:name], deploy_id) # unless artifact_exists?('prima-artifacts-encrypted', "prima/#{@projects["prima"][:revision]}-#{deploy_id}.tar.gz")
525
- create_crash_artifact(@projects['crash'][:revision], deploy_id) unless !deploy_crash? || artifact_exists?('prima-artifacts-encrypted', "microservices/crash/#{@projects['crash'][:revision]}-#{deploy_id}-qa.tar.gz")
526
- create_urania_artifact(@projects["urania"][:revision]) unless artifact_exists?('prima-artifacts-encrypted', "microservices/urania/#{@projects["urania"][:revision]}-qa.tar.gz")
527
- create_ermes_artifact(@projects["ermes"][:revision], deploy_id) unless artifact_exists?('prima-artifacts-encrypted', "microservices/ermes/#{@projects["ermes"][:revision]}-#{deploy_id}-qa.tar.gz")
528
- create_bburago_artifact(@projects["bburago"][:revision]) unless artifact_exists?('prima-artifacts-encrypted', "microservices/bburago/#{@projects["bburago"][:revision]}-qa.tar.gz")
529
- create_hal9000_artifact(@projects["hal9000"][:revision]) unless artifact_exists?('prima-artifacts-encrypted', "microservices/hal9000/#{@projects["hal9000"][:revision]}-qa.tar.gz")
530
- create_fidaty_artifact(@projects["fidaty"][:revision], deploy_id) unless artifact_exists?('prima-artifacts-encrypted', "microservices/fidaty/#{@projects["fidaty"][:revision]}-#{deploy_id}-qa.tar.gz")
531
- create_backoffice_artifact(@projects["backoffice"][:revision], deploy_id) unless artifact_exists?('prima-artifacts', "backoffice/#{@projects["backoffice"][:revision]}-#{deploy_id}.zip")
532
- create_peano_artifact(@projects["peano"][:revision], deploy_id) unless artifact_exists?('prima-artifacts-encrypted', "microservices/peano/#{@projects["peano"][:revision]}-#{deploy_id}-qa.tar.gz")
533
- create_rogoreport_artifact(@projects["rogoreport"][:revision], deploy_id) unless artifact_exists?('prima-artifacts-encrypted', "microservices/rogoreport/rogoreport_qa-#{@projects["rogoreport"][:revision]}-#{deploy_id}-qa.tar.gz")
534
- create_assange_artifact(@projects["assange"][:revision], deploy_id) unless artifact_exists?('prima-artifacts-encrypted', "microservices/assange/#{@projects["assange"][:revision]}-#{deploy_id}-qa.tar.gz")
535
- create_borat_artifact(@projects["borat"][:revision], deploy_id) unless artifact_exists?('prima-artifacts-encrypted', "microservices/borat/#{@projects["borat"][:revision]}-#{deploy_id}-qa.tar.gz")
536
- create_bolla_artifact(@projects["bolla"][:revision], deploy_id) unless artifact_exists?('prima-artifacts-encrypted', "microservices/bolla/#{@projects["bolla"][:revision]}-#{deploy_id}-qa-migrator.tar.gz")
537
-
538
- wait_for_stack_ready(stack_name_db) unless stack_ready?(stack_name_db)
539
- import_dbs(ec2_ip_address(asg_stack_name)) unless stack_exists?("ecs-task-web-qa-#{deploy_id}")
540
-
541
- import_redis_crash(ec2_ip_address(asg_stack_name)) if deploy_crash? && !stack_exists?("ecs-task-web-qa-#{deploy_id}")
542
-
543
- wait_for_stack_ready(@stack_name_alb) unless stack_ready?(@stack_name_alb)
544
- wait_for_stack_ready(@stack_name_alb_ws) unless stack_ready?(@stack_name_alb_ws)
545
-
546
- stack_name_route53 = "ecs-route53-qa-#{deploy_id}"
547
- stack_body = IO.read('cloudformation/stacks/route53/qa.yml')
548
- parameters = [
549
- {
550
- parameter_key: "DnsRecordIdentifier",
551
- parameter_value: @dns_record_identifier
552
- },
553
- {
554
- parameter_key: "PrimaElbHostname",
555
- parameter_value: get_alb_host(@stack_name_alb)
556
- },
557
- {
558
- parameter_key: "BackofficeElbHostname",
559
- parameter_value: get_alb_host(@stack_name_alb)
560
- },
561
- {
562
- parameter_key: "UraniaIp",
563
- parameter_value: ec2_ip_address(asg_stack_name)
564
- },
565
- {
566
- parameter_key: "BburagoIp",
567
- parameter_value: ec2_ip_address(asg_stack_name)
568
- },
569
- {
570
- parameter_key: "Hal9000Ip",
571
- parameter_value: ec2_ip_address(asg_stack_name)
572
- },
573
- {
574
- parameter_key: "FidatyIp",
575
- parameter_value: ec2_ip_address(asg_stack_name)
576
- },
577
- {
578
- parameter_key: "PeanoIp",
579
- parameter_value: ec2_ip_address(asg_stack_name)
580
- },
581
- {
582
- parameter_key: "ErmesIp",
583
- parameter_value: ec2_ip_address(asg_stack_name)
584
- },
585
- {
586
- parameter_key: "RedisIp",
587
- parameter_value: ec2_ip_address(asg_stack_name)
588
- },
589
- {
590
- parameter_key: "AssangeElbHostname",
591
- parameter_value: get_alb_host(@stack_name_alb)
592
- },
593
- {
594
- parameter_key: "BoratElbHostname",
595
- parameter_value: get_alb_host(@stack_name_alb_ws)
596
- },
597
- {
598
- parameter_key: 'CrashElbHostname',
599
- parameter_value: get_alb_host(@stack_name_alb_ws)
600
- }
601
- ]
602
-
603
- create_stack(stack_name_route53, stack_body, parameters, tags) unless stack_exists?(stack_name_route53)
604
- wait_for_stack_ready(stack_name_route53) unless stack_ready?(stack_name_route53)
605
-
606
- stack_name_urania = "ecs-task-urania-qa-#{deploy_id}"
607
- git_checkout_version('urania', @projects["urania"][:revision])
608
- stack_body = YAML.load_file('projects/urania/deploy/task.yml')
609
- stack_body['Resources']['ECSServiceUrania']['Properties'].reject!{ |k| ['LoadBalancers', 'Role'].include?(k) }
610
- stack_body = stack_body.to_yaml
611
- parameters = [
612
- {
613
- parameter_key: "Environment",
614
- parameter_value: "qa"
615
- },
616
- {
617
- parameter_key: "ReleaseVersion",
618
- parameter_value: @projects["urania"][:revision]
619
- },
620
- {
621
- parameter_key: "TaskDesiredCount",
622
- parameter_value: "1"
623
- },
624
- {
625
- parameter_key: "ECSClusterName",
626
- parameter_value: @ecs_cluster_name
627
- },
628
- {
629
- parameter_key: "ALBShortName",
630
- parameter_value: "urania-qa-#{deploy_id}"[0..31]
631
- },
632
- {
633
- parameter_key: "HostnamePattern",
634
- parameter_value: "urania-#{@dns_record_identifier}.qa.colaster.com"
635
- },
636
- {
637
- parameter_key: "HostnamePatternPriority",
638
- parameter_value: hostname_pattern_priority
639
- }
640
- ]
641
- if stack_exists?(stack_name_urania)
642
- cur_version = get_currently_deployed_version(stack_name_urania)
643
- update_stack(stack_name_urania, stack_body, parameters, tags) unless cur_version.include?(@projects["urania"][:revision])
644
- else
645
- create_stack(stack_name_urania, stack_body, parameters, tags)
646
- end
420
+ @projects.merge!(arg_projects)
647
421
 
648
- stack_name_ermes = "ecs-task-ermes-qa-#{deploy_id}"
649
- git_checkout_version('ermes', @projects["ermes"][:revision])
650
- stack_body = YAML.load_file('projects/ermes/deploy/task.yml')
651
- stack_body['Resources']['ECSServiceErmes']['Properties'].reject!{ |k| ['LoadBalancers', 'Role'].include?(k) }
652
- stack_body = stack_body.to_yaml
653
- parameters = [
654
- {
655
- parameter_key: "Environment",
656
- parameter_value: "qa"
657
- },
658
- {
659
- parameter_key: "ReleaseVersion",
660
- parameter_value: "#{@projects['ermes'][:revision]}-#{deploy_id}"
661
- },
662
- {
663
- parameter_key: "TaskDesiredCount",
664
- parameter_value: "1"
665
- },
666
- {
667
- parameter_key: "ECSClusterName",
668
- parameter_value: @ecs_cluster_name
669
- },
670
- {
671
- parameter_key: "ALBShortName",
672
- parameter_value: "ermes-qa-#{deploy_id}"[0..31]
673
- },
674
- {
675
- parameter_key: "HostnamePattern",
676
- parameter_value: "ermes-#{@dns_record_identifier}.qa.colaster.com"
677
- },
678
- {
679
- parameter_key: "HostnamePatternPriority",
680
- parameter_value: hostname_pattern_priority
681
- }
682
- ]
683
- if stack_exists?(stack_name_ermes)
684
- cur_version = get_currently_deployed_version(stack_name_ermes)
685
- update_stack(stack_name_ermes, stack_body, parameters, tags) unless cur_version.include?(@projects["ermes"][:revision])
686
- else
687
- create_stack(stack_name_ermes, stack_body, parameters, tags)
422
+ @projects.each_key do |project|
423
+ if @projects[project].empty?
424
+ @projects[project] = choose_branch_to_deploy(project, true)
425
+ end
688
426
  end
427
+ end
689
428
 
690
- stack_name_bburago = "ecs-task-bburago-qa-#{deploy_id}"
691
- git_checkout_version('bburago', @projects["bburago"][:revision])
692
- stack_body = YAML.load_file('projects/bburago/deploy/task.yml')
693
- stack_body['Resources']['ECSServiceBburago']['Properties'].reject!{ |k| ['LoadBalancers', 'Role'].include?(k) }
694
- stack_body = stack_body.to_yaml
695
- parameters = [
696
- {
697
- parameter_key: "Environment",
698
- parameter_value: "qa"
699
- },
700
- {
701
- parameter_key: "ReleaseVersion",
702
- parameter_value: @projects["bburago"][:revision]
703
- },
704
- {
705
- parameter_key: "ECSClusterName",
706
- parameter_value: @ecs_cluster_name
707
- },
708
- {
709
- parameter_key: "TaskDesiredCount",
710
- parameter_value: "1"
711
- },
712
- {
713
- parameter_key: "ALBShortName",
714
- parameter_value: "bburago-qa-#{deploy_id}"[0..31]
715
- },
716
- {
717
- parameter_key: "HostnamePattern",
718
- parameter_value: "bburago-#{@dns_record_identifier}.qa.colaster.com"
719
- },
720
- {
721
- parameter_key: "HostnamePatternPriority",
722
- parameter_value: hostname_pattern_priority
723
- }
724
- ]
725
- if stack_exists?(stack_name_bburago)
726
- cur_version = get_currently_deployed_version(stack_name_bburago)
727
- update_stack(stack_name_bburago, stack_body, parameters, tags) unless cur_version.include?(@projects["bburago"][:revision])
728
- else
729
- create_stack(stack_name_bburago, stack_body, parameters, tags)
730
- end
429
+ def get_git_user()
430
+ `git config user.name`.gsub(/[^A-Za-z]/, '').gsub("\n", '')
431
+ end
731
432
 
732
- stack_name_hal9000 = "ecs-task-hal9000-qa-#{deploy_id}"
733
- git_checkout_version('hal9000', @projects["hal9000"][:revision])
734
- stack_body = YAML.load_file('projects/hal9000/deploy/task.yml')
735
- stack_body['Resources']['ECSServiceHal9000']['Properties'].reject!{ |k| ['LoadBalancers', 'Role'].include?(k) }
736
- stack_body = stack_body.to_yaml
737
- parameters = [
738
- {
739
- parameter_key: "Environment",
740
- parameter_value: "qa"
741
- },
742
- {
743
- parameter_key: "ReleaseVersion",
744
- parameter_value: @projects["hal9000"][:revision]
745
- },
746
- {
747
- parameter_key: "ECSClusterName",
748
- parameter_value: @ecs_cluster_name
749
- },
750
- {
751
- parameter_key: "TaskDesiredCount",
752
- parameter_value: "1"
753
- },
754
- {
755
- parameter_key: "ALBShortName",
756
- parameter_value: "hal9000-qa-#{deploy_id}"[0..31]
757
- },
758
- {
759
- parameter_key: "HostnamePattern",
760
- parameter_value: "hal9000-#{@dns_record_identifier}.qa.colaster.com"
761
- },
762
- {
763
- parameter_key: "HostnamePatternPriority",
764
- parameter_value: hostname_pattern_priority
765
- }
766
- ]
767
- if stack_exists?(stack_name_hal9000)
768
- cur_version = get_currently_deployed_version(stack_name_hal9000)
769
- update_stack(stack_name_hal9000, stack_body, parameters, tags) unless cur_version.include?(@projects["hal9000"][:revision])
770
- else
771
- create_stack(stack_name_hal9000, stack_body, parameters, tags)
772
- end
433
+ def get_git_mail()
434
+ `git config user.email`.gsub("\n", '')
435
+ end
773
436
 
774
- stack_name_fidaty = "ecs-task-fidaty-qa-#{deploy_id}"
775
- git_checkout_version('fidaty', @projects["fidaty"][:revision])
776
- stack_body = YAML.load_file('projects/fidaty/deploy/task.yml')
777
- stack_body['Resources']['ECSServiceFidaty']['Properties'].reject!{ |k| ['LoadBalancers', 'Role'].include?(k) }
778
- stack_body = stack_body.to_yaml
779
- parameters = [
780
- {
781
- parameter_key: "Environment",
782
- parameter_value: "qa"
783
- },
784
- {
785
- parameter_key: "ReleaseVersion",
786
- parameter_value: "#{@projects["fidaty"][:revision]}-#{deploy_id}"
787
- },
788
- {
789
- parameter_key: "ECSClusterName",
790
- parameter_value: @ecs_cluster_name
791
- },
792
- {
793
- parameter_key: "TaskDesiredCount",
794
- parameter_value: "1"
795
- },
796
- {
797
- parameter_key: "ALBShortName",
798
- parameter_value: "fidaty-qa-#{deploy_id}"[0..31]
799
- },
800
- {
801
- parameter_key: "HostnamePattern",
802
- parameter_value: "fidaty-#{@dns_record_identifier}.qa.colaster.com"
803
- },
804
- {
805
- parameter_key: "HostnamePatternPriority",
806
- parameter_value: hostname_pattern_priority
807
- }
808
- ]
809
- if stack_exists?(stack_name_fidaty)
810
- cur_version = get_currently_deployed_version(stack_name_fidaty)
811
- update_stack(stack_name_fidaty, stack_body, parameters, tags) unless cur_version.include?(@projects["fidaty"][:revision])
812
- else
813
- create_stack(stack_name_fidaty, stack_body, parameters, tags)
814
- end
437
+ def qainit_deploy!(quiet = false)
438
+ `git checkout master && git pull && git submodule update --init --recursive && git remote prune origin`
815
439
 
816
- stack_name_peano = "ecs-task-peano-qa-#{deploy_id}"
817
- git_checkout_version('peano', @projects["peano"][:revision])
818
- stack_body = YAML.load_file('projects/peano/deploy/task.yml')
819
- stack_body['Resources']['ECSServicePeano']['Properties'].reject!{ |k| ['LoadBalancers', 'Role'].include?(k) }
820
- stack_body = stack_body.to_yaml
821
- parameters = [
822
- {
823
- parameter_key: "Environment",
824
- parameter_value: "qa"
825
- },
826
- {
827
- parameter_key: "ReleaseVersion",
828
- parameter_value: "#{@projects['peano'][:revision]}-#{deploy_id}"
829
- },
830
- {
831
- parameter_key: "ECSClusterName",
832
- parameter_value: @ecs_cluster_name
833
- },
834
- {
835
- parameter_key: "TaskDesiredCount",
836
- parameter_value: "1"
837
- },
838
- {
839
- parameter_key: "ALBShortName",
840
- parameter_value: "peano-qa-#{deploy_id}"[0..31]
841
- },
842
- {
843
- parameter_key: "HostnamePattern",
844
- parameter_value: "peano-#{@dns_record_identifier}.qa.colaster.com"
845
- },
846
- {
847
- parameter_key: "HostnamePatternPriority",
848
- parameter_value: hostname_pattern_priority
849
- }
850
- ]
851
- if stack_exists?(stack_name_peano)
852
- cur_version = get_currently_deployed_version(stack_name_peano)
853
- update_stack(stack_name_peano, stack_body, parameters, tags) unless cur_version.include?(@projects["peano"][:revision])
854
- else
855
- create_stack(stack_name_peano, stack_body, parameters, tags)
440
+ `git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D`
441
+
442
+ default_name = get_default_branch_name @projects
443
+ feature_number = ''
444
+ unless quiet
445
+ output "Inserisci la feature a cui si riferisce il QA: [#{default_name}]".cyan
446
+ feature_number = String(STDIN.gets.chomp)
856
447
  end
448
+ feature_number = default_name if feature_number.empty?
449
+ branch_name = get_git_user + '_' + feature_number
857
450
 
858
- stack_name_rogoreport = "ecs-task-rogoreport-qa-#{deploy_id}"
859
- git_checkout_version('rogoreport', @projects["rogoreport"][:revision])
860
- stack_body = IO.read('projects/rogoreport/deploy/task.yml')
861
- parameters = [
862
- {
863
- parameter_key: "Environment",
864
- parameter_value: "qa"
865
- },
866
- {
867
- parameter_key: "ReleaseVersion",
868
- parameter_value: "#{@projects["rogoreport"][:revision]}-#{deploy_id}"
869
- },
870
- {
871
- parameter_key: "ReleaseName",
872
- parameter_value: "rogoreport_qa"
873
- },
874
- {
875
- parameter_key: "ECSClusterName",
876
- parameter_value: @ecs_cluster_name
877
- }
878
- ]
879
- if stack_exists?(stack_name_rogoreport)
880
- cur_version = get_currently_deployed_version(stack_name_rogoreport)
881
- update_stack(stack_name_rogoreport, stack_body, parameters, tags) unless cur_version.include?(@projects["rogoreport"][:revision])
451
+ if `git branch -l | grep #{branch_name}`.size > 0
452
+ `git checkout #{branch_name} && git pull`
882
453
  else
883
- create_stack(stack_name_rogoreport, stack_body, parameters, tags)
454
+ `git checkout -b #{branch_name}`
455
+ end
456
+
457
+ @git_branch = branch_name
458
+
459
+ File.open('branch_names', 'w') { |file| file.write(JSON.generate(@projects)) }
460
+
461
+ update_drone_yml!
462
+
463
+ `git add projects && \
464
+ git add branch_names .drone.yml && \
465
+ git commit -m '#{branch_name}' && \
466
+ git push -f --set-upstream origin #{branch_name} && \
467
+ git checkout master`
468
+ end
469
+
470
+ def qainit_deploy_update!
471
+ `git checkout master && git pull`
472
+ # cancelliamo tutti i branch che non sono più sul repo remoto
473
+ `git fetch -p && for branch in \`git branch -vv | grep ': gone]' | awk '{print $1}'\`; do git branch -D $branch; done`
474
+ # leggiamo i nomi dei branch superstiti
475
+ former_branches = `git branch -a | grep remotes/ | grep -v HEAD | sed 's/ remotes\\/origin\\///g'`.split "\n"
476
+ git_user = get_git_user
477
+ # stampiamo la lista
478
+ chosen_branch = choose do |menu|
479
+ menu.prompt = "Scegli il QA che vuoi aggiornare: ".cyan
480
+ menu.shell = true
481
+ former_branches.delete('master')
482
+ former_branches.each_with_index do |branch, index|
483
+ msg = index.odd? ? branch.white : branch.light_yellow # uno bianco e uno giallo alternati
484
+ msg = branch.start_with?(git_user) ? msg.on_blue : msg.on_black # i branch creati da chi lancia l'update sono su sfondo più chiaro
485
+ menu.choice(msg) { branch }
486
+ end
884
487
  end
488
+ # checkout master, checkout branch, pull branch
489
+ `git checkout master && git checkout #{chosen_branch} && git pull`
885
490
 
886
- stack_name_assange = "ecs-task-assange-qa-#{deploy_id}"
887
- git_checkout_version('assange', @projects["assange"][:revision])
888
- stack_body = IO.read('projects/assange/deploy/task.yml')
889
- parameters = [
890
- {
891
- parameter_key: "Environment",
892
- parameter_value: "qa"
893
- },
894
- {
895
- parameter_key: "ReleaseVersion",
896
- parameter_value: "#{@projects["assange"][:revision]}-#{deploy_id}"
897
- },
898
- {
899
- parameter_key: "ECSClusterName",
900
- parameter_value: @ecs_cluster_name
901
- },
902
- {
903
- parameter_key: "TaskDesiredCount",
904
- parameter_value: "1"
905
- },
906
- {
907
- parameter_key: "ALBShortName",
908
- parameter_value: "assange-qa-#{deploy_id}"[0..31]
909
- },
910
- {
911
- parameter_key: "HostnamePattern",
912
- parameter_value: "assange-#{@dns_record_identifier}.qa.colaster.com"
913
- },
914
- {
915
- parameter_key: "HostnamePatternPriority",
916
- parameter_value: (hostname_pattern_priority.to_i + 20).to_s
917
- }
918
- ]
919
- if stack_exists?(stack_name_assange)
920
- cur_version = get_currently_deployed_version(stack_name_assange)
921
- update_stack(stack_name_assange, stack_body, parameters, tags) unless cur_version.include?(@projects["assange"][:revision])
922
- else
923
- create_stack(stack_name_assange, stack_body, parameters, tags)
491
+ # aggiornare il commit (revision a cui fa riferimento)
492
+
493
+ # leggo il file branch_names / recupero i nomi dei branch / riscrivo tutto
494
+ projects = ''
495
+ File.open('branch_names', 'r') do |file|
496
+ file.each_line do |line|
497
+ projects = JSON.parse(line)
498
+ end
924
499
  end
925
500
 
926
- stack_name_borat = "ecs-task-borat-qa-#{deploy_id}"
927
- git_checkout_version('borat', @projects["borat"][:revision])
928
- stack_body = IO.read('projects/borat/deploy/task.yml')
929
- parameters = [
930
- {
931
- parameter_key: "Environment",
932
- parameter_value: "qa"
933
- },
934
- {
935
- parameter_key: "ReleaseVersion",
936
- parameter_value: "#{@projects["borat"][:revision]}-#{deploy_id}"
937
- },
938
- {
939
- parameter_key: "ECSClusterName",
940
- parameter_value: @ecs_cluster_name
941
- },
942
- {
943
- parameter_key: "TaskDesiredCount",
944
- parameter_value: "1"
945
- },
946
- {
947
- parameter_key: "ALBShortName",
948
- parameter_value: "borat-qa-#{deploy_id}"[0..31]
949
- },
950
- {
951
- parameter_key: "HostnamePattern",
952
- parameter_value: "backoffice-#{@dns_record_identifier}.qa.colaster.com"
953
- },
954
- {
955
- parameter_key: "HostnamePatternPriority",
956
- parameter_value: (hostname_pattern_priority.to_i + 30).to_s
957
- }
958
- ]
959
- if stack_exists?(stack_name_borat)
960
- cur_version = get_currently_deployed_version(stack_name_borat)
961
- update_stack(stack_name_borat, stack_body, parameters, tags) unless cur_version.include?(@projects["borat"][:revision])
962
- else
963
- create_stack(stack_name_borat, stack_body, parameters, tags)
501
+ projects.each do |key, project|
502
+ @projects[key] = select_branch_to_deploy(key, project['name'])
503
+ @projects[key]['default_branch'] = project['default_branch']
964
504
  end
965
505
 
966
- git_checkout_version('backoffice', @projects["backoffice"][:revision])
967
- stack_name_backoffice = "ecs-task-backoffice-qa-#{deploy_id}"
968
- stack_body = IO.read('projects/backoffice/deploy/task.yml')
969
- parameters = [
970
- {
971
- parameter_key: "Environment",
972
- parameter_value: "qa"
973
- },
974
- {
975
- parameter_key: "ReleaseVersion",
976
- parameter_value: "#{@projects["backoffice"][:revision]}-#{deploy_id}"
977
- },
978
- {
979
- parameter_key: "TaskDesiredCount",
980
- parameter_value: "1"
981
- },
982
- {
983
- parameter_key: "ECSClusterName",
984
- parameter_value: @ecs_cluster_name
985
- },
986
- {
987
- parameter_key: "ALBShortName",
988
- parameter_value: "backoffice-qa-#{deploy_id}"[0..31]
989
- },
990
- {
991
- parameter_key: "HostnamePattern",
992
- parameter_value: "backoffice-legacy-#{@dns_record_identifier}.qa.colaster.com"
993
- },
994
- {
995
- parameter_key: "HostnamePatternPriority",
996
- parameter_value: (hostname_pattern_priority.to_i + 10).to_s
997
- }
998
- ]
999
- if stack_exists?(stack_name_backoffice)
1000
- cur_version = get_currently_deployed_version(stack_name_backoffice)
1001
- update_stack(stack_name_backoffice, stack_body, parameters, tags) unless cur_version.include?(@projects["backoffice"][:revision])
506
+ File.open('branch_names', 'w') { |file| file.write(JSON.generate(@projects)) }
507
+
508
+ update_drone_yml!
509
+
510
+ `git add branch_names .drone.yml`
511
+ `git commit -m 'update'`
512
+ `git push && git checkout master`
513
+ end
514
+
515
+ def qainit_deploy_shutdown!(selection = nil)
516
+ `git checkout master && git pull && git remote prune origin`
517
+ # leggiamo i nomi dei branch
518
+ former_branches = `git branch -a | grep remotes/ | grep -v HEAD | sed 's/ remotes\\/origin\\///g'`.split "\n"
519
+ if selection.nil?
520
+ # stampiamo la lista
521
+ chosen_branch = choose do |menu|
522
+ menu.prompt = "Scegli il QA che vuoi spegnere: ".cyan
523
+ menu.shell = true
524
+ git_user = get_git_user
525
+ former_branches.delete('master')
526
+ former_branches.each_with_index do |branch, index|
527
+ msg = index.odd? ? branch.white : branch.light_yellow # uno bianco e uno giallo alternati
528
+ msg = branch.start_with?(git_user) ? msg.on_blue : msg.on_black # i branch creati da chi lancia l'update sono su sfondo blu
529
+ menu.choice(msg) { branch }
530
+ end
531
+ end
1002
532
  else
1003
- create_stack(stack_name_backoffice, stack_body, parameters, tags)
533
+ chosen_branch = selection
1004
534
  end
535
+ # checkout master, checkout branch, pull branch, push sul branch con commit vuoto
536
+ `git checkout master && git checkout #{chosen_branch} && git pull`
537
+ `git commit --allow-empty -m 'shutdown' && git push && git checkout master`
538
+ end
1005
539
 
1006
- if deploy_crash?
1007
- git_checkout_version('crash', @projects['crash'][:revision])
1008
- stack_name_crash = "ecs-task-crash-qa-#{deploy_id}"
1009
- stack_body = IO.read('projects/crash/deploy/task.yml')
1010
- parameters = [
1011
- {
1012
- parameter_key: 'Environment',
1013
- parameter_value: 'qa'
1014
- },
1015
- {
1016
- parameter_key: 'ReleaseVersion',
1017
- parameter_value: "#{@projects['crash'][:revision]}-#{deploy_id}"
1018
- },
1019
- {
1020
- parameter_key: 'TaskDesiredCount',
1021
- parameter_value: '1'
1022
- },
1023
- {
1024
- parameter_key: 'ECSClusterName',
1025
- parameter_value: @ecs_cluster_name
1026
- },
1027
- {
1028
- parameter_key: 'ALBShortName',
1029
- parameter_value: "crash-qa-#{deploy_id}"[0..31]
1030
- },
1031
- {
1032
- parameter_key: 'HostnamePattern',
1033
- parameter_value: "crash-#{@dns_record_identifier}.qa.colaster.com"
1034
- },
1035
- {
1036
- parameter_key: 'HostnamePatternPriority',
1037
- parameter_value: (hostname_pattern_priority.to_i + 10).to_s
1038
- }
1039
- ]
1040
- if stack_exists?(stack_name_crash)
1041
- cur_version = get_currently_deployed_version(stack_name_crash)
1042
- update_stack(stack_name_crash, stack_body, parameters, tags) unless cur_version.include?(@projects["crash"][:revision])
1043
- else
1044
- create_stack(stack_name_crash, stack_body, parameters, tags)
540
+ def qainit_drone_shutdown!
541
+ output "Recupero le informazioni sui QA attivi..."
542
+ stack_list, envs = get_stacks
543
+
544
+ env_hash = "qa-" + get_deploy_id
545
+
546
+ cluster_stack_name = nil
547
+ stacks_to_delete = []
548
+ stack_list.each do |stack|
549
+ if stack.stack_name.match(/#{env_hash}$/)
550
+ if stack.stack_name.match(/ecs-cluster/)
551
+ cluster_stack_name = stack.stack_name
552
+ else
553
+ break unless stack.stack_name.match(/#{env_hash}$/)
554
+ stacks_to_delete.push(stack.stack_name)
555
+ delete_stack(stack.stack_name)
556
+ end
1045
557
  end
1046
558
  end
1047
559
 
1048
- # Waiting for prima healtcheck dependencies
1049
- wait_for_stack_ready(stack_name_urania) unless stack_ready?(stack_name_urania)
1050
- wait_for_stack_ready(stack_name_bburago) unless stack_ready?(stack_name_bburago)
1051
- wait_for_stack_ready(stack_name_hal9000) unless stack_ready?(stack_name_hal9000)
1052
- wait_for_stack_ready(stack_name_assange) unless stack_ready?(stack_name_assange)
1053
- wait_for_stack_ready(stack_name_fidaty) unless stack_ready?(stack_name_fidaty)
1054
-
1055
- stack_name_bolla = "ecs-task-bolla-qa-#{deploy_id}"
1056
- git_checkout_version('bolla', @projects["bolla"][:revision])
1057
- stack_body = YAML.load_file('projects/bolla/deploy/task.yml')
1058
- stack_body['Resources']['ECSServiceBolla']['Properties'].reject!{ |k| ['LoadBalancers', 'Role'].include?(k) }
1059
- stack_body = stack_body.to_yaml
1060
- parameters = [
1061
- {
1062
- parameter_key: "Environment",
1063
- parameter_value: "qa"
1064
- },
1065
- {
1066
- parameter_key: "ReleaseVersion",
1067
- parameter_value: "#{@projects["bolla"][:revision]}-#{deploy_id}"
1068
- },
1069
- {
1070
- parameter_key: "TaskDesiredCount",
1071
- parameter_value: "1"
1072
- },
1073
- {
1074
- parameter_key: "ECSClusterName",
1075
- parameter_value: @ecs_cluster_name
1076
- },
1077
- {
1078
- parameter_key: "ALBShortName",
1079
- parameter_value: "bolla-qa-#{deploy_id}"[0..31]
1080
- },
1081
- {
1082
- parameter_key: "HostnamePattern",
1083
- parameter_value: "bolla-#{@dns_record_identifier}.qa.colaster.com"
1084
- },
1085
- {
1086
- parameter_key: "HostnamePatternPriority",
1087
- parameter_value: hostname_pattern_priority
1088
- },
1089
- ]
1090
- if stack_exists?(stack_name_bolla)
1091
- cur_version = get_currently_deployed_version(stack_name_bolla)
1092
- update_stack(stack_name_bolla, stack_body, parameters, tags) unless cur_version.include?(@projects["bolla"][:revision])
1093
- else
1094
- create_stack(stack_name_bolla, stack_body, parameters, tags)
1095
- end
560
+ cluster_stack_name = "ecs-cluster-#{env_hash}"
561
+ if stack_exists?(cluster_stack_name)
562
+ aggregator_enabled = get_stack_tags(cluster_stack_name).detect do |tag|
563
+ tag.key === "hostname_pattern_priority" and tag.value === "1"
564
+ end.is_a?(Aws::CloudFormation::Types::Tag)
1096
565
 
1097
- stack_name_web = "ecs-task-web-qa-#{deploy_id}"
1098
- git_checkout_version('prima', @projects["prima"][:revision])
1099
- stack_body = IO.read('projects/prima/app/cloudformation/tasks/web.yml')
1100
- parameters = [
1101
- {
1102
- parameter_key: "Environment",
1103
- parameter_value: "qa"
1104
- },
1105
- {
1106
- parameter_key: "ReleaseVersion",
1107
- parameter_value: "#{@projects["prima"][:revision]}-#{deploy_id}"
1108
- },
1109
- {
1110
- parameter_key: "TaskDesiredCount",
1111
- parameter_value: "1"
1112
- },
1113
- {
1114
- parameter_key: "ECSClusterName",
1115
- parameter_value: @ecs_cluster_name
1116
- },
1117
- {
1118
- parameter_key: "ALBShortName",
1119
- parameter_value: "web-qa-#{deploy_id}"[0..31]
1120
- },
1121
- {
1122
- parameter_key: "WebQaBaseHostname",
1123
- parameter_value: "#{@dns_record_identifier}.qa.colaster.com"
1124
- },
1125
- {
1126
- parameter_key: "HostnamePattern",
1127
- parameter_value: "ww*-#{@dns_record_identifier}.qa.colaster.com"
1128
- },
1129
- {
1130
- parameter_key: "HostnamePatternPriority",
1131
- parameter_value: hostname_pattern_priority
1132
- },
1133
- {
1134
- parameter_key: "HostnamePatternAggregatorPriority",
1135
- parameter_value: (hostname_pattern_priority.to_i + 1).to_s
1136
- }
1137
- ]
1138
- if stack_exists?(stack_name_web)
1139
- cur_version = get_currently_deployed_version(stack_name_web)
1140
- update_stack(stack_name_web, stack_body, parameters, tags) unless cur_version.include?(@projects["prima"][:revision])
1141
- else
1142
- create_stack(stack_name_web, stack_body, parameters, tags)
566
+ if aggregator_enabled
567
+ dns_to_staging(env_hash)
568
+ end
1143
569
  end
1144
570
 
1145
- stack_name_consumer = "ecs-task-consumer-qa-#{deploy_id}"
1146
- git_checkout_version('prima', @projects["prima"][:revision])
1147
- stack_body = IO.read('projects/prima/app/cloudformation/tasks/consumer.yml')
1148
- parameters = [
1149
- {
1150
- parameter_key: "Environment",
1151
- parameter_value: "qa"
1152
- },
1153
- {
1154
- parameter_key: "ReleaseVersion",
1155
- parameter_value: "#{@projects["prima"][:revision]}-#{deploy_id}"
1156
- },
1157
- {
1158
- parameter_key: "ECSClusterName",
1159
- parameter_value: @ecs_cluster_name
1160
- }
1161
- ]
1162
- if stack_exists?(stack_name_consumer)
1163
- cur_version = get_currently_deployed_version(stack_name_consumer)
1164
- update_stack(stack_name_consumer, stack_body, parameters, tags) unless cur_version.include?(@projects["prima"][:revision])
1165
- else
1166
- create_stack(stack_name_consumer, stack_body, parameters, tags)
571
+ # Se non ha finito di cancellare le altre non si puo' cancellare il cluster
572
+ output "Attendo 10 secondi per poter eliminare il cluster ECS"
573
+
574
+ while stacks_to_delete.length > 0
575
+ sleep 13
576
+ stacks_to_delete.each do |stack_name|
577
+ stacks_to_delete = stacks_to_delete - [stack_name] unless stack_exists?(stack_name)
578
+ end
579
+ output "Stack ancora attivi: #{stacks_to_delete.length.to_s}. Attendo altri 10 secondi per eliminare il cluster ECS"
1167
580
  end
1168
581
 
1169
- wait_for_stack_ready(stack_name_web) unless stack_ready?(stack_name_web)
1170
- wait_for_stack_ready(stack_name_consumer) unless stack_ready?(stack_name_consumer)
1171
- wait_for_stack_ready(stack_name_backoffice) unless stack_ready?(stack_name_backoffice)
1172
- wait_for_stack_ready(stack_name_ermes) unless stack_ready?(stack_name_ermes)
1173
- wait_for_stack_ready(stack_name_fidaty) unless stack_ready?(stack_name_fidaty)
1174
- wait_for_stack_ready(stack_name_peano) unless stack_ready?(stack_name_peano)
1175
- wait_for_stack_ready(stack_name_rogoreport) unless stack_ready?(stack_name_rogoreport)
1176
- wait_for_stack_ready(stack_name_borat) unless stack_ready?(stack_name_borat)
1177
- wait_for_stack_ready(stack_name_bolla) unless stack_ready?(stack_name_bolla)
1178
- wait_for_stack_ready(stack_name_crash) unless stack_ready?(stack_name_crash) || !deploy_crash?
1179
-
1180
- update_service_defaults(stack_name_web)
1181
- update_service_defaults(stack_name_consumer)
1182
- update_service_defaults(stack_name_urania)
1183
- update_service_defaults(stack_name_backoffice)
1184
- update_service_defaults(stack_name_ermes)
1185
- update_service_defaults(stack_name_bburago)
1186
- update_service_defaults(stack_name_hal9000)
1187
- update_service_defaults(stack_name_fidaty)
1188
- update_service_defaults(stack_name_peano)
1189
- update_service_defaults(stack_name_rogoreport)
1190
- update_service_defaults(stack_name_assange)
1191
- update_service_defaults(stack_name_borat)
1192
- update_service_defaults(stack_name_bolla)
1193
- update_service_defaults(stack_name_crash) unless stack_ready?(stack_name_crash) || !deploy_crash?
1194
-
1195
- prima_hostname = get_route53_hostname(stack_name_web)
1196
- urania_hostname = get_route53_hostname(stack_name_urania)
1197
- bburago_hostname = get_route53_hostname(stack_name_bburago)
1198
- hal9000_hostname = get_route53_hostname(stack_name_hal9000)
1199
- ermes_hostname = get_route53_hostname(stack_name_ermes)
1200
- fidaty_hostname = get_route53_hostname(stack_name_fidaty)
1201
- peano_hostname = get_route53_hostname(stack_name_peano)
1202
- backoffice_hostname = get_route53_hostname(stack_name_backoffice)
1203
- assange_hostname = get_route53_hostname(stack_name_assange)
1204
- borat_hostname = get_route53_hostname(stack_name_borat)
1205
- bolla_hostname = get_route53_hostname(stack_name_bolla)
1206
- deploy_crash? && crash_hostname = get_route53_hostname(stack_name_crash)
1207
-
1208
- launch_marley ec2_ip_address(asg_stack_name), prima_hostname, borat_hostname
1209
-
1210
- projects_text = "
1211
- > Prima url: https://#{prima_hostname}
1212
- > Prima RI url: https://#{prima_hostname.sub("www", "wwwri")}
1213
- > Backoffice (Borat) url: https://#{borat_hostname}
1214
- > Urania url: http://#{urania_hostname}:81
1215
- > Bburago url: http://#{bburago_hostname}:83
1216
- > Ermes url: http://#{ermes_hostname}:10002
1217
- > Hal9000 url: http://#{hal9000_hostname}:10031
1218
- > Fidaty url: http://#{fidaty_hostname}:10021
1219
- > Peano url: http://#{peano_hostname}:10039
1220
- > Bolla url: http://#{ec2_ip_address(asg_stack_name)}:10046
1221
- > Assange url: https://#{assange_hostname}
1222
- > Backoffice (legacy) url: https://#{backoffice_hostname}"
1223
- projects_text.concat "
1224
- > Crash url: https://#{crash_hostname}" if deploy_crash?
1225
- projects_text.concat "
1226
- > RabbitMQ url: http://#{ec2_ip_address(asg_stack_name)}:15672
1227
- > Supervisor url: http://#{ec2_ip_address(asg_stack_name)}:9001
1228
- > Elasticsearch url: http://#{ec2_ip_address(asg_stack_name)}:9200
1229
- > Elasticsearch 2 url: http://#{ec2_ip_address(asg_stack_name)}:9201
1230
- > SSH connection: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no githubUsername@#{ec2_ip_address(asg_stack_name)}\n"
1231
- output projects_text.cyan
1232
- output "Deploy effettuato, everything is awesome!\n".green
582
+ delete_stack(cluster_stack_name) if stack_exists?(cluster_stack_name)
583
+ delete_stack(@base_stack_name_alb + env_hash[3..8]) if stack_exists?(@base_stack_name_alb + env_hash[3..8])
584
+ delete_stack(@base_stack_name_alb_ws + env_hash[3..8]) if stack_exists?(@base_stack_name_alb_ws + env_hash[3..8])
585
+ `git checkout master && git push origin --delete ${DRONE_BRANCH}`
586
+ output "Cancello il record DNS utilizzato da Lighthouse"
587
+ delete_lighthouse_dns()
588
+ output "Finito!".green
1233
589
  end
1234
590
 
1235
- def get_route53_hostname(stack_name)
1236
- case
1237
- when stack_name.include?('web')
1238
- host = "www-#{@dns_record_identifier}.qa.colaster.com"
1239
- when stack_name.include?('urania')
1240
- host = "urania-#{@dns_record_identifier}.qa.colaster.com"
1241
- when stack_name.include?('backoffice')
1242
- host = "backoffice-legacy-#{@dns_record_identifier}.qa.colaster.com"
1243
- when stack_name.include?('bburago')
1244
- host = "bburago-#{@dns_record_identifier}.qa.colaster.com"
1245
- when stack_name.include?('hal9000')
1246
- host = "hal9000-#{@dns_record_identifier}.qa.colaster.com"
1247
- when stack_name.include?('fidaty')
1248
- host = "fidaty-#{@dns_record_identifier}.qa.colaster.com"
1249
- when stack_name.include?('peano')
1250
- host = "peano-#{@dns_record_identifier}.qa.colaster.com"
1251
- when stack_name.include?('assange')
1252
- host = "assange-#{@dns_record_identifier}.qa.colaster.com"
1253
- when stack_name.include?('borat')
1254
- host = "backoffice-#{@dns_record_identifier}.qa.colaster.com"
1255
- when stack_name.include?('crash')
1256
- host = "crash-#{@dns_record_identifier}.qa.colaster.com"
1257
- when stack_name.include?('ermes')
1258
- host = "ermes-#{@dns_record_identifier}.qa.colaster.com"
1259
- when stack_name.include?('bolla')
1260
- host = "bolla-#{@dns_record_identifier}.qa.colaster.com"
591
+ def qainit_write_output(file_message, output_message)
592
+ `mkdir -p /etc/qainit-output`
593
+ qa_file_name = "/etc/qainit-output/url_qa"
594
+ File.open(qa_file_name + '.txt', 'w') { |file| file.write(file_message) }
595
+ output "#{output_message} #{qa_file_name}".green
596
+ end
597
+
598
+ def update_drone_yml!()
599
+ drone_yml = File.read('.drone.yml')
600
+ @projects.each do |key, project|
601
+ drone_yml = drone_yml.gsub(/#{key}@.+\n/, "#{key}@#{project['revision']}\n")
602
+ end
603
+ File.open(".drone.yml", "w") do |f|
604
+ f.write(drone_yml)
1261
605
  end
1262
- host
1263
606
  end
1264
607
 
1265
- def ec2_ip_address(asg_stack_name)
1266
- resp = @cf.describe_stack_resource({
1267
- stack_name: asg_stack_name,
1268
- logical_resource_id: 'ECSAutoScalingGroup'
1269
- })
1270
- resp = @asg.describe_auto_scaling_groups({
1271
- auto_scaling_group_names: [resp.stack_resource_detail.physical_resource_id],
1272
- max_records: 1
1273
- })
1274
- instance_id = resp.auto_scaling_groups[0].instances[0].instance_id
1275
- resp = @ec2.describe_instances({instance_ids: [instance_id]})
1276
- resp.reservations[0].instances[0].private_ip_address
608
+ def get_deploy_id
609
+ if @deploy_id
610
+ @deploy_id
611
+ else
612
+ @deploy_id = Digest::MD5.hexdigest(ENV['DRONE_BRANCH'])
613
+ @deploy_id
614
+ end
1277
615
  end
1278
616
 
1279
617
  def get_alb_host(stack_name)
@@ -1290,549 +628,53 @@ class Release
1290
628
  logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1291
629
  when stack_name.include?('fidaty')
1292
630
  logical_resource_id = 'EcsApplicationLoadBalancerInternal'
631
+ when stack_name.include?('activia')
632
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
633
+ when stack_name.include?('skynet')
634
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
635
+ when stack_name.include?('roger')
636
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1293
637
  when stack_name.include?('alb-http-public')
1294
638
  logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1295
639
  when stack_name.include?('alb-ws-public')
1296
640
  logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1297
641
  when stack_name.include?('peano')
1298
642
  logical_resource_id = 'EcsApplicationLoadBalancerInternal'
643
+ when stack_name.include?('leftorium')
644
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1299
645
  when stack_name.include?('assange')
1300
646
  logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1301
647
  when stack_name.include?('borat')
1302
648
  logical_resource_id = 'EcsApplicationLoadBalancerPublic'
1303
649
  when stack_name.include?('crash')
1304
650
  logical_resource_id = 'EcsApplicationLoadBalancerPublic'
651
+ when stack_name.include?('rachele')
652
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
653
+ when stack_name.include?('starsky')
654
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
655
+ when stack_name.include?('hutch')
656
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
657
+ when stack_name.include?('maia')
658
+ logical_resource_id = 'EcsApplicationLoadBalancerPublic'
659
+ when stack_name.include?('legion')
660
+ logical_resource_id = 'EcsApplicationLoadBalancerInternal'
1305
661
  end
1306
- resp = @cf.describe_stack_resource({
1307
- stack_name: stack_name,
1308
- logical_resource_id: logical_resource_id
1309
- })
1310
- resp = @alb.describe_load_balancers({
1311
- load_balancer_arns: [resp.stack_resource_detail.physical_resource_id]
1312
- })
662
+ resp = describe_stack_resource(stack_name, logical_resource_id)
663
+ resp = describe_load_balancers([resp.stack_resource_detail.physical_resource_id])
1313
664
  resp.load_balancers[0].dns_name
1314
665
  end
1315
666
 
1316
- def update_service_defaults(stack_name)
1317
- case
1318
- when stack_name.include?('web')
1319
- logical_resource_id = 'ECSServiceWeb'
1320
- when stack_name.include?('consumer')
1321
- logical_resource_id = 'ECSServiceConsumer'
1322
- when stack_name.include?('urania')
1323
- logical_resource_id = 'ECSServiceUrania'
1324
- when stack_name.include?('backoffice')
1325
- logical_resource_id = 'ECSServiceBackoffice'
1326
- when stack_name.include?('ermes')
1327
- logical_resource_id = 'ECSServiceErmes'
1328
- when stack_name.include?('bburago')
1329
- logical_resource_id = 'ECSServiceBburago'
1330
- when stack_name.include?('hal9000')
1331
- logical_resource_id = 'ECSServiceHal9000'
1332
- when stack_name.include?('fidaty')
1333
- logical_resource_id = 'ECSServiceFidaty'
1334
- when stack_name.include?('peano')
1335
- logical_resource_id = 'ECSServicePeano'
1336
- when stack_name.include?('rogoreport')
1337
- logical_resource_id = 'ECSServiceRogoreport'
1338
- when stack_name.include?('assange')
1339
- logical_resource_id = 'ECSServiceAssange'
1340
- when stack_name.include?('borat')
1341
- logical_resource_id = 'ECSServiceBorat'
1342
- when stack_name.include?('crash')
1343
- logical_resource_id = 'ECSServiceCrash'
1344
- when stack_name.include?('bolla')
1345
- logical_resource_id = 'ECSServiceBolla'
667
+ def deploy_pyxis?
668
+ if defined? @deploy_pyxis
669
+ @deploy_pyxis
1346
670
  else
1347
- raise "Service name non gestito per lo stack #{stack_name}"
1348
- end
1349
- resp = @cf.describe_stack_resource(
1350
- stack_name: stack_name,
1351
- logical_resource_id: logical_resource_id
1352
- )
1353
- @ecs.update_service(
1354
- cluster: @ecs_cluster_name,
1355
- service: resp.stack_resource_detail.physical_resource_id,
1356
- deployment_configuration: {
1357
- minimum_healthy_percent: 0,
1358
- maximum_percent: 100
1359
- }
1360
- )
1361
- end
1362
-
1363
- def create_urania_artifact(revision)
1364
- output "Preparo l'artifact urania .zip\n".yellow
671
+ pyxis_updated = `git log -p -1 --unified=0 | grep pyxis-npm:`.length > 0
1365
672
 
1366
- git_checkout_version('urania', revision)
673
+ update_pyxis = !@projects['pyxis-npm'].empty? && @projects['pyxis-npm']['name'] != 'master' && pyxis_updated
1367
674
 
1368
- Dir.chdir 'projects/urania'
1369
-
1370
- decrypt_secrets()
1371
-
1372
- [
1373
- "docker-compose build web",
1374
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh urania_web \
1375
- '-c' 'mix local.hex --force && mix hex.info && \
1376
- mix deps.get && mix compile && mix deps.compile && \
1377
- rm -rf _build/qa/rel/ && \
1378
- mix release --env=qa'"
1379
- ].each do |cmd|
1380
- execute_command cmd
1381
- end
1382
-
1383
- artifact_path = Dir.glob("_build/qa/rel/urania/releases/*/urania.tar.gz").first
1384
- upload_artifact(artifact_path, "microservices/urania/#{revision}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1385
-
1386
- Dir.chdir '../../'
1387
- end
1388
-
1389
- def create_ermes_artifact(revision, deploy_id)
1390
- output "Preparo l'artifact ermes .zip\n".yellow
1391
-
1392
- git_checkout_version('ermes', revision)
1393
-
1394
- Dir.chdir 'projects/ermes'
1395
-
1396
- stack_name_web = 'ecs-task-web-qa-notneeded'
1397
- web_qa_host = get_route53_hostname(stack_name_web)
1398
- stack_name_peano = 'ecs-task-peano-qa-notneeded'
1399
- peano_qa_host = "#{get_route53_hostname(stack_name_peano)}:10039"
1400
-
1401
- [
1402
- "if echo `docker network ls` | grep crash_default; \
1403
- then echo 'crash_default network already existing'; \
1404
- else docker network create crash_default; fi",
1405
- 'docker-compose build web',
1406
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh ermes_web \
1407
- '-c' 'sed -i \"s/peano-qa-host/#{peano_qa_host}/g\" config/qa.exs && \
1408
- sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1409
- mix local.hex --force && mix hex.info && \
1410
- mix deps.get && mix compile && mix deps.compile && \
1411
- mix phx.digest && \
1412
- rm -rf _build/qa/rel/ && \
1413
- mix release --env=qa'",
1414
- "if echo `docker ps` | grep crash; \
1415
- then echo 'cannot delete crash_default network'; \
1416
- else docker network rm crash_default; fi "
1417
- ].each do |cmd|
1418
- execute_command cmd
1419
- end
1420
-
1421
- artifact_path = Dir.glob("_build/qa/rel/ermes/releases/*/ermes.tar.gz").first
1422
- upload_artifact(artifact_path, "microservices/ermes/#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1423
-
1424
- Dir.chdir '../../'
1425
- end
1426
-
1427
- def deploy_crash?
1428
- !@projects['crash'].empty? && !@projects['crash'][:default_branch]
1429
- end
1430
-
1431
- def create_crash_artifact(revision, deploy_id)
1432
- output "Preparo l'artifact crash .zip\n".yellow
1433
-
1434
- git_checkout_version('crash', revision)
1435
-
1436
- Dir.chdir 'projects/crash'
1437
-
1438
- stack_name_web = 'ecs-task-web-qa-notneeded'
1439
- web_qa_host = get_route53_hostname(stack_name_web)
1440
- stack_name_crash = 'ecs-task-crash-qa-notneeded'
1441
- crash_qa_host = get_route53_hostname(stack_name_crash)
1442
-
1443
- ws_endpoint = "wss://#{crash_qa_host}/socket/websocket?vsn=1.0.0"
1444
- frontend_endpoint = "https://#{crash_qa_host}/graphql"
1445
-
1446
- decrypt_secrets()
1447
-
1448
- [
1449
- 'mv docker-compose-ci.yml docker-compose.yml',
1450
- 'docker-compose build web',
1451
- "docker-compose run -w $PWD -e WS_ENDPOINT=#{ws_endpoint} -e GRAPHQL_ENDPOINT=#{frontend_endpoint} -e MIX_ENV=qa web \
1452
- '-c' 'sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1453
- sed -i \"s/crash-qa-host/#{crash_qa_host}/g\" config/qa.exs && \
1454
- mix local.hex --force && mix hex.info && \
1455
- mix deps.get && \
1456
- cd assets && \
1457
- yarn --cache-folder ~/.cache/yarn && \
1458
- ./node_modules/.bin/elm-github-install && \
1459
- NODE_ENV=production sysconfcpus -n 2 ./node_modules/.bin/webpack -p --config config/webpack.config.prod.js && \
1460
- cd ../ && \
1461
- mix release.clean --implode --no-confirm && \
1462
- mix phx.digest && \
1463
- mix deps.clean --all && \
1464
- mix deps.get && \
1465
- mix compile && mix release --env=qa'",
1466
- 'docker-compose down'
1467
- ].each do |cmd|
1468
- execute_command cmd
675
+ @deploy_pyxis = update_pyxis
676
+ return update_pyxis
1469
677
  end
1470
-
1471
- artifact_path = Dir.glob('_build/qa/rel/crash/releases/*/crash.tar.gz').first
1472
- upload_artifact(artifact_path, "microservices/crash/#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1473
-
1474
- Dir.chdir '../../'
1475
- end
1476
-
1477
- def create_bburago_artifact(revision)
1478
- output "Preparo l'artifact bburago .zip\n".yellow
1479
-
1480
- git_checkout_version('bburago', revision)
1481
-
1482
- Dir.chdir 'projects/bburago'
1483
-
1484
- decrypt_secrets()
1485
-
1486
- [
1487
- "docker-compose build web",
1488
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh bburago_web \
1489
- '-c' 'mix local.hex --force && mix hex.info && \
1490
- mix deps.get && mix compile && mix deps.compile && \
1491
- rm -rf _build/qa/rel/ && \
1492
- mix release --env=qa'"
1493
- ].each do |cmd|
1494
- execute_command cmd
1495
- end
1496
-
1497
- artifact_path = Dir.glob("_build/qa/rel/bburago/releases/*/bburago.tar.gz").first
1498
- upload_artifact(artifact_path, "microservices/bburago/#{revision}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1499
-
1500
- Dir.chdir '../../'
1501
- end
1502
-
1503
- def create_hal9000_artifact(revision)
1504
- output "Preparo l'artifact hal9000 .zip\n".yellow
1505
-
1506
- git_checkout_version('hal9000', revision)
1507
-
1508
- Dir.chdir 'projects/hal9000'
1509
-
1510
- decrypt_secrets()
1511
-
1512
- [
1513
- "docker-compose build web",
1514
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh hal9000_web \
1515
- '-c' 'mix local.hex --force && mix hex.info && \
1516
- mix deps.get && mix compile && mix deps.compile && \
1517
- mix phx.digest && \
1518
- rm -rf _build/qa/rel/ && \
1519
- mix release --env=qa'"
1520
- ].each do |cmd|
1521
- execute_command cmd
1522
- end
1523
-
1524
- artifact_path = Dir.glob("_build/qa/rel/hal9000/releases/*/hal9000.tar.gz").first
1525
- upload_artifact(artifact_path, "microservices/hal9000/#{revision}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1526
-
1527
- Dir.chdir '../../'
1528
- end
1529
-
1530
- def create_fidaty_artifact(revision, deploy_id)
1531
- output "Preparo l'artifact fidaty .zip\n".yellow
1532
-
1533
- git_checkout_version('fidaty', revision)
1534
-
1535
- Dir.chdir 'projects/fidaty'
1536
-
1537
- stack_name_web = "ecs-task-web-qa-notneeded"
1538
- web_qa_host = get_route53_hostname(stack_name_web)
1539
-
1540
- stack_name_peano = "ecs-task-peano-qa-notneeded"
1541
- peano_qa_host = "#{get_route53_hostname(stack_name_peano)}:10039"
1542
-
1543
- decrypt_secrets()
1544
-
1545
- [
1546
- "docker-compose build web",
1547
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh fidaty_web \
1548
- '-c' 'sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1549
- sed -i \"s/peano-qa-host/#{peano_qa_host}/g\" config/qa.exs && \
1550
- mix local.hex --force && mix hex.info && \
1551
- mix deps.get && mix compile && mix deps.compile && \
1552
- mix phx.digest && \
1553
- rm -rf _build/qa/rel/ && \
1554
- mix release --env=qa'"
1555
- ].each do |cmd|
1556
- execute_command cmd
1557
- end
1558
-
1559
- artifact_path = Dir.glob("_build/qa/rel/fidaty/releases/*/fidaty.tar.gz").first
1560
- upload_artifact(artifact_path, "microservices/fidaty/#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1561
-
1562
- Dir.chdir '../../'
1563
- end
1564
-
1565
- def create_peano_artifact(revision, deploy_id)
1566
- output "Preparo l'artifact peano .zip\n".yellow
1567
-
1568
- git_checkout_version('peano', revision)
1569
-
1570
- stack_name_assange = "ecs-task-assange-qa-notneeded"
1571
- assange_qa_host = get_route53_hostname(stack_name_assange)
1572
- stack_name_web = 'ecs-task-web-qa-notneeded'
1573
- web_qa_host = get_route53_hostname(stack_name_web)
1574
-
1575
- Dir.chdir 'projects/peano'
1576
-
1577
- stop_unless is_branch_compatible_with_current_twig_version?("peano"), "Il tuo branch del progetto peano non e' compatibile con questa versione di twig, devi REBASARE DA MASTER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!".red
1578
-
1579
- decrypt_secrets()
1580
-
1581
- [
1582
- "docker-compose build web",
1583
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh peano_web \
1584
- '-c' 'mix local.hex --force && mix hex.info && \
1585
- sed -i \"s/assange-qa-host/#{assange_qa_host}/g\" config/qa.exs && \
1586
- sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1587
- mix deps.get && mix compile && mix deps.compile && \
1588
- rm -rf _build/qa/rel/ && \
1589
- mix release --env=qa'"
1590
- ].each do |cmd|
1591
- execute_command cmd
1592
- end
1593
-
1594
- artifact_path = Dir.glob("_build/qa/rel/peano/releases/*/peano.tar.gz").first
1595
- upload_artifact(artifact_path, "microservices/peano/#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1596
-
1597
- Dir.chdir '../../'
1598
- end
1599
-
1600
- def create_rogoreport_artifact(revision, deploy_id)
1601
- output "Preparo l'artifact rogoreport .zip\n".yellow
1602
-
1603
- git_checkout_version('rogoreport', revision)
1604
-
1605
- Dir.chdir 'projects/rogoreport'
1606
-
1607
- stack_name_peano = 'ecs-task-peano-qa-notneeded'
1608
- stack_name_web = 'ecs-task-web-qa-notneeded'
1609
- peano_qa_host = "#{get_route53_hostname(stack_name_peano)}:10039"
1610
- web_qa_host = get_route53_hostname(stack_name_web)
1611
-
1612
- decrypt_secrets()
1613
-
1614
- [
1615
- "docker-compose build web",
1616
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh rogoreport_web \
1617
- '-c' 'sed -i \"s/peano-qa-host/#{peano_qa_host}/g\" apps/escile/config/qa.exs && \
1618
- sed -i \"s/web-qa-host/#{web_qa_host}/g\" apps/escile/config/qa.exs && \
1619
- cat apps/escile/config/qa.exs && \
1620
- mix local.hex --force && mix hex.info && \
1621
- mix deps.get && mix compile && mix deps.compile && \
1622
- rm -rf _build/qa/rel/ && \
1623
- mix release --name=rogoreport_qa --env=qa'"
1624
- ].each do |cmd|
1625
- execute_command cmd
1626
- end
1627
-
1628
- artifact_path = Dir.glob("_build/qa/rel/rogoreport*/releases/*/rogoreport*.tar.gz").first
1629
- upload_artifact(artifact_path, "microservices/rogoreport/rogoreport_qa-#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1630
-
1631
- Dir.chdir '../../'
1632
- end
1633
-
1634
- def create_assange_artifact(revision, deploy_id)
1635
- output "Preparo l'artifact assange .zip\n".yellow
1636
-
1637
- git_checkout_version('assange', revision)
1638
-
1639
- Dir.chdir 'projects/assange'
1640
-
1641
- stack_name_web = 'ecs-task-web-qa-notneeded'
1642
- web_qa_host = get_route53_hostname(stack_name_web)
1643
-
1644
- decrypt_secrets()
1645
-
1646
- [
1647
- "docker-compose build web",
1648
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh assange_web \
1649
- '-c' 'mix local.hex --force && mix hex.info && \
1650
- sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1651
- mix deps.get && mix compile && mix deps.compile && \
1652
- mix phx.digest && \
1653
- rm -rf _build/qa/rel/ && \
1654
- mix release --env=qa'"
1655
- ].each do |cmd|
1656
- execute_command cmd
1657
- end
1658
-
1659
- artifact_path = Dir.glob("_build/qa/rel/assange/releases/*/assange.tar.gz").first
1660
- upload_artifact(artifact_path, "microservices/assange/#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1661
-
1662
- Dir.chdir '../../'
1663
- end
1664
-
1665
- def create_bolla_artifact(revision, deploy_id)
1666
- output "Preparo l'artifact bolla .zip\n".yellow
1667
-
1668
- git_checkout_version('bolla', revision)
1669
-
1670
- Dir.chdir 'projects/bolla'
1671
-
1672
- decrypt_secrets()
1673
-
1674
- [
1675
- "docker-compose build web",
1676
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh assange_web \
1677
- '-c' 'mix local.hex --force && mix hex.info && \
1678
- mix deps.get && mix compile && mix deps.compile && \
1679
- rm -rf _build/qa/rel/ && \
1680
- mix release --env=qa'"
1681
- ].each do |cmd|
1682
- execute_command cmd
1683
- end
1684
-
1685
- artifact_path = Dir.glob("_build/qa/rel/migrator/releases/*/migrator.tar.gz").first
1686
- upload_artifact(artifact_path, "microservices/bolla/#{revision}-#{deploy_id}-qa-migrator.tar.gz", "#{@s3_bucket}-encrypted")
1687
-
1688
- Dir.chdir '../../'
1689
- end
1690
-
1691
- def create_borat_artifact(revision, deploy_id)
1692
- output "Preparo l'artifact borat .zip\n".yellow
1693
-
1694
- git_checkout_version('borat', revision)
1695
-
1696
- Dir.chdir 'projects/borat'
1697
-
1698
- stack_name_web = "ecs-task-web-qa-notneeded"
1699
- web_qa_host = get_route53_hostname(stack_name_web)
1700
- stack_name_backoffice = "ecs-task-backoffice-qa-notneeded"
1701
- backoffice_qa_host = get_route53_hostname(stack_name_backoffice)
1702
- stack_name_assange = "ecs-task-assange-qa-notneeded"
1703
- assange_qa_host = get_route53_hostname(stack_name_assange)
1704
- stack_name_peano = "ecs-task-peano-qa-notneeded"
1705
- peano_qa_host = "#{get_route53_hostname(stack_name_peano)}:10039"
1706
- stack_name_borat = "ecs-task-borat-qa-notneeded"
1707
- borat_qa_host = get_route53_hostname(stack_name_borat)
1708
-
1709
- ws_endpoint = "wss://#{borat_qa_host}/socket/websocket?vsn=1.0.0"
1710
- frontend_endpoint = "https://#{web_qa_host}/"
1711
-
1712
- stop_unless is_branch_compatible_with_current_twig_version?("borat"), "Il tuo branch del progetto borat non e' compatibile con questa versione di twig, devi REBASARE DA MASTER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!".red
1713
-
1714
- decrypt_secrets()
1715
-
1716
- [
1717
- "docker-compose build backend",
1718
- "docker run -v $PWD:/code -w /code -e WS_ENDPOINT=#{ws_endpoint} -e FRONTEND=#{frontend_endpoint} -e MIX_ENV=qa --entrypoint /bin/sh borat_backend \
1719
- '-c' 'sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1720
- sed -i \"s/backoffice-legacy-qa-host/#{backoffice_qa_host}/g\" config/qa.exs && \
1721
- sed -i \"s/assange-qa-host/#{assange_qa_host}/g\" config/qa.exs && \
1722
- sed -i \"s/peano-qa-host/#{peano_qa_host}/g\" config/qa.exs && \
1723
- sed -i \"s/borat-qa-host/#{borat_qa_host}/g\" config/qa.exs && \
1724
- mix local.hex --force && mix hex.info && \
1725
- mix deps.get && \
1726
- cd assets && \
1727
- yarn --cache-folder ~/.cache/yarn && \
1728
- ./node_modules/.bin/elm-github-install && \
1729
- sysconfcpus -n 2 ./node_modules/.bin/webpack -p --config config/webpack.config.prod.js && \
1730
- cd ../ && \
1731
- mix phx.digest && \
1732
- mix compile && mix deps.compile && \
1733
- rm -rf _build/qa/rel/ && \
1734
- mix release --env=qa'"
1735
- ].each do |cmd|
1736
- execute_command cmd
1737
- end
1738
-
1739
- artifact_path = Dir.glob("_build/qa/rel/backend/releases/*/backend.tar.gz").first
1740
- upload_artifact(artifact_path, "microservices/borat/#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1741
-
1742
- Dir.chdir '../../'
1743
- end
1744
-
1745
- def create_backoffice_artifact(revision, deploy_id)
1746
- output "Preparo l'artifact backoffice .zip\n".yellow
1747
-
1748
- git_checkout_version('backoffice', revision)
1749
-
1750
- Dir.chdir 'projects/backoffice'
1751
-
1752
- ['node_modules'].each do |dir|
1753
- unless File.directory?(dir)
1754
- if File.directory?("../../../backoffice/#{dir}")
1755
- exec_step "rsync -a ../../../backoffice/#{dir} ."
1756
- end
1757
- end
1758
- end
1759
-
1760
- stack_name_web = "ecs-task-web-qa-notneeded"
1761
- web_qa_host = get_route53_hostname(stack_name_web)
1762
- webri_qa_host = web_qa_host.sub("www", "wwwri")
1763
-
1764
- [
1765
- "docker-compose build workers",
1766
- "rm -rf src/ && git checkout -- .",
1767
- "cd ../../ && docker run -e GIT_DIR=$PWD -v $PWD:/usr/app/src -w /usr/app/src/projects/backoffice blinkmobile/bower install --allow-root",
1768
- "docker run -v $PWD:/code -w /code -e PHANTOMJS_BIN=/code/node_modules/grunt-selenium-webdriver/node_modules/phantomjs/bin/phantomjs --entrypoint /bin/bash backoffice_workers '-c' 'sed -i \"s/web-qa-url/#{web_qa_host}/g\" Gruntfile.js && sed -i \"s/web-qa-ri-url/#{webri_qa_host}/g\" Gruntfile.js && npm install && grunt qa'"
1769
- ].each do |cmd|
1770
- execute_command cmd
1771
- end
1772
-
1773
- artifact_path = '/tmp/backoffice.zip'
1774
- exec_step "rm -f #{artifact_path} && zip -9 -r #{artifact_path} bin/"
1775
- upload_artifact(artifact_path, "backoffice/#{revision}-#{deploy_id}.zip")
1776
-
1777
- Dir.chdir '../../'
1778
- end
1779
-
1780
- def create_prima_artifact(revision, branch_name, deploy_id)
1781
- output "Preparo l'artifact prima .zip\n".yellow
1782
-
1783
- git_checkout_version('prima', revision)
1784
-
1785
- Dir.chdir 'projects/prima'
1786
-
1787
- ['vendor'].each do |dir|
1788
- unless File.directory?(dir)
1789
- if File.directory?("../../../prima/#{dir}")
1790
- exec_step "rsync -a ../../../prima/#{dir} ."
1791
- end
1792
- end
1793
- end
1794
-
1795
- backoffice_qa_host = get_route53_hostname("ecs-task-borat-qa-notneeded")
1796
- web_qa_host = get_route53_hostname("ecs-task-web-qa-notneeded")
1797
- assange_qa_host = get_route53_hostname("ecs-task-assange-qa-notneeded")
1798
-
1799
- [
1800
- "bin/local_build_artifact.sh #{branch_name} #{web_qa_host} #{backoffice_qa_host} #{assange_qa_host} #{deploy_id} #{'update' if @deploy_update}"
1801
- ].each do |cmd|
1802
- execute_command cmd
1803
- end
1804
-
1805
- Dir.chdir "../../"
1806
- end
1807
-
1808
- def git_checkout_version(project, revision)
1809
- Dir.chdir "projects/#{project}"
1810
- exec_step "git checkout -- . && git checkout #{revision}"
1811
- Dir.chdir "../../"
1812
- end
1813
-
1814
- def create_asg_stack(stack_name, tags = [])
1815
- stack_body = IO.read('cloudformation/stacks/asg/ecs-asg-allinone.yml')
1816
- parameters = [
1817
- {
1818
- parameter_key: "Environment",
1819
- parameter_value: "qa"
1820
- },
1821
- {
1822
- parameter_key: "InstanceType",
1823
- parameter_value: "t2.large"
1824
- },
1825
- {
1826
- parameter_key: "ECSClusterName",
1827
- parameter_value: @ecs_cluster_name
1828
- }
1829
- ]
1830
- create_stack(stack_name, stack_body, parameters, tags)
1831
- end
1832
-
1833
- def create_cluster_stack(stack_name, tags = [])
1834
- stack_body = IO.read('cloudformation/stacks/ecs-cluster.yml')
1835
- create_stack(stack_name, stack_body, [], tags)
1836
678
  end
1837
679
 
1838
680
  def update_cluster_stack(stack_name, tags = [])
@@ -1840,84 +682,13 @@ class Release
1840
682
  update_stack(stack_name, stack_body, [], tags)
1841
683
  end
1842
684
 
1843
- def create_alb_stack(stack_name, role)
1844
- stack_body = IO.read('cloudformation/stacks/alb/ecs-alb-public.yml')
1845
- parameters = [
1846
- {
1847
- parameter_key: "Environment",
1848
- parameter_value: "qa"
1849
- },
1850
- {
1851
- parameter_key: "Role",
1852
- parameter_value: role
1853
- }
1854
- ]
1855
- create_stack(stack_name, stack_body, parameters)
1856
- end
1857
-
1858
- def import_redis_crash(qa_ip_address)
1859
- output "Importo dump di Redis da staging\n".yellow
1860
-
1861
- redis_qa = Redis.new(:url => "redis://#{qa_ip_address}:6379/10")
1862
-
1863
- return unless redis_qa.keys('CODICI').empty?
1864
-
1865
- redis_staging = Redis.new(:url => 'redis://staging.cache-1.prima.it:6379/10')
1866
-
1867
- dump_staging = redis_staging.dump 'CODICI'
1868
-
1869
- redis_qa.restore 'CODICI', 0, dump_staging
1870
- end
1871
-
1872
- def import_dbs(ip_address)
1873
- resp = @ecs.run_task({
1874
- cluster: @ecs_cluster_name,
1875
- task_definition: @import_db_task,
1876
- overrides: {
1877
- container_overrides: [
1878
- {
1879
- name: 'dbrestore',
1880
- environment: [
1881
- {
1882
- name: 'EC2_IP_ADDRESS',
1883
- value: ip_address
1884
- }
1885
- ]
1886
- }
1887
- ]
1888
- },
1889
- count: 1
1890
- })
1891
- output "Attendo che i DB vengano importati...\n".yellow
1892
- stopped_at = nil
1893
- while stopped_at.nil?
1894
- unless resp.tasks[0].nil?
1895
- resp = @ecs.describe_tasks({
1896
- cluster: @ecs_cluster_name,
1897
- tasks: [resp.tasks[0].task_arn]
1898
- })
1899
- end
1900
- stopped_at = resp.tasks[0].stopped_at unless resp.tasks[0].nil?
1901
- sleep_seconds = 10
1902
- seconds_elapsed = 0
1903
- while true && stopped_at.nil?
1904
- break if seconds_elapsed >= sleep_seconds
1905
- print '.'.yellow; STDOUT.flush
1906
- sleep 1
1907
- seconds_elapsed += 1
1908
- end
1909
- end
1910
- print "\n"
1911
- end
1912
-
1913
685
  def choose_branch_to_deploy(project_name, select_master = false)
1914
- return {} if project_name == 'crash' && select_master
1915
686
  Dir.chdir "projects/#{project_name}"
1916
687
  output "Recupero la lista dei branch del progetto #{project_name}..."
1917
688
  `git remote prune origin`
1918
689
  out = %x[ git fetch ]
1919
690
  branches = %x[ git for-each-ref --sort=-committerdate refs/remotes/ --format='%(refname) %(objectname) %(committeremail)' | sed 's/refs\\/remotes\\/origin\\///g' ]
1920
- .split("\n").delete_if { |b| b.include?('HEAD') || b.include?('dev') }[0..49]
691
+ .split("\n").delete_if { |b| b.include?('HEAD') }[0..49]
1921
692
 
1922
693
  master_branch = nil
1923
694
 
@@ -1926,16 +697,20 @@ class Release
1926
697
  break unless master_branch.nil?
1927
698
  end
1928
699
 
1929
- if select_master
700
+ if select_master || branches.length == 1
1930
701
  branch_name = master_branch
1931
702
  else
703
+ branches.insert(0, branches.delete(master_branch))
1932
704
  branch_name = choose do |menu|
1933
705
  menu.prompt = "Scegli il branch di #{project_name} da deployare: ".cyan
1934
706
  menu.shell = true
1935
707
 
1936
- branches.each do |branch|
708
+ git_mail = get_git_mail
709
+
710
+ branches.each_with_index do |branch, index|
1937
711
  title = @prima.reduce_size(branch, 100)
1938
- msg = "#{title}".light_blue
712
+ msg = index.odd? ? title.white : title.light_yellow # uno bianco e uno giallo alternati
713
+ msg = branch.include?(git_mail) ? msg.on_blue : msg.on_black # i branch aggiornati da chi lancia la creazione sono su sfondo blu
1939
714
  menu.choice(msg) { branch }
1940
715
  menu.default = branch if branch == master_branch
1941
716
  end
@@ -1947,7 +722,7 @@ class Release
1947
722
  name = branch_name.split(' ')[0]
1948
723
  revision = branch_name.split(' ')[1]
1949
724
  committer_email = branch_name.split(' ')[2].tr('<>', '')
1950
- { name: name, revision: revision[0..14], committer: committer_email, default_branch: select_master }
725
+ { 'name' => name, 'revision' => revision[0..14], 'committer' => committer_email, 'default_branch' => select_master }
1951
726
  end
1952
727
 
1953
728
  def select_branch_to_deploy(project_name, branch_name)
@@ -1956,41 +731,14 @@ class Release
1956
731
  `git remote prune origin`
1957
732
  out = %x[ git fetch ]
1958
733
  branch_name = %x[ git for-each-ref --sort=-committerdate refs/remotes/ --format='%(refname) %(objectname) %(committeremail)' | sed 's/refs\\/remotes\\/origin\\///g' ]
1959
- .split("\n").delete_if { |b| !b.include?(branch_name) }[0..49]
734
+ .split("\n").delete_if { |b| !b.match("^#{Regexp.escape(branch_name)}") }[0..49]
1960
735
  .first
1961
736
 
1962
737
  Dir.chdir "../../"
1963
738
  name = branch_name.split(' ')[0]
1964
739
  revision = branch_name.split(' ')[1]
1965
740
  committer_email = branch_name.split(' ')[2].tr('<>', '')
1966
- { name: name, revision: revision[0..14], committer: committer_email }
1967
- end
1968
-
1969
- def is_branch_compatible_with_current_twig_version?(project)
1970
- case
1971
- when project == 'prima'
1972
- File.readlines("app/config/config_qa.yml").grep(/replaceme-assange.qa.staging.colaster.com/).size > 0
1973
- when project == 'urania'
1974
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1975
- when project == 'backoffice'
1976
- File.readlines("deploy/deploy.sh").grep(/HOSTNAME_PATTERN/).size > 0
1977
- when project == 'bburago'
1978
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1979
- when project == 'hal9000'
1980
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1981
- when project == 'fidaty'
1982
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1983
- when project == 'peano'
1984
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1985
- when project == 'assange'
1986
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1987
- when project == 'borat'
1988
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1989
- when project == 'crash'
1990
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1991
- when project == 'ermes'
1992
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1993
- end
741
+ { 'name' => name, 'revision' => revision[0..14], 'committer' => committer_email }
1994
742
  end
1995
743
 
1996
744
  def get_stacks()
@@ -2005,87 +753,32 @@ class Release
2005
753
  return stack_list, envs
2006
754
  end
2007
755
 
2008
- def hostname_pattern_priority()
2009
- (Time.now.to_i.to_s[-4..-1].to_i + Random.rand(40000)).to_s
2010
- end
2011
-
2012
- def launch_marley(ip_address, prima_hostname, borat_hostname)
2013
- resp = @cf.describe_stack_resource({
2014
- stack_name: 'batch-job-marley',
2015
- logical_resource_id: 'JobDefinition'
2016
- })
2017
-
2018
- @batch.submit_job({
2019
- job_name: "marley-#{@dns_record_identifier}", # required
2020
- job_queue: "marley", # required
2021
- job_definition: resp.stack_resource_detail.physical_resource_id, # required
2022
- container_overrides: {
2023
- environment: [
2024
- {
2025
- name: 'PRIMA_URL',
2026
- value: "https://#{prima_hostname}/"
2027
- },
2028
- {
2029
- name: 'PRIMA_IP',
2030
- value: ip_address
2031
- },
2032
- {
2033
- name: 'PROJECTS_JSON',
2034
- value: @projects.to_json
2035
- },
2036
- {
2037
- name: 'BACKOFFICE_URL',
2038
- value: "https://#{borat_hostname}"
2039
- }
2040
- ]
2041
- }
2042
- })
2043
-
2044
- output "Marley lanciato con successo!\n".green
2045
- end
2046
-
2047
- def get_currently_deployed_version(stack_name)
2048
- parameters = get_stack_parameters(stack_name)
2049
- currently_deployed_version = nil
2050
- parameters.each do |parameter|
2051
- if parameter.parameter_key == "ReleaseVersion"
2052
- currently_deployed_version = parameter.parameter_value
756
+ def get_clusters()
757
+ envs = {}
758
+ cluster_list = cluster_list()
759
+ cluster_list.each do |stack|
760
+ unless stack.stack_name.match(/spotfleet-allinone-qa-(\w+)$/)
761
+ env_hash = stack.stack_name.match(/qa-(\w+)$/)[0]
762
+ envs[env_hash] = stack.tags unless envs.has_key?(env_hash) || stack.tags.empty?
2053
763
  end
2054
764
  end
2055
- currently_deployed_version
765
+ return cluster_list, envs
2056
766
  end
2057
767
 
2058
- def decrypt_secrets()
2059
- docker_image = "prima/biscuit_populate_configs"
2060
- [
2061
- "docker pull #{docker_image}",
2062
- "docker run -t --rm -v $HOME/.aws:/root/.aws -v $PWD:$PWD -w $PWD #{docker_image}"
2063
- ].each do |cmd|
2064
- execute_command cmd
2065
- end
768
+ def hostname_pattern_priority()
769
+ (Time.now.to_i.to_s[-4..-1].to_i + Random.rand(40000)).to_s
2066
770
  end
2067
771
 
2068
- def select_branches(project_name = nil)
772
+ def select_branches(project_names = nil)
2069
773
  output "Deploy feature menu"
2070
- if project_name.nil?
2071
- @projects["prima"] = choose_branch_to_deploy('prima')
2072
- @projects["backoffice"] = choose_branch_to_deploy('backoffice')
2073
- @projects["urania"] = choose_branch_to_deploy('urania')
2074
- @projects["ermes"] = choose_branch_to_deploy('ermes')
2075
- @projects["bburago"] = choose_branch_to_deploy('bburago')
2076
- @projects["hal9000"] = choose_branch_to_deploy('hal9000')
2077
- @projects["fidaty"] = choose_branch_to_deploy('fidaty')
2078
- @projects["peano"] = choose_branch_to_deploy('peano')
2079
- @projects["rogoreport"] = choose_branch_to_deploy('rogoreport')
2080
- @projects["assange"] = choose_branch_to_deploy('assange')
2081
- @projects["borat"] = choose_branch_to_deploy('borat')
2082
- @projects["bolla"] = choose_branch_to_deploy('bolla')
2083
- @projects['crash'] = choose_branch_to_deploy('crash')
774
+ if project_names.nil?
775
+ @projects.each{ |key, value| @projects[key] = choose_branch_to_deploy(key) }
2084
776
  else
2085
- stop_unless File.directory?("./projects/#{project_name}"), "progetto #{project_name} inesistente o non supportato"
2086
- @projects[project_name] = choose_branch_to_deploy(project_name)
777
+ project_names.each do |project|
778
+ @projects[project] = choose_branch_to_deploy(project)
779
+ end
2087
780
  @projects.each_key do |branch_project|
2088
- @projects[branch_project] = choose_branch_to_deploy(branch_project, true) unless branch_project == project_name
781
+ @projects[branch_project] = choose_branch_to_deploy(branch_project, true) unless project_names.include? branch_project
2089
782
  end
2090
783
  end
2091
784
  end
@@ -2112,6 +805,12 @@ Description
2112
805
 
2113
806
  start creates a new feature branch
2114
807
  finish finishes the feature by merging to dev and master
808
+ qainit deploys a new environment with selected branches from every project
809
+ qainit $PROJECT_NAME deploys a new environment allowing to selected a branch from the input project (everything else is master)
810
+ qainit shutdown deletes a specific qa environment
811
+
812
+ Available only to devops (from artemide)
813
+ -----------
2115
814
  deploy deploys the feature branch to a temporary AWS Elastic Beanstalk env
2116
815
  deploy stop destroys the AWS Elastic Beanstalk env
2117
816
  deploy update updates a feature branch with current branches
@@ -2131,4 +830,11 @@ if args.include?('--help')
2131
830
  exit
2132
831
  end
2133
832
 
2134
- Release.new.execute!(args)
833
+ gem_update = true
834
+ if args.include?('no-gem-update')
835
+ gem_update = false
836
+ end
837
+
838
+ args.delete('no-gem-update')
839
+
840
+ Release.new(gem_update).execute!(args)