prima-twig 1.2.6 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 665845adb115e9091a4d63673e3386d7b50e2043350ee342daee36122a6807f1
4
- data.tar.gz: d92dc143955f44ae455eb20bead9668737183bfab7fa7f62c9b116e279c9538e
3
+ metadata.gz: 51cb0052822145cda1bf819fcfe58de19406d13d3a1124220e0b46c029d386b9
4
+ data.tar.gz: 0771ece2ce724ae9aa119fa6dbb6b2532083fb2a9aaef73f23a2fc2586a28ee5
5
5
  SHA512:
6
- metadata.gz: 27bcc7a32bc312e359015843c05ad59872d54582ce342587894489407a6c48dbbce6997a7cbc5be2e7d246aead9dc0f235996658e450810e4409b829a670428a
7
- data.tar.gz: 2474944753cd11b793107b6b8de274e7460ea2f54a2587ee43f3bef89ca2ef2278b40f861e5198a79c4fb8acce32a1e14c6bc684b479e0a5b188417b2c939462
6
+ metadata.gz: 4301bf537b0eb0971092f3ff7118dc4b4a75ba077509a97be26af3145bbd153a0a8f20cb896a9a4d3829ace185c159564d80381ec72ef4cf2acd7744e8a284db
7
+ data.tar.gz: f97669324765a6445657d49649b06d1c740a737f9b71fc874585bdb476dbeaea8fa09036d28517cf1594358f14f938161050f8374d862f7d412a0c5309639e3d
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rubygems'
4
- require_relative '../lib/prima_twig.rb'
5
- require_relative '../lib/prima_aws_client.rb'
4
+ require_relative '../lib/prima_twig'
5
+ require_relative '../lib/prima_aws_client'
6
6
  require 'digest'
7
7
  require 'json'
8
8
  require 'launchy'
@@ -14,11 +14,11 @@ class Release
14
14
  include Command
15
15
  include PrimaAwsClient
16
16
 
17
- def initialize(update_gem=true)
17
+ def initialize(update_gem = true)
18
18
  @prima = Prima.new
19
19
  if update_gem
20
20
  output 'Controllo se ci sono aggiornamenti da fare (potrebbe richiedere qualche minuto)'
21
- unless `gem update prima-twig`=="Updating installed gems\nNothing to update\n"
21
+ unless `gem update prima-twig` == "Updating installed gems\nNothing to update\n"
22
22
  output 'Gemma prima-twig aggiornata'
23
23
  exec "twig feature #{ARGV.join ' '}"
24
24
  end
@@ -47,20 +47,22 @@ class Release
47
47
  'legion' => {},
48
48
  'vianello' => {},
49
49
  'domus' => {},
50
- 'toretto' => {}
50
+ 'toretto' => {},
51
+ 'lira' => {},
52
+ 'frontale' => {}
51
53
  }
52
54
  @base_stack_name_alb = 'ecs-alb-http-public-qa-'
53
55
  @base_stack_name_alb_ws = 'ecs-alb-ws-public-qa-'
54
56
  @cloudflare = Rubyflare.connect_with(ENV['CLOUDFLARE_EMAIL'], ENV['CLOUDFLARE_APIKEY'])
55
57
  @config = YAML.load_file 'twig.yml'
56
- @gh = Octokit::Client.new(:access_token => @config['github'])
58
+ @gh = Octokit::Client.new(access_token: @config['github'])
57
59
  end
58
60
 
59
61
  def execute!(args)
60
62
  case args[0]
61
63
  when 'qainit'
62
- abort('Non sei nella cartella di qainit') unless Dir.pwd.match 'qainit$' or Dir.pwd.match '/drone/src'
63
- if ['terminate', 'stop', 'shutdown', 'halt', 'destroy'].include? args[1]
64
+ abort('Non sei nella cartella di qainit') unless Dir.pwd.match('qainit$') || Dir.pwd.match('/drone/src')
65
+ if %w[terminate stop shutdown halt destroy].include? args[1]
64
66
  qainit_deploy_shutdown!
65
67
  elsif 'update' == args[1]
66
68
  qainit_deploy_update!
@@ -75,13 +77,11 @@ class Release
75
77
  when 'suite'
76
78
  abort('Non sei nella cartella di qainit') unless Dir.pwd.match 'qainit$'
