prima-twig 0.34.8 → 0.34.127

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