prima-twig 0.34.6 → 0.34.125

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,551 +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
- decrypt_secrets()
1402
-
1403
- [
1404
- "if echo `docker network ls` | grep crash_default; \
1405
- then echo 'crash_default network already existing'; \
1406
- else docker network create crash_default; fi",
1407
- 'docker-compose build web',
1408
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh ermes_web \
1409
- '-c' 'sed -i \"s/peano-qa-host/#{peano_qa_host}/g\" config/qa.exs && \
1410
- sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1411
- mix local.hex --force && mix hex.info && \
1412
- mix deps.get && mix compile && mix deps.compile && \
1413
- mix phx.digest && \
1414
- rm -rf _build/qa/rel/ && \
1415
- mix release --env=qa'",
1416
- "if echo `docker ps` | grep crash; \
1417
- then echo 'cannot delete crash_default network'; \
1418
- else docker network rm crash_default; fi "
1419
- ].each do |cmd|
1420
- execute_command cmd
1421
- end
1422
-
1423
- artifact_path = Dir.glob("_build/qa/rel/ermes/releases/*/ermes.tar.gz").first
1424
- upload_artifact(artifact_path, "microservices/ermes/#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1425
-
1426
- Dir.chdir '../../'
1427
- end
1428
-
1429
- def deploy_crash?
1430
- !@projects['crash'].empty? && !@projects['crash'][:default_branch]
1431
- end
1432
-
1433
- def create_crash_artifact(revision, deploy_id)
1434
- output "Preparo l'artifact crash .zip\n".yellow
1435
-
1436
- git_checkout_version('crash', revision)
1437
-
1438
- Dir.chdir 'projects/crash'
1439
-
1440
- stack_name_web = 'ecs-task-web-qa-notneeded'
1441
- web_qa_host = get_route53_hostname(stack_name_web)
1442
- stack_name_crash = 'ecs-task-crash-qa-notneeded'
1443
- crash_qa_host = get_route53_hostname(stack_name_crash)
1444
-
1445
- ws_endpoint = "wss://#{crash_qa_host}/socket/websocket?vsn=1.0.0"
1446
- frontend_endpoint = "https://#{crash_qa_host}/graphql"
1447
-
1448
- decrypt_secrets()
1449
-
1450
- [
1451
- 'mv docker-compose-ci.yml docker-compose.yml',
1452
- 'docker-compose build web',
1453
- "docker-compose run -w $PWD -e WS_ENDPOINT=#{ws_endpoint} -e GRAPHQL_ENDPOINT=#{frontend_endpoint} -e MIX_ENV=qa web \
1454
- '-c' 'sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1455
- sed -i \"s/crash-qa-host/#{crash_qa_host}/g\" config/qa.exs && \
1456
- mix local.hex --force && mix hex.info && \
1457
- mix deps.get && \
1458
- cd assets && \
1459
- yarn --cache-folder ~/.cache/yarn && \
1460
- ./node_modules/.bin/elm-github-install && \
1461
- NODE_ENV=production sysconfcpus -n 2 ./node_modules/.bin/webpack -p --config config/webpack.config.prod.js && \
1462
- cd ../ && \
1463
- mix release.clean --implode --no-confirm && \
1464
- mix phx.digest && \
1465
- mix deps.clean --all && \
1466
- mix deps.get && \
1467
- mix compile && mix release --env=qa'",
1468
- 'docker-compose down'
1469
- ].each do |cmd|
1470
- execute_command cmd
675
+ @deploy_pyxis = update_pyxis
676
+ return update_pyxis
1471
677
  end
1472
-
1473
- artifact_path = Dir.glob('_build/qa/rel/crash/releases/*/crash.tar.gz').first
1474
- upload_artifact(artifact_path, "microservices/crash/#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1475
-
1476
- Dir.chdir '../../'
1477
- end
1478
-
1479
- def create_bburago_artifact(revision)
1480
- output "Preparo l'artifact bburago .zip\n".yellow
1481
-
1482
- git_checkout_version('bburago', revision)
1483
-
1484
- Dir.chdir 'projects/bburago'
1485
-
1486
- decrypt_secrets()
1487
-
1488
- [
1489
- "docker-compose build web",
1490
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh bburago_web \
1491
- '-c' 'mix local.hex --force && mix hex.info && \
1492
- mix deps.get && mix compile && mix deps.compile && \
1493
- rm -rf _build/qa/rel/ && \
1494
- mix release --env=qa'"
1495
- ].each do |cmd|
1496
- execute_command cmd
1497
- end
1498
-
1499
- artifact_path = Dir.glob("_build/qa/rel/bburago/releases/*/bburago.tar.gz").first
1500
- upload_artifact(artifact_path, "microservices/bburago/#{revision}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1501
-
1502
- Dir.chdir '../../'
1503
- end
1504
-
1505
- def create_hal9000_artifact(revision)
1506
- output "Preparo l'artifact hal9000 .zip\n".yellow
1507
-
1508
- git_checkout_version('hal9000', revision)
1509
-
1510
- Dir.chdir 'projects/hal9000'
1511
-
1512
- decrypt_secrets()
1513
-
1514
- [
1515
- "docker-compose build web",
1516
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh hal9000_web \
1517
- '-c' 'mix local.hex --force && mix hex.info && \
1518
- mix deps.get && mix compile && mix deps.compile && \
1519
- mix phx.digest && \
1520
- rm -rf _build/qa/rel/ && \
1521
- mix release --env=qa'"
1522
- ].each do |cmd|
1523
- execute_command cmd
1524
- end
1525
-
1526
- artifact_path = Dir.glob("_build/qa/rel/hal9000/releases/*/hal9000.tar.gz").first
1527
- upload_artifact(artifact_path, "microservices/hal9000/#{revision}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1528
-
1529
- Dir.chdir '../../'
1530
- end
1531
-
1532
- def create_fidaty_artifact(revision, deploy_id)
1533
- output "Preparo l'artifact fidaty .zip\n".yellow
1534
-
1535
- git_checkout_version('fidaty', revision)
1536
-
1537
- Dir.chdir 'projects/fidaty'
1538
-
1539
- stack_name_web = "ecs-task-web-qa-notneeded"
1540
- web_qa_host = get_route53_hostname(stack_name_web)
1541
-
1542
- stack_name_peano = "ecs-task-peano-qa-notneeded"
1543
- peano_qa_host = "#{get_route53_hostname(stack_name_peano)}:10039"
1544
-
1545
- decrypt_secrets()
1546
-
1547
- [
1548
- "docker-compose build web",
1549
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh fidaty_web \
1550
- '-c' 'sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1551
- sed -i \"s/peano-qa-host/#{peano_qa_host}/g\" config/qa.exs && \
1552
- mix local.hex --force && mix hex.info && \
1553
- mix deps.get && mix compile && mix deps.compile && \
1554
- mix phx.digest && \
1555
- rm -rf _build/qa/rel/ && \
1556
- mix release --env=qa'"
1557
- ].each do |cmd|
1558
- execute_command cmd
1559
- end
1560
-
1561
- artifact_path = Dir.glob("_build/qa/rel/fidaty/releases/*/fidaty.tar.gz").first
1562
- upload_artifact(artifact_path, "microservices/fidaty/#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1563
-
1564
- Dir.chdir '../../'
1565
- end
1566
-
1567
- def create_peano_artifact(revision, deploy_id)
1568
- output "Preparo l'artifact peano .zip\n".yellow
1569
-
1570
- git_checkout_version('peano', revision)
1571
-
1572
- stack_name_assange = "ecs-task-assange-qa-notneeded"
1573
- assange_qa_host = get_route53_hostname(stack_name_assange)
1574
- stack_name_web = 'ecs-task-web-qa-notneeded'
1575
- web_qa_host = get_route53_hostname(stack_name_web)
1576
-
1577
- Dir.chdir 'projects/peano'
1578
-
1579
- 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
1580
-
1581
- decrypt_secrets()
1582
-
1583
- [
1584
- "docker-compose build web",
1585
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh peano_web \
1586
- '-c' 'mix local.hex --force && mix hex.info && \
1587
- sed -i \"s/assange-qa-host/#{assange_qa_host}/g\" config/qa.exs && \
1588
- sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1589
- mix deps.get && mix compile && mix deps.compile && \
1590
- rm -rf _build/qa/rel/ && \
1591
- mix release --env=qa'"
1592
- ].each do |cmd|
1593
- execute_command cmd
1594
- end
1595
-
1596
- artifact_path = Dir.glob("_build/qa/rel/peano/releases/*/peano.tar.gz").first
1597
- upload_artifact(artifact_path, "microservices/peano/#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1598
-
1599
- Dir.chdir '../../'
1600
- end
1601
-
1602
- def create_rogoreport_artifact(revision, deploy_id)
1603
- output "Preparo l'artifact rogoreport .zip\n".yellow
1604
-
1605
- git_checkout_version('rogoreport', revision)
1606
-
1607
- Dir.chdir 'projects/rogoreport'
1608
-
1609
- stack_name_peano = 'ecs-task-peano-qa-notneeded'
1610
- stack_name_web = 'ecs-task-web-qa-notneeded'
1611
- peano_qa_host = "#{get_route53_hostname(stack_name_peano)}:10039"
1612
- web_qa_host = get_route53_hostname(stack_name_web)
1613
-
1614
- decrypt_secrets()
1615
-
1616
- [
1617
- "docker-compose build web",
1618
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh rogoreport_web \
1619
- '-c' 'sed -i \"s/peano-qa-host/#{peano_qa_host}/g\" apps/escile/config/qa.exs && \
1620
- sed -i \"s/web-qa-host/#{web_qa_host}/g\" apps/escile/config/qa.exs && \
1621
- cat apps/escile/config/qa.exs && \
1622
- mix local.hex --force && mix hex.info && \
1623
- mix deps.get && mix compile && mix deps.compile && \
1624
- rm -rf _build/qa/rel/ && \
1625
- mix release --name=rogoreport_qa --env=qa'"
1626
- ].each do |cmd|
1627
- execute_command cmd
1628
- end
1629
-
1630
- artifact_path = Dir.glob("_build/qa/rel/rogoreport*/releases/*/rogoreport*.tar.gz").first
1631
- upload_artifact(artifact_path, "microservices/rogoreport/rogoreport_qa-#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1632
-
1633
- Dir.chdir '../../'
1634
- end
1635
-
1636
- def create_assange_artifact(revision, deploy_id)
1637
- output "Preparo l'artifact assange .zip\n".yellow
1638
-
1639
- git_checkout_version('assange', revision)
1640
-
1641
- Dir.chdir 'projects/assange'
1642
-
1643
- stack_name_web = 'ecs-task-web-qa-notneeded'
1644
- web_qa_host = get_route53_hostname(stack_name_web)
1645
-
1646
- decrypt_secrets()
1647
-
1648
- [
1649
- "docker-compose build web",
1650
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh assange_web \
1651
- '-c' 'mix local.hex --force && mix hex.info && \
1652
- sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1653
- mix deps.get && mix compile && mix deps.compile && \
1654
- mix phx.digest && \
1655
- rm -rf _build/qa/rel/ && \
1656
- mix release --env=qa'"
1657
- ].each do |cmd|
1658
- execute_command cmd
1659
- end
1660
-
1661
- artifact_path = Dir.glob("_build/qa/rel/assange/releases/*/assange.tar.gz").first
1662
- upload_artifact(artifact_path, "microservices/assange/#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1663
-
1664
- Dir.chdir '../../'
1665
- end
1666
-
1667
- def create_bolla_artifact(revision, deploy_id)
1668
- output "Preparo l'artifact bolla .zip\n".yellow
1669
-
1670
- git_checkout_version('bolla', revision)
1671
-
1672
- Dir.chdir 'projects/bolla'
1673
-
1674
- decrypt_secrets()
1675
-
1676
- [
1677
- "docker-compose build web",
1678
- "docker run -v $PWD:/code -w /code -e MIX_ENV=qa --entrypoint /bin/sh assange_web \
1679
- '-c' 'mix local.hex --force && mix hex.info && \
1680
- mix deps.get && mix compile && mix deps.compile && \
1681
- rm -rf _build/qa/rel/ && \
1682
- mix release --env=qa'"
1683
- ].each do |cmd|
1684
- execute_command cmd
1685
- end
1686
-
1687
- artifact_path = Dir.glob("_build/qa/rel/migrator/releases/*/migrator.tar.gz").first
1688
- upload_artifact(artifact_path, "microservices/bolla/#{revision}-#{deploy_id}-qa-migrator.tar.gz", "#{@s3_bucket}-encrypted")
1689
-
1690
- Dir.chdir '../../'
1691
- end
1692
-
1693
- def create_borat_artifact(revision, deploy_id)
1694
- output "Preparo l'artifact borat .zip\n".yellow
1695
-
1696
- git_checkout_version('borat', revision)
1697
-
1698
- Dir.chdir 'projects/borat'
1699
-
1700
- stack_name_web = "ecs-task-web-qa-notneeded"
1701
- web_qa_host = get_route53_hostname(stack_name_web)
1702
- stack_name_backoffice = "ecs-task-backoffice-qa-notneeded"
1703
- backoffice_qa_host = get_route53_hostname(stack_name_backoffice)
1704
- stack_name_assange = "ecs-task-assange-qa-notneeded"
1705
- assange_qa_host = get_route53_hostname(stack_name_assange)
1706
- stack_name_peano = "ecs-task-peano-qa-notneeded"
1707
- peano_qa_host = "#{get_route53_hostname(stack_name_peano)}:10039"
1708
- stack_name_borat = "ecs-task-borat-qa-notneeded"
1709
- borat_qa_host = get_route53_hostname(stack_name_borat)
1710
-
1711
- ws_endpoint = "wss://#{borat_qa_host}/socket/websocket?vsn=1.0.0"
1712
- frontend_endpoint = "https://#{web_qa_host}/"
1713
-
1714
- 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
1715
-
1716
- decrypt_secrets()
1717
-
1718
- [
1719
- "docker-compose build backend",
1720
- "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 \
1721
- '-c' 'sed -i \"s/web-qa-host/#{web_qa_host}/g\" config/qa.exs && \
1722
- sed -i \"s/backoffice-legacy-qa-host/#{backoffice_qa_host}/g\" config/qa.exs && \
1723
- sed -i \"s/assange-qa-host/#{assange_qa_host}/g\" config/qa.exs && \
1724
- sed -i \"s/peano-qa-host/#{peano_qa_host}/g\" config/qa.exs && \
1725
- sed -i \"s/borat-qa-host/#{borat_qa_host}/g\" config/qa.exs && \
1726
- mix local.hex --force && mix hex.info && \
1727
- mix deps.get && \
1728
- cd assets && \
1729
- yarn --cache-folder ~/.cache/yarn && \
1730
- ./node_modules/.bin/elm-github-install && \
1731
- sysconfcpus -n 2 ./node_modules/.bin/webpack -p --config config/webpack.config.prod.js && \
1732
- cd ../ && \
1733
- mix phx.digest && \
1734
- mix compile && mix deps.compile && \
1735
- rm -rf _build/qa/rel/ && \
1736
- mix release --env=qa'"
1737
- ].each do |cmd|
1738
- execute_command cmd
1739
- end
1740
-
1741
- artifact_path = Dir.glob("_build/qa/rel/backend/releases/*/backend.tar.gz").first
1742
- upload_artifact(artifact_path, "microservices/borat/#{revision}-#{deploy_id}-qa.tar.gz", "#{@s3_bucket}-encrypted")
1743
-
1744
- Dir.chdir '../../'
1745
- end
1746
-
1747
- def create_backoffice_artifact(revision, deploy_id)
1748
- output "Preparo l'artifact backoffice .zip\n".yellow
1749
-
1750
- git_checkout_version('backoffice', revision)
1751
-
1752
- Dir.chdir 'projects/backoffice'
1753
-
1754
- ['node_modules'].each do |dir|
1755
- unless File.directory?(dir)
1756
- if File.directory?("../../../backoffice/#{dir}")
1757
- exec_step "rsync -a ../../../backoffice/#{dir} ."
1758
- end
1759
- end
1760
- end
1761
-
1762
- stack_name_web = "ecs-task-web-qa-notneeded"
1763
- web_qa_host = get_route53_hostname(stack_name_web)
1764
- webri_qa_host = web_qa_host.sub("www", "wwwri")
1765
-
1766
- [
1767
- "docker-compose build workers",
1768
- "rm -rf src/ && git checkout -- .",
1769
- "cd ../../ && docker run -e GIT_DIR=$PWD -v $PWD:/usr/app/src -w /usr/app/src/projects/backoffice blinkmobile/bower install --allow-root",
1770
- "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'"
1771
- ].each do |cmd|
1772
- execute_command cmd
1773
- end
1774
-
1775
- artifact_path = '/tmp/backoffice.zip'
1776
- exec_step "rm -f #{artifact_path} && zip -9 -r #{artifact_path} bin/"
1777
- upload_artifact(artifact_path, "backoffice/#{revision}-#{deploy_id}.zip")
1778
-
1779
- Dir.chdir '../../'
1780
- end
1781
-
1782
- def create_prima_artifact(revision, branch_name, deploy_id)
1783
- output "Preparo l'artifact prima .zip\n".yellow
1784
-
1785
- git_checkout_version('prima', revision)
1786
-
1787
- Dir.chdir 'projects/prima'
1788
-
1789
- ['vendor'].each do |dir|
1790
- unless File.directory?(dir)
1791
- if File.directory?("../../../prima/#{dir}")
1792
- exec_step "rsync -a ../../../prima/#{dir} ."
1793
- end
1794
- end
1795
- end
1796
-
1797
- backoffice_qa_host = get_route53_hostname("ecs-task-borat-qa-notneeded")
1798
- web_qa_host = get_route53_hostname("ecs-task-web-qa-notneeded")
1799
- assange_qa_host = get_route53_hostname("ecs-task-assange-qa-notneeded")
1800
-
1801
- [
1802
- "bin/local_build_artifact.sh #{branch_name} #{web_qa_host} #{backoffice_qa_host} #{assange_qa_host} #{deploy_id} #{'update' if @deploy_update}"
1803
- ].each do |cmd|
1804
- execute_command cmd
1805
- end
1806
-
1807
- Dir.chdir "../../"
1808
- end
1809
-
1810
- def git_checkout_version(project, revision)
1811
- Dir.chdir "projects/#{project}"
1812
- exec_step "git checkout -- . && git checkout #{revision}"
1813
- Dir.chdir "../../"
1814
- end
1815
-
1816
- def create_asg_stack(stack_name, tags = [])
1817
- stack_body = IO.read('cloudformation/stacks/asg/ecs-asg-allinone.yml')
1818
- parameters = [
1819
- {
1820
- parameter_key: "Environment",
1821
- parameter_value: "qa"
1822
- },
1823
- {
1824
- parameter_key: "InstanceType",
1825
- parameter_value: "t2.large"
1826
- },
1827
- {
1828
- parameter_key: "ECSClusterName",
1829
- parameter_value: @ecs_cluster_name
1830
- }
1831
- ]
1832
- create_stack(stack_name, stack_body, parameters, tags)
1833
- end
1834
-
1835
- def create_cluster_stack(stack_name, tags = [])
1836
- stack_body = IO.read('cloudformation/stacks/ecs-cluster.yml')
1837
- create_stack(stack_name, stack_body, [], tags)
1838
678
  end
1839
679
 
1840
680
  def update_cluster_stack(stack_name, tags = [])
@@ -1842,84 +682,13 @@ class Release
1842
682
  update_stack(stack_name, stack_body, [], tags)
1843
683
  end
1844
684
 
1845
- def create_alb_stack(stack_name, role)
1846
- stack_body = IO.read('cloudformation/stacks/alb/ecs-alb-public.yml')
1847
- parameters = [
1848
- {
1849
- parameter_key: "Environment",
1850
- parameter_value: "qa"
1851
- },
1852
- {
1853
- parameter_key: "Role",
1854
- parameter_value: role
1855
- }
1856
- ]
1857
- create_stack(stack_name, stack_body, parameters)
1858
- end
1859
-
1860
- def import_redis_crash(qa_ip_address)
1861
- output "Importo dump di Redis da staging\n".yellow
1862
-
1863
- redis_qa = Redis.new(:url => "redis://#{qa_ip_address}:6379/10")
1864
-
1865
- return unless redis_qa.keys('CODICI').empty?
1866
-
1867
- redis_staging = Redis.new(:url => 'redis://staging.cache-1.prima.it:6379/10')
1868
-
1869
- dump_staging = redis_staging.dump 'CODICI'
1870
-
1871
- redis_qa.restore 'CODICI', 0, dump_staging
1872
- end
1873
-
1874
- def import_dbs(ip_address)
1875
- resp = @ecs.run_task({
1876
- cluster: @ecs_cluster_name,
1877
- task_definition: @import_db_task,
1878
- overrides: {
1879
- container_overrides: [
1880
- {
1881
- name: 'dbrestore',
1882
- environment: [
1883
- {
1884
- name: 'EC2_IP_ADDRESS',
1885
- value: ip_address
1886
- }
1887
- ]
1888
- }
1889
- ]
1890
- },
1891
- count: 1
1892
- })
1893
- output "Attendo che i DB vengano importati...\n".yellow
1894
- stopped_at = nil
1895
- while stopped_at.nil?
1896
- unless resp.tasks[0].nil?
1897
- resp = @ecs.describe_tasks({
1898
- cluster: @ecs_cluster_name,
1899
- tasks: [resp.tasks[0].task_arn]
1900
- })
1901
- end
1902
- stopped_at = resp.tasks[0].stopped_at unless resp.tasks[0].nil?
1903
- sleep_seconds = 10
1904
- seconds_elapsed = 0
1905
- while true && stopped_at.nil?
1906
- break if seconds_elapsed >= sleep_seconds
1907
- print '.'.yellow; STDOUT.flush
1908
- sleep 1
1909
- seconds_elapsed += 1
1910
- end
1911
- end
1912
- print "\n"
1913
- end
1914
-
1915
685
  def choose_branch_to_deploy(project_name, select_master = false)
1916
- return {} if project_name == 'crash' && select_master
1917
686
  Dir.chdir "projects/#{project_name}"
1918
687
  output "Recupero la lista dei branch del progetto #{project_name}..."
1919
688
  `git remote prune origin`
1920
689
  out = %x[ git fetch ]
1921
690
  branches = %x[ git for-each-ref --sort=-committerdate refs/remotes/ --format='%(refname) %(objectname) %(committeremail)' | sed 's/refs\\/remotes\\/origin\\///g' ]
1922
- .split("\n").delete_if { |b| b.include?('HEAD') || b.include?('dev') }[0..49]
691
+ .split("\n").delete_if { |b| b.include?('HEAD') }[0..49]
1923
692
 
1924
693
  master_branch = nil
1925
694
 
@@ -1928,16 +697,20 @@ class Release
1928
697
  break unless master_branch.nil?
1929
698
  end
1930
699
 
1931
- if select_master
700
+ if select_master || branches.length == 1
1932
701
  branch_name = master_branch
1933
702
  else
703
+ branches.insert(0, branches.delete(master_branch))
1934
704
  branch_name = choose do |menu|
1935
705
  menu.prompt = "Scegli il branch di #{project_name} da deployare: ".cyan
1936
706
  menu.shell = true
1937
707
 
1938
- branches.each do |branch|
708
+ git_mail = get_git_mail
709
+
710
+ branches.each_with_index do |branch, index|
1939
711
  title = @prima.reduce_size(branch, 100)
1940
- 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
1941
714
  menu.choice(msg) { branch }
1942
715
  menu.default = branch if branch == master_branch
1943
716
  end
@@ -1949,7 +722,7 @@ class Release
1949
722
  name = branch_name.split(' ')[0]
1950
723
  revision = branch_name.split(' ')[1]
1951
724
  committer_email = branch_name.split(' ')[2].tr('<>', '')
1952
- { 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 }
1953
726
  end
1954
727
 
1955
728
  def select_branch_to_deploy(project_name, branch_name)
@@ -1958,41 +731,14 @@ class Release
1958
731
  `git remote prune origin`
1959
732
  out = %x[ git fetch ]
1960
733
  branch_name = %x[ git for-each-ref --sort=-committerdate refs/remotes/ --format='%(refname) %(objectname) %(committeremail)' | sed 's/refs\\/remotes\\/origin\\///g' ]
1961
- .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]
1962
735
  .first
1963
736
 
1964
737
  Dir.chdir "../../"
1965
738
  name = branch_name.split(' ')[0]
1966
739
  revision = branch_name.split(' ')[1]
1967
740
  committer_email = branch_name.split(' ')[2].tr('<>', '')
1968
- { name: name, revision: revision[0..14], committer: committer_email }
1969
- end
1970
-
1971
- def is_branch_compatible_with_current_twig_version?(project)
1972
- case
1973
- when project == 'prima'
1974
- File.readlines("app/config/config_qa.yml").grep(/replaceme-assange.qa.staging.colaster.com/).size > 0
1975
- when project == 'urania'
1976
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1977
- when project == 'backoffice'
1978
- File.readlines("deploy/deploy.sh").grep(/HOSTNAME_PATTERN/).size > 0
1979
- when project == 'bburago'
1980
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1981
- when project == 'hal9000'
1982
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1983
- when project == 'fidaty'
1984
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1985
- when project == 'peano'
1986
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1987
- when project == 'assange'
1988
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1989
- when project == 'borat'
1990
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1991
- when project == 'crash'
1992
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1993
- when project == 'ermes'
1994
- File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
1995
- end
741
+ { 'name' => name, 'revision' => revision[0..14], 'committer' => committer_email }
1996
742
  end
1997
743
 
1998
744
  def get_stacks()
@@ -2007,87 +753,32 @@ class Release
2007
753
  return stack_list, envs
2008
754
  end
2009
755
 
2010
- def hostname_pattern_priority()
2011
- (Time.now.to_i.to_s[-4..-1].to_i + Random.rand(40000)).to_s
2012
- end
2013
-
2014
- def launch_marley(ip_address, prima_hostname, borat_hostname)
2015
- resp = @cf.describe_stack_resource({
2016
- stack_name: 'batch-job-marley',
2017
- logical_resource_id: 'JobDefinition'
2018
- })
2019
-
2020
- @batch.submit_job({
2021
- job_name: "marley-#{@dns_record_identifier}", # required
2022
- job_queue: "marley", # required
2023
- job_definition: resp.stack_resource_detail.physical_resource_id, # required
2024
- container_overrides: {
2025
- environment: [
2026
- {
2027
- name: 'PRIMA_URL',
2028
- value: "https://#{prima_hostname}/"
2029
- },
2030
- {
2031
- name: 'PRIMA_IP',
2032
- value: ip_address
2033
- },
2034
- {
2035
- name: 'PROJECTS_JSON',
2036
- value: @projects.to_json
2037
- },
2038
- {
2039
- name: 'BACKOFFICE_URL',
2040
- value: "https://#{borat_hostname}"
2041
- }
2042
- ]
2043
- }
2044
- })
2045
-
2046
- output "Marley lanciato con successo!\n".green
2047
- end
2048
-
2049
- def get_currently_deployed_version(stack_name)
2050
- parameters = get_stack_parameters(stack_name)
2051
- currently_deployed_version = nil
2052
- parameters.each do |parameter|
2053
- if parameter.parameter_key == "ReleaseVersion"
2054
- 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?
2055
763
  end
2056
764
  end
2057
- currently_deployed_version
765
+ return cluster_list, envs
2058
766
  end
2059
767
 
2060
- def decrypt_secrets()
2061
- docker_image = "prima/biscuit_populate_configs"
2062
- [
2063
- "docker pull #{docker_image}",
2064
- "docker run -t --rm -v $HOME/.aws:/root/.aws -v $PWD:$PWD -w $PWD #{docker_image}"
2065
- ].each do |cmd|
2066
- execute_command cmd
2067
- end
768
+ def hostname_pattern_priority()
769
+ (Time.now.to_i.to_s[-4..-1].to_i + Random.rand(40000)).to_s
2068
770
  end
2069
771
 
2070
- def select_branches(project_name = nil)
772
+ def select_branches(project_names = nil)
2071
773
  output "Deploy feature menu"
2072
- if project_name.nil?
2073
- @projects["prima"] = choose_branch_to_deploy('prima')
2074
- @projects["backoffice"] = choose_branch_to_deploy('backoffice')
2075
- @projects["urania"] = choose_branch_to_deploy('urania')
2076
- @projects["ermes"] = choose_branch_to_deploy('ermes')
2077
- @projects["bburago"] = choose_branch_to_deploy('bburago')
2078
- @projects["hal9000"] = choose_branch_to_deploy('hal9000')
2079
- @projects["fidaty"] = choose_branch_to_deploy('fidaty')
2080
- @projects["peano"] = choose_branch_to_deploy('peano')
2081
- @projects["rogoreport"] = choose_branch_to_deploy('rogoreport')
2082
- @projects["assange"] = choose_branch_to_deploy('assange')
2083
- @projects["borat"] = choose_branch_to_deploy('borat')
2084
- @projects["bolla"] = choose_branch_to_deploy('bolla')
2085
- @projects['crash'] = choose_branch_to_deploy('crash')
774
+ if project_names.nil?
775
+ @projects.each{ |key, value| @projects[key] = choose_branch_to_deploy(key) }
2086
776
  else
2087
- stop_unless File.directory?("./projects/#{project_name}"), "progetto #{project_name} inesistente o non supportato"
2088
- @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
2089
780
  @projects.each_key do |branch_project|
2090
- @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
2091
782
  end
2092
783
  end
2093
784
  end
@@ -2114,6 +805,12 @@ Description
2114
805
 
2115
806
  start creates a new feature branch
2116
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
+ -----------
2117
814
  deploy deploys the feature branch to a temporary AWS Elastic Beanstalk env
2118
815
  deploy stop destroys the AWS Elastic Beanstalk env
2119
816
  deploy update updates a feature branch with current branches
@@ -2133,4 +830,11 @@ if args.include?('--help')
2133
830
  exit
2134
831
  end
2135
832
 
2136
- 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)