77
79
  if 'deploy' == args[1]
78
- suite_py_branches()
80
+ suite_py_branches
79
81
  qainit_deploy!(true)
80
82
  end
81
83
  when 'deploy'
82
- if 'lock' == args[1]
83
- deploy_lock!
84
- end
84
+ deploy_lock! if 'lock' == args[1]
85
85
  when 'aggregator'
86
86
  if 'enable' == args[1]
87
87
  aggregator_enable!
@@ -103,25 +103,25 @@ class Release
103
103
  def aggregator_disable!
104
104
  output 'Disable aggregator'
105
105
 
106
- output "Recupero le informazioni relative al puntamento dei record DNS..."
107
- output "Recupero le informazioni sui QA attivi..."
108
- stack_list, envs = get_stacks()
106
+ output 'Recupero le informazioni relative al puntamento dei record DNS...'
107
+ output 'Recupero le informazioni sui QA attivi...'
108
+ stack_list, envs = get_stacks
109
109
 
110
110
  env_hash = nil
111
- unless envs.empty?
112
- env_hash = envs.detect do |key, tags|
111
+ if envs.empty?
112
+ output 'Nessun QA trovato'.red
113
+ exit
114
+ else
115
+ env_hash = envs.detect do |_key, tags|
113
116
  aggregator_enabled = tags.detect do |tag|
114
- tag.key === "hostname_pattern_priority" and tag.value === "1"
117
+ tag.key === 'hostname_pattern_priority' and tag.value === '1'
115
118
  end.is_a?(Aws::CloudFormation::Types::Tag)
116
119
  aggregator_enabled
117
120
  end[0]
118
- 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])})
119
- stop_if dns_records.body[:result].empty?, "I record DNS degli aggregatori non stanno puntando ad un QA".red
120
- change_hostname_priority(env_hash, hostname_pattern_priority())
121
+ 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]) })
122
+ stop_if dns_records.body[:result].empty?, 'I record DNS degli aggregatori non stanno puntando ad un QA'.red
123
+ change_hostname_priority(env_hash, hostname_pattern_priority)
121
124
  dns_to_staging(env_hash)
122
- else
123
- output 'Nessun QA trovato'.red
124
- exit
125
125
  end
126
126
 
127
127
  output 'Finito!'.green
@@ -134,46 +134,46 @@ class Release
134
134
  dns_records = @cloudflare.get('zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records', { per_page: 100, type: 'CNAME', content: 'staging.prima.it' })
135
135
  stop_if dns_records.body[:result].empty?, "I record DNS degli aggregatori stanno gia' puntando ad un QA".red
136
136
 
137
- output "Recupero le informazioni sui QA attivi..."
138
- stack_list, envs = get_stacks()
137
+ output 'Recupero le informazioni sui QA attivi...'
138
+ stack_list, envs = get_stacks
139
139
 
140
140
  env_hash = nil
141
- unless envs.empty?
141
+ if envs.empty?
142
+ output 'Nessun QA trovato'.red
143
+ exit
144
+ else
142
145
  env_hash = choose do |menu|
143
- menu.prompt = "Scegli il QA al quale vuoi far puntare gli ambienti di staging dei comparatori: ".cyan
146
+ menu.prompt = 'Scegli il QA al quale vuoi far puntare gli ambienti di staging dei comparatori: '.cyan
144
147
  menu.shell = true
145
148
  envs.each do |key, env|
146
- title = ""
149
+ title = ''
147
150
  env.each do |e|
148
151
  title << "\n#{e.key.upcase}: #{e.value}"
149
152
  end
150
- msg = "#{@prima.reduce_size(title, 1000)}".light_blue
153
+ msg = @prima.reduce_size(title, 1000).to_s.light_blue
151
154
  menu.choice(msg) { key }
152
155
  end
153
156
  end
154
- else
155
- output "Nessun QA trovato".red
156
- exit
157
157
  end
158
158
 
159
- change_hostname_priority(env_hash, "1")
159
+ change_hostname_priority(env_hash, '1')
160
160
 
161
161
  dns_records.body[:result].each do |dns|
162
- if dns[:name] =~ /^\w+\-\w+\-staging\.prima\.it$/
162
+ if dns[:name] =~ /^\w+-\w+-staging\.prima\.it$/
163
163
  output "Changing #{dns[:name]} DNS record"
