prima-twig 1.3.3 → 1.3.4

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