164
- @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})
164
+ @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 })
165
165
  end
166
166
  end
167
167
 
168
- output "Finito!".green
168
+ output 'Finito!'.green
169
169
  end
170
170
 
171
171
  def change_hostname_priority(env_hash, hostname_pattern_priority)
172
172
  cluster_stack_name = "ecs-cluster-#{env_hash}"
173
173
  tags = get_stack_tags(cluster_stack_name).map do |tag|
174
- if tag.key === "hostname_pattern_priority"
174
+ if tag.key === 'hostname_pattern_priority'
175
175
  {
176
- key: "hostname_pattern_priority",
176
+ key: 'hostname_pattern_priority',
177
177
  value: hostname_pattern_priority
178
178
  }
179
179
  else
@@ -198,14 +198,14 @@ class Release
198
198
 
199
199
  stack_name_web = "ecs-task-web-#{env_hash}"
200
200
  parameters = get_stack_parameters(stack_name_web).map do |param|
201
- if param.parameter_key === "HostnamePatternPriority"
201
+ if param.parameter_key === 'HostnamePatternPriority'
202
202
  {
203
- parameter_key: "HostnamePatternPriority",
203
+ parameter_key: 'HostnamePatternPriority',
204
204
  parameter_value: hostname_pattern_priority
205
205
  }
206
- elsif param.parameter_key === "HostnamePatternAggregatorPriority"
206
+ elsif param.parameter_key === 'HostnamePatternAggregatorPriority'
207
207
  {
208
- parameter_key: "HostnamePatternAggregatorPriority",
208
+ parameter_key: 'HostnamePatternAggregatorPriority',
209
209
  parameter_value: (hostname_pattern_priority.to_i + 1).to_s
210
210
  }
211
211
  else
@@ -219,22 +219,25 @@ class Release
219
219
  end
220
220
 
221
221
  def dns_to_staging(env_hash)
222
- output "Recupero le informazioni relative al puntamento dei record DNS..."
223
- 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])})
222
+ output 'Recupero le informazioni relative al puntamento dei record DNS...'
223
+ 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]) })
224
224
  dns_records.body[:result].each do |dns|
225
- if dns[:name] =~ /^\w+\-\w+\-staging\.prima\.it$/
225
+ if dns[:name] =~ /^\w+-\w+-staging\.prima\.it$/
226
226
  output "Changing #{dns[:name]} DNS record"
227
- @cloudflare.put("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records/#{dns[:id]}", {type: 'CNAME', name: dns[:name], content: 'staging.prima.it', proxied: true, ttl: 1})
227
+ @cloudflare.put("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records/#{dns[:id]}", { type: 'CNAME', name: dns[:name], content: 'staging.prima.it', proxied: true, ttl: 1 })
228
228
  end
229
229
  end
230
230
  end
231
231
 
232
232
  def deploy_shutdown!
233
- output "Recupero le informazioni sui QA attivi..."
233
+ output 'Recupero le informazioni sui QA attivi...'
234
234
  stack_list, envs = get_stacks
235
235
 
236
236
  env_hash = nil
237
- unless envs.empty?
237
+ if envs.empty?
238
+ output 'Nessun environment trovato'.red
239
+ exit
240
+ else
238
241
  env_hash = choose do |menu|
239
242
  menu.prompt = "Scegli l'environment che vuoi spegnere: ".cyan
240
243
  menu.shell = true
@@ -248,9 +251,6 @@ class Release
248
251
  menu.choice(msg) { key }
249
252
  end
250
253
  end
251
- else
252
- output 'Nessun environment trovato'.red
253
- exit
254
254
  end
255
255
 
256
256
  cluster_stack_name = nil
@@ -261,6 +261,7 @@ class Release
261
261
  cluster_stack_name = stack.stack_name
262
262
  else
263
263
  break unless stack.stack_name.match(/#{env_hash}$/)
264
+
264
265
  stacks_to_delete.push(stack.stack_name)
265
266
  delete_stack(stack.stack_name)
266
267
  end
@@ -269,138 +270,134 @@ class Release
269
270
 
270
271
  cluster_stack_name = "ecs-cluster-#{env_hash}"
271
272
  aggregator_enabled = get_stack_tags(cluster_stack_name).detect do |tag|
272
- tag.key === "hostname_pattern_priority" and tag.value === "1"
273
+ tag.key === 'hostname_pattern_priority' and tag.value === '1'
273
274
  end.is_a?(Aws::CloudFormation::Types::Tag)
274
275
 
275
- if aggregator_enabled
276
- dns_to_staging(env_hash)
277
- end
276
+ dns_to_staging(env_hash) if aggregator_enabled
278
277
 
279
278
  # Se non ha finito di cancellare le altre non si puo' cancellare il cluster
280
- output "Attendo 10 secondi per poter eliminare il cluster ECS"
279
+ output 'Attendo 10 secondi per poter eliminare il cluster ECS'
281
280
 
282
281
  while stacks_to_delete.length > 0
283
282
  sleep 13
284
283
  stacks_to_delete.each do |stack_name|
285
- stacks_to_delete = stacks_to_delete - [stack_name] unless stack_exists?(stack_name)
284
+ stacks_to_delete -= [stack_name] unless stack_exists?(stack_name)
286
285
  end
287
- output "Stack ancora attivi: #{stacks_to_delete.length.to_s}. Attendo altri 10 secondi per eliminare il cluster ECS"
286
+ output "Stack ancora attivi: #{stacks_to_delete.length}. Attendo altri 10 secondi per eliminare il cluster ECS"
288
287
  end
289
288
 
290
289
  delete_stack(cluster_stack_name)
291
290
  delete_stack(@base_stack_name_alb + env_hash[3..8])
292
291
  delete_stack(@base_stack_name_alb_ws + env_hash[3..8])
293
- output "Finito!".green
292
+ output 'Finito!'.green
294
293
  end
295
294
 
296
295
  def deploy_lock!
297
- output "Deploy update menu"
296
+ output 'Deploy update menu'
298
297
  `git pull`
299
298
 
300
- output "Recupero le informazioni sui QA attivi..."
301
- stack_list, envs = get_clusters()
299
+ output 'Recupero le informazioni sui QA attivi...'
300
+ stack_list, envs = get_clusters
302
301
 
303
302
  env_hash = nil
304
- unless envs.empty?
303
+ if envs.empty?
304
+ output 'Nessun QA trovato'.red
305
+ exit
306
+ else
305
307
  env_hash = choose do |menu|
306
- menu.prompt = "Scegli il QA che vuoi proteggere dallo spegnimento automatico: ".cyan
308
+ menu.prompt = 'Scegli il QA che vuoi proteggere dallo spegnimento automatico: '.cyan
307
309
  menu.shell = true
308
310
  envs.each do |key, env|
309
- title = ""
311
+ title = ''
310
312
  env.each do |e|
311
- title << "#{e.value}" if e.key == 'qainit'
313
+ title << e.value.to_s if e.key == 'qainit'
312
314
  end
313
- msg = "#{@prima.reduce_size(title, 1000)}".light_blue
315
+ msg = @prima.reduce_size(title, 1000).to_s.light_blue
314
316
  menu.choice(msg) { key }
315
317
  end
316
318
  end
317
- else
318
- output "Nessun QA trovato".red
319
- exit
320
319
  end
321
320
 
322
321
  cluster_stack_name = "ecs-cluster-#{env_hash}"
323
322
  if stack_exists?(cluster_stack_name)
324
323
  tags = get_stack_tags(cluster_stack_name)
325
- tag_keep_data = Aws::CloudFormation::Types::Tag.new({key:'AUTOMATIC_DELETION_PROTECTION', value:'true'})
324
+ tag_keep_data = Aws::CloudFormation::Types::Tag.new({ key: 'AUTOMATIC_DELETION_PROTECTION', value: 'true' })
326
325
  tags.push tag_keep_data
327
326
  end
328
327
 
329
328
  update_cluster_stack(cluster_stack_name, tags, get_stack_parameters(cluster_stack_name))
330
329
 
331
- output "Finito!".green
330
+ output 'Finito!'.green
332
331
  end
333
332
 
334
333
  def deploy_update!
335
- output "Deploy update menu"
334
+ output 'Deploy update menu'
336
335
  `git pull`
337
336
 
338
- output "Recupero le informazioni sui QA attivi..."
339
- stack_list, envs = get_stacks()
337
+ output 'Recupero le informazioni sui QA attivi...'
338
+ stack_list, envs = get_stacks
340
339
 
341
340
  env_hash = nil
342
- unless envs.empty?
341
+ if envs.empty?
342
+ output 'Nessun QA trovato'.red
343
+ exit
344
+ else
343
345
  env_hash = choose do |menu|
344
- menu.prompt = "Scegli il QA che vuoi aggiornare: ".cyan
346
+ menu.prompt = 'Scegli il QA che vuoi aggiornare: '.cyan
345
347
  menu.shell = true
346
348
  envs.each do |key, env|
347
- title = ""
349
+ title = ''
348
350
  env.each do |e|
349
351
  title << "\n#{e.key.upcase}: #{e.value}"
350
352
  end
351
- msg = "#{@prima.reduce_size(title, 1000)}".light_blue
353
+ msg = @prima.reduce_size(title, 1000).to_s.light_blue
352
354
  menu.choice(msg) { key }
353
355
  end
354
356
  end
355
- else
356
- output "Nessun QA trovato".red
357
- exit
358
357
  end
359
358
 
360
359
  envs[env_hash].each do |env|
361
- unless ['hostname_pattern_priority', 'AUTOMATIC_DELETION_PROTECTION'].include? env.key
360
+ unless %w[hostname_pattern_priority AUTOMATIC_DELETION_PROTECTION].include? env.key
362
361
  @projects[env.key] = select_branch_to_deploy(env.key, env.value)
363
362
  end
364
363
  end
365
364
  deploy_feature!
366
365
 
367
- output "Finito!".green
366
+ output 'Finito!'.green
368
367
  end
369
368
 
370
369
  def get_default_branch_name(projects)
371
370
  projects.each_key do |project|
372
- return projects[project]['name'] if not projects[project]['default_branch']
371
+ return projects[project]['name'] unless projects[project]['default_branch']
373
372
  end
374
373
  end
375
374
 
376
- def suite_py_branches()
377
- if File.exist?("suitepy-projects.yml")
378
- arg_projects = YAML.load(File.read("suitepy-projects.yml"))
375
+ def suite_py_branches
376
+ if File.exist?('suitepy-projects.yml')
377
+ arg_projects = YAML.load(File.read('suitepy-projects.yml'))
379
378
 
380
379
  @projects.merge!(arg_projects)
381
380
 
382
381
  `rm suitepy-projects.yml`
383
382
 
384
383
  @projects.each_key do |project|
385
- if @projects[project].empty?
386
- @projects[project] = choose_branch_to_deploy(project, true)
387
- end
384
+ @projects[project] = choose_branch_to_deploy(project, true) if @projects[project].empty?
388
385
  end
389
386
  end
390
387
  end
391
388
 
392
- def get_git_user()
389
+ def get_git_user
393
390
  `git config user.name`.gsub(/[^A-Za-z]/, '').gsub("\n", '')
394
391
  end
395
392
 
396
- def get_git_mail()
393
+ def get_git_mail
397
394
  `git config user.email`.gsub("\n", '')
398
395
  end
399
396
 
400
397
  def qainit_deploy!(quiet = false)
401
- `git checkout master && git pull && git remote prune origin`
398
+ `git checkout master && git fetch && git pull && git remote prune origin`
402
399
 
403
- `git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D`
400
+ `git fetch -p && for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}'); do git branch -D $branch; done`
404
401
 
405
402
  default_name = get_default_branch_name @projects
406
403
  feature_number = ''
@@ -417,7 +414,7 @@ class Release
417
414
  `git checkout -b #{branch_name}`
418
415
  end
419
416
 
420
- File.open("projects.yml", "w") { |file| file.write(@projects.to_yaml) }
417
+ File.open('projects.yml', 'w') { |file| file.write(@projects.to_yaml) }
421
418
 
422
419
  update_drone_yml!
423
420
 
@@ -436,7 +433,7 @@ class Release
436
433
  git_user = get_git_user
437
434
  # stampiamo la lista
438
435
  chosen_branch = choose do |menu|
439
- menu.prompt = "Scegli il QA che vuoi aggiornare: ".cyan
436
+ menu.prompt = 'Scegli il QA che vuoi aggiornare: '.cyan
440
437
  menu.shell = true
441
438
  former_branches.delete('master')
442
439
  former_branches.each_with_index do |branch, index|
@@ -451,14 +448,14 @@ class Release
451
448
  # aggiornare il commit (revision a cui fa riferimento)
452
449
 
453
450
  # leggo il file projects.yml / recupero i nomi dei branch / riscrivo tutto
454
- projects = YAML.load(File.read("projects.yml"))
451
+ projects = YAML.load(File.read('projects.yml'))
455
452
 
456
453
  projects.each do |key, project|
457
454
  @projects[key] = select_branch_to_deploy(key, project['name'])
458
455
  @projects[key]['default_branch'] = project['default_branch']
459
456
  end
460
457
 
461
- File.open("projects.yml", "w") { |file| file.write(@projects.to_yaml) }
458
+ File.open('projects.yml', 'w') { |file| file.write(@projects.to_yaml) }
462
459
 
463
460
  update_drone_yml!
464
461
 
@@ -474,7 +471,7 @@ class Release
474
471
  if selection.nil?
475
472
  # stampiamo la lista
476
473
  chosen_branch = choose do |menu|
477
- menu.prompt = "Scegli il QA che vuoi spegnere: ".cyan
474
+ menu.prompt = 'Scegli il QA che vuoi spegnere: '.cyan
478
475
  menu.shell = true
479
476
  git_user = get_git_user
480
477
  former_branches.delete('master')
@@ -493,10 +490,10 @@ class Release
493
490
  end
494
491
 
495
492
  def qainit_drone_shutdown!
496
- output "Recupero le informazioni sui QA attivi..."
493
+ output 'Recupero le informazioni sui QA attivi...'
497
494
  stack_list, envs = get_stacks
498
495
 
499
- env_hash = "qa-" + get_deploy_id
496
+ env_hash = 'qa-' + get_deploy_id
500
497
 
501
498
  cluster_stack_name = nil
502
499
  stacks_to_delete = []
@@ -506,6 +503,7 @@ class Release
506
503
  cluster_stack_name = stack.stack_name
507
504
  else
508
505
  break unless stack.stack_name.match(/#{env_hash}$/)
506
+
509
507
  stacks_to_delete.push(stack.stack_name)
510
508
  delete_stack(stack.stack_name)
511
509
  end
@@ -515,47 +513,45 @@ class Release
515
513
  cluster_stack_name = "ecs-cluster-#{env_hash}"
516
514
  if stack_exists?(cluster_stack_name)
517
515
  aggregator_enabled = get_stack_tags(cluster_stack_name).detect do |tag|
518
- tag.key === "hostname_pattern_priority" and tag.value === "1"
516
+ tag.key === 'hostname_pattern_priority' and tag.value === '1'
519
517
  end.is_a?(Aws::CloudFormation::Types::Tag)
520
518
 
521
- if aggregator_enabled
522
- dns_to_staging(env_hash)
523
- end
519
+ dns_to_staging(env_hash) if aggregator_enabled
524
520
  end
525
521
 
526
522
  # Se non ha finito di cancellare le altre non si puo' cancellare il cluster
527
- output "Attendo 10 secondi per poter eliminare il cluster ECS"
523
+ output 'Attendo 10 secondi per poter eliminare il cluster ECS'
528
524
 
529
525
  while stacks_to_delete.length > 0
530
526
  sleep 13
531
527
  stacks_to_delete.each do |stack_name|
532
- stacks_to_delete = stacks_to_delete - [stack_name] unless stack_exists?(stack_name)
528
+ stacks_to_delete -= [stack_name] unless stack_exists?(stack_name)
533
529
  end
534
- output "Stack ancora attivi: #{stacks_to_delete.length.to_s}. Attendo altri 10 secondi per eliminare il cluster ECS"
530
+ output "Stack ancora attivi: #{stacks_to_delete.length}. Attendo altri 10 secondi per eliminare il cluster ECS"
535
531
  end
536
532
 
537
533
  delete_stack(cluster_stack_name) if stack_exists?(cluster_stack_name)
538
534
  delete_stack(@base_stack_name_alb + env_hash[3..8]) if stack_exists?(@base_stack_name_alb + env_hash[3..8])
539
535
  delete_stack(@base_stack_name_alb_ws + env_hash[3..8]) if stack_exists?(@base_stack_name_alb_ws + env_hash[3..8])
540
536
  `git checkout master && git push origin --delete ${DRONE_BRANCH}`
541
- output "Cancello il record DNS utilizzato da Lighthouse"
542
- delete_lighthouse_dns()
543
- output "Finito!".green
537
+ output 'Cancello il record DNS utilizzato da Lighthouse'
538
+ delete_lighthouse_dns
539
+ output 'Finito!'.green
544
540
  end
545
541
 
546
542
  def qainit_write_output(file_message, output_message)
547
543
  `mkdir -p /etc/qainit-output`
548
- qa_file_name = "/etc/qainit-output/url_qa"
544
+ qa_file_name = '/etc/qainit-output/url_qa'
549
545
  File.open(qa_file_name + '.txt', 'w') { |file| file.write(file_message) }
550
546
  output "#{output_message} #{qa_file_name}".green
551
547
  end
552
548
 
553
- def update_drone_yml!()
549
+ def update_drone_yml!
554
550
  drone_yml = File.read('.drone.yml')
555
551
  @projects.each do |key, project|
556
552
  drone_yml = drone_yml.gsub(/#{key}@.+\n/, "#{key}@#{project['revision']}\n")
557
553
  end
558
- File.open(".drone.yml", "w") do |f|
554
+ File.open('.drone.yml', 'w') do |f|
559
555
  f.write(drone_yml)
560
556
  end
561
557
  end
@@ -570,10 +566,9 @@ class Release
570
566
  end
571
567
 
572
568
  def get_alb_host(stack_name)
573
- case
574
- when stack_name.include?('alb-http-public')
569
+ if stack_name.include?('alb-http-public')
575
570
  logical_resource_id = 'EcsApplicationLoadBalancerPublic'
576
- when stack_name.include?('alb-ws-public')
571
+ elsif stack_name.include?('alb-ws-public')
577
572
  logical_resource_id = 'EcsApplicationLoadBalancerPublic'
578
573
  end
579
574
  resp = describe_stack_resource(stack_name, logical_resource_id)
@@ -589,8 +584,8 @@ class Release
589
584
  def choose_branch_to_deploy(project_name, select_master = false)
590
585
  # chiamare api octokit per recuperare i branch/commit
591
586
  output "Recupero la lista dei branch del progetto #{project_name}..."
592
- branches = @gh.branches("primait/#{project_name}", {per_page: 100})
593
- master_branch = branches.select {|branch| branch[:name] == 'master'}[0]
587
+ branches = @gh.branches("primait/#{project_name}", { per_page: 100 })
588
+ master_branch = branches.select { |branch| branch[:name] == 'master' }[0]
594
589
 
595
590
  if select_master || branches.length == 1
596
591
  branch_name = 'master'
@@ -612,7 +607,7 @@ class Release
612
607
  end
613
608
  end
614
609
 
615
- chosen_branch = branches.select {|branch| branch[:name] == branch_name}[0]
610
+ chosen_branch = branches.select { |branch| branch[:name] == branch_name }[0]
616
611
  name = branch_name
617
612
  revision = chosen_branch[:commit][:sha]
618
613
  { 'name' => name, 'revision' => revision[0..14], 'default_branch' => select_master }
@@ -627,7 +622,7 @@ class Release
627
622
  { 'name' => name, 'revision' => revision[0..14], 'committer' => committer_email }
628
623
  end
629
624
 
630
- def get_stacks()
625
+ def get_stacks
631
626
  envs = {}
632
627
  stack_list = stack_list()
633
628
  stack_list.each do |stack|
@@ -636,10 +631,10 @@ class Release
636
631
  envs[env_hash] = stack.tags unless envs.has_key?(env_hash) || stack.tags.empty?
637
632
  end
638
633
  end
639
- return stack_list, envs
634
+ [stack_list, envs]
640
635
  end
641
636
 
642
- def get_clusters()
637
+ def get_clusters
643
638
  envs = {}
644
639
  cluster_list = cluster_list()
645
640
  cluster_list.each do |stack|
@@ -648,63 +643,65 @@ class Release
648
643
  envs[env_hash] = stack.tags unless envs.has_key?(env_hash) || stack.tags.empty?
649
644
  end
650
645
  end
651
- return cluster_list, envs
646
+ [cluster_list, envs]
652
647
  end
653
648
 
654
- def hostname_pattern_priority()
655
- (Time.now.to_i.to_s[-4..-1].to_i + Random.rand(40000)).to_s
649
+ def hostname_pattern_priority
650
+ (Time.now.to_i.to_s[-4..-1].to_i + Random.rand(40_000)).to_s
656
651
  end
657
652
 
658
653
  def select_branches(project_names = nil)
659
- output "Deploy feature menu"
654
+ output 'Deploy feature menu'
660
655
  if project_names.nil?
661
- @projects.each{ |key, value| @projects[key] = choose_branch_to_deploy(key) }
656
+ @projects.each { |key, _value| @projects[key] = choose_branch_to_deploy(key) }
662
657
  else
663
658
  project_names.each do |project|
664
659
  @projects[project] = choose_branch_to_deploy(project)
665
660
  end
666
661
  @projects.each_key do |branch_project|
667
- @projects[branch_project] = choose_branch_to_deploy(branch_project, true) unless project_names.include? branch_project
662
+ unless project_names.include? branch_project
663
+ @projects[branch_project] = choose_branch_to_deploy(branch_project, true)
664
+ end
668
665
  end
669
666
  end
670
667
  end
671
668
  end
672
669
 
673
670
  def help_content
674
- <<-HELP
671
+ <<~HELP
675
672
 
676
- twig-feature
677
- ===========
673
+ twig-feature
674
+ ===========
678
675
 
679
- Manage feature branches
676
+ Manage feature branches
680
677
 
681
- Synopsis
682
- --------
678
+ Synopsis
679
+ --------
683
680
 
684
- twig release start
685
- twig release finish
686
- twig release deploy
687
- twig release aggregator
681
+ twig release start
682
+ twig release finish
683
+ twig release deploy
684
+ twig release aggregator
688
685
 
689
- Description
690
- -----------
686
+ Description
687
+ -----------
691
688
 
692
- start creates a new feature branch
693
- finish finishes the feature by merging to dev and master
694
- qainit deploys a new environment with selected branches from every project
695
- qainit $PROJECT_NAME deploys a new environment allowing to selected a branch from the input project (everything else is master)
696
- qainit shutdown deletes a specific qa environment
689
+ start creates a new feature branch
690
+ finish finishes the feature by merging to dev and master
691
+ qainit deploys a new environment with selected branches from every project
692
+ qainit $PROJECT_NAME deploys a new environment allowing to selected a branch from the input project (everything else is master)
693
+ qainit shutdown deletes a specific qa environment
697
694
 
698
- Available only to devops (from artemide)
699
- -----------
700
- deploy deploys the feature branch to a temporary AWS Elastic Beanstalk env
701
- deploy stop destroys the AWS Elastic Beanstalk env
702
- deploy update updates a feature branch with current branches
703
- deploy lock protects a qa environment from automatic deletion
704
- aggregator enable/disable directs comparator's staging environments to a qa/staging
695
+ Available only to devops (from artemide)
696
+ -----------
697
+ deploy deploys the feature branch to a temporary AWS Elastic Beanstalk env
698
+ deploy stop destroys the AWS Elastic Beanstalk env
699
+ deploy update updates a feature branch with current branches
700
+ deploy lock protects a qa environment from automatic deletion
701
+ aggregator enable/disable directs comparator's staging environments to a qa/staging
705
702
 
706
- Subcommand for Twig: <http://rondevera.github.io/twig/>
707
- Author: Andrea Usuelli <https://github.com/andreausu>
703
+ Subcommand for Twig: <http://rondevera.github.io/twig/>
704
+ Author: Andrea Usuelli <https://github.com/andreausu>
708
705
 
709
706
  HELP
710
707
  end
@@ -717,9 +714,7 @@ if args.include?('--help')
717
714
  end
718
715
 
719
716
  gem_update = true
720
- if args.include?('no-gem-update')
721
- gem_update = false
722
- end
717
+ gem_update = false if args.include?('no-gem-update')
723
718
 
724
719
  args.delete('no-gem-update')
725
720