prima-twig 1.3.3 → 1.3.8

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 +156 -160
  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: 05b8e6ea2b34f2253c198695c6e46ac763b7ac290f3f9070ce6f2bbd27f2bf6b
4
+ data.tar.gz: 67b7416f8b613001af2f4b56ebed3f213d5f7c7cc905e7bd8e1b98fe04c3e311
5
5
  SHA512:
6
- metadata.gz: c8af38f500b2534fb931351ba661f2fc2c3f432b711dc04d507994de4f53e98e5c54481288323cc61e462c6938d0231622e8bd565c6637604eaa0c94146c1c45
7
- data.tar.gz: 4ecba9abf78e0d4e4b3eb47e41a42611b4931125018db311f6afc188b8155b98ef00b1777e7ea55d51504864d461f6c4cabe9a0f60d9c153ace48cc162440a26
6
+ metadata.gz: 889052a90214299137f00075a6e866192bc9b8ba12146fec2dce7eddfc5bf24e3931c7882fac4ab160a0539c943f19601984672fe40828b1f542285523ad4ea6
7
+ data.tar.gz: cfb1b7273e8249961a8616c99c3b6c4411cfbeae1b6035bddb0d36727fb9a50c5097b548b344c4c577e63e429b14227ed23a8efce7738489e4fa8b4fab4498fa
@@ -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
@@ -49,20 +49,23 @@ class Release
49
49
  'domus' => {},
50
50
  'toretto' => {},
51
51
  'lira' => {},
52
- 'frontale' => {}
52
+ 'frontale' => {},
53
+ 'baggio' => {},
54
+ 'mario' => {},
55
+ 'zuhause' => {}
53
56
  }
54
57
  @base_stack_name_alb = 'ecs-alb-http-public-qa-'
55
58
  @base_stack_name_alb_ws = 'ecs-alb-ws-public-qa-'
56
59
  @cloudflare = Rubyflare.connect_with(ENV['CLOUDFLARE_EMAIL'], ENV['CLOUDFLARE_APIKEY'])
57
60
  @config = YAML.load_file 'twig.yml'
58
- @gh = Octokit::Client.new(:access_token => @config['github'])
61
+ @gh = Octokit::Client.new(access_token: @config['github'])
59
62
  end
60
63
 
61
64
  def execute!(args)
62
65
  case args[0]
63
66
  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]
67
+ abort('Non sei nella cartella di qainit') unless Dir.pwd.match('qainit$') || Dir.pwd.match('/drone/src')
68
+ if %w[terminate stop shutdown halt destroy].include? args[1]
66
69
  qainit_deploy_shutdown!
67
70
  elsif 'update' == args[1]
68
71
  qainit_deploy_update!
@@ -77,13 +80,11 @@ class Release
77
80
  when 'suite'
78
81
  abort('Non sei nella cartella di qainit') unless Dir.pwd.match 'qainit$'
79
82
  if 'deploy' == args[1]
80
- suite_py_branches()
83
+ suite_py_branches
81
84
  qainit_deploy!(true)
82
85
  end
83
86
  when 'deploy'
84
- if 'lock' == args[1]
85
- deploy_lock!
86
- end
87
+ deploy_lock! if 'lock' == args[1]
87
88
  when 'aggregator'
88
89
  if 'enable' == args[1]
89
90
  aggregator_enable!
@@ -105,25 +106,25 @@ class Release
105
106
  def aggregator_disable!
106
107
  output 'Disable aggregator'
107
108
 
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()
109
+ output 'Recupero le informazioni relative al puntamento dei record DNS...'
110
+ output 'Recupero le informazioni sui QA attivi...'
111
+ stack_list, envs = get_stacks
111
112
 
112
113
  env_hash = nil
113
- unless envs.empty?
114
- env_hash = envs.detect do |key, tags|
114
+ if envs.empty?
115
+ output 'Nessun QA trovato'.red
116
+ exit
117
+ else
118
+ env_hash = envs.detect do |_key, tags|
115
119
  aggregator_enabled = tags.detect do |tag|
116
- tag.key === "hostname_pattern_priority" and tag.value === "1"
120
+ tag.key === 'hostname_pattern_priority' and tag.value === '1'
117
121
  end.is_a?(Aws::CloudFormation::Types::Tag)
118
122
  aggregator_enabled
119
123
  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())
124
+ 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]) })
125
+ stop_if dns_records.body[:result].empty?, 'I record DNS degli aggregatori non stanno puntando ad un QA'.red
126
+ change_hostname_priority(env_hash, hostname_pattern_priority)
123
127
  dns_to_staging(env_hash)
124
- else
125
- output 'Nessun QA trovato'.red
126
- exit
127
128
  end
128
129
 
129
130
  output 'Finito!'.green
@@ -136,46 +137,46 @@ class Release
136
137
  dns_records = @cloudflare.get('zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records', { per_page: 100, type: 'CNAME', content: 'staging.prima.it' })
137
138
  stop_if dns_records.body[:result].empty?, "I record DNS degli aggregatori stanno gia' puntando ad un QA".red
138
139
 
139
- output "Recupero le informazioni sui QA attivi..."
140
- stack_list, envs = get_stacks()
140
+ output 'Recupero le informazioni sui QA attivi...'
141
+ stack_list, envs = get_stacks
141
142
 
142
143
  env_hash = nil
143
- unless envs.empty?
144
+ if envs.empty?
145
+ output 'Nessun QA trovato'.red
146
+ exit
147
+ else
144
148
  env_hash = choose do |menu|
145
- menu.prompt = "Scegli il QA al quale vuoi far puntare gli ambienti di staging dei comparatori: ".cyan
149
+ menu.prompt = 'Scegli il QA al quale vuoi far puntare gli ambienti di staging dei comparatori: '.cyan
146
150
  menu.shell = true
147
151
  envs.each do |key, env|
148
- title = ""
152
+ title = ''
149
153
  env.each do |e|
150
154
  title << "\n#{e.key.upcase}: #{e.value}"
151
155
  end
152
- msg = "#{@prima.reduce_size(title, 1000)}".light_blue
156
+ msg = @prima.reduce_size(title, 1000).to_s.light_blue
153
157
  menu.choice(msg) { key }
154
158
  end
155
159
  end
156
- else
157
- output "Nessun QA trovato".red
158
- exit
159
160
  end
160
161
 
161
- change_hostname_priority(env_hash, "1")
162
+ change_hostname_priority(env_hash, '1')
162
163
 
163
164
  dns_records.body[:result].each do |dns|
164
- if dns[:name] =~ /^\w+\-\w+\-staging\.prima\.it$/
165
+ if dns[:name] =~ /^\w+-\w+-staging\.prima\.it$/
165
166
  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})
167
+ @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
168
  end
168
169
  end
169
170
 
170
- output "Finito!".green
171
+ output 'Finito!'.green
171
172
  end
172
173
 
173
174
  def change_hostname_priority(env_hash, hostname_pattern_priority)
174
175
  cluster_stack_name = "ecs-cluster-#{env_hash}"
175
176
  tags = get_stack_tags(cluster_stack_name).map do |tag|
176
- if tag.key === "hostname_pattern_priority"
177
+ if tag.key === 'hostname_pattern_priority'
177
178
  {
178
- key: "hostname_pattern_priority",
179
+ key: 'hostname_pattern_priority',
179
180
  value: hostname_pattern_priority
180
181
  }
181
182
  else
@@ -200,14 +201,14 @@ class Release
200
201
 
201
202
  stack_name_web = "ecs-task-web-#{env_hash}"
202
203
  parameters = get_stack_parameters(stack_name_web).map do |param|
203
- if param.parameter_key === "HostnamePatternPriority"
204
+ if param.parameter_key === 'HostnamePatternPriority'
204
205
  {
205
- parameter_key: "HostnamePatternPriority",
206
+ parameter_key: 'HostnamePatternPriority',
206
207
  parameter_value: hostname_pattern_priority
207
208
  }
208
- elsif param.parameter_key === "HostnamePatternAggregatorPriority"
209
+ elsif param.parameter_key === 'HostnamePatternAggregatorPriority'
209
210
  {
210
- parameter_key: "HostnamePatternAggregatorPriority",
211
+ parameter_key: 'HostnamePatternAggregatorPriority',
211
212
  parameter_value: (hostname_pattern_priority.to_i + 1).to_s
212
213
  }
213
214
  else
@@ -221,22 +222,25 @@ class Release
221
222
  end
222
223
 
223
224
  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])})
225
+ output 'Recupero le informazioni relative al puntamento dei record DNS...'
226
+ 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
227
  dns_records.body[:result].each do |dns|
227
- if dns[:name] =~ /^\w+\-\w+\-staging\.prima\.it$/
228
+ if dns[:name] =~ /^\w+-\w+-staging\.prima\.it$/
228
229
  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})
230
+ @cloudflare.put("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records/#{dns[:id]}", { type: 'CNAME', name: dns[:name], content: 'staging.prima.it', proxied: true, ttl: 1 })
230
231
  end
231
232
  end
232
233
  end
233
234
 
234
235
  def deploy_shutdown!
235
- output "Recupero le informazioni sui QA attivi..."
236
+ output 'Recupero le informazioni sui QA attivi...'
236
237
  stack_list, envs = get_stacks
237
238
 
238
239
  env_hash = nil
239
- unless envs.empty?
240
+ if envs.empty?
241
+ output 'Nessun environment trovato'.red
242
+ exit
243
+ else
240
244
  env_hash = choose do |menu|
241
245
  menu.prompt = "Scegli l'environment che vuoi spegnere: ".cyan
242
246
  menu.shell = true
@@ -250,9 +254,6 @@ class Release
250
254
  menu.choice(msg) { key }
251
255
  end
252
256
  end
253
- else
254
- output 'Nessun environment trovato'.red
255
- exit
256
257
  end
257
258
 
258
259
  cluster_stack_name = nil
@@ -263,6 +264,7 @@ class Release
263
264
  cluster_stack_name = stack.stack_name
264
265
  else
265
266
  break unless stack.stack_name.match(/#{env_hash}$/)
267
+
266
268
  stacks_to_delete.push(stack.stack_name)
267
269
  delete_stack(stack.stack_name)
268
270
  end
@@ -271,138 +273,134 @@ class Release
271
273
 
272
274
  cluster_stack_name = "ecs-cluster-#{env_hash}"
273
275
  aggregator_enabled = get_stack_tags(cluster_stack_name).detect do |tag|
274
- tag.key === "hostname_pattern_priority" and tag.value === "1"
276
+ tag.key === 'hostname_pattern_priority' and tag.value === '1'
275
277
  end.is_a?(Aws::CloudFormation::Types::Tag)
276
278
 
277
- if aggregator_enabled
278
- dns_to_staging(env_hash)
279
- end
279
+ dns_to_staging(env_hash) if aggregator_enabled
280
280
 
281
281
  # 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"
282
+ output 'Attendo 10 secondi per poter eliminare il cluster ECS'
283
283
 
284
284
  while stacks_to_delete.length > 0
285
285
  sleep 13
286
286
  stacks_to_delete.each do |stack_name|
287
- stacks_to_delete = stacks_to_delete - [stack_name] unless stack_exists?(stack_name)
287
+ stacks_to_delete -= [stack_name] unless stack_exists?(stack_name)
288
288
  end
289
- output "Stack ancora attivi: #{stacks_to_delete.length.to_s}. Attendo altri 10 secondi per eliminare il cluster ECS"
289
+ output "Stack ancora attivi: #{stacks_to_delete.length}. Attendo altri 10 secondi per eliminare il cluster ECS"
290
290
  end
291
291
 
292
292
  delete_stack(cluster_stack_name)
293
293
  delete_stack(@base_stack_name_alb + env_hash[3..8])
294
294
  delete_stack(@base_stack_name_alb_ws + env_hash[3..8])
295
- output "Finito!".green
295
+ output 'Finito!'.green
296
296
  end
297
297
 
298
298
  def deploy_lock!
299
- output "Deploy update menu"
299
+ output 'Deploy update menu'
300
300
  `git pull`
301
301
 
302
- output "Recupero le informazioni sui QA attivi..."
303
- stack_list, envs = get_clusters()
302
+ output 'Recupero le informazioni sui QA attivi...'
303
+ stack_list, envs = get_clusters
304
304
 
305
305
  env_hash = nil
306
- unless envs.empty?
306
+ if envs.empty?
307
+ output 'Nessun QA trovato'.red
308
+ exit
309
+ else
307
310
  env_hash = choose do |menu|
308
- menu.prompt = "Scegli il QA che vuoi proteggere dallo spegnimento automatico: ".cyan
311
+ menu.prompt = 'Scegli il QA che vuoi proteggere dallo spegnimento automatico: '.cyan
309
312
  menu.shell = true
310
313
  envs.each do |key, env|
311
- title = ""
314
+ title = ''
312
315
  env.each do |e|
313
- title << "#{e.value}" if e.key == 'qainit'
316
+ title << e.value.to_s if e.key == 'qainit'
314
317
  end
315
- msg = "#{@prima.reduce_size(title, 1000)}".light_blue
318
+ msg = @prima.reduce_size(title, 1000).to_s.light_blue
316
319
  menu.choice(msg) { key }
317
320
  end
318
321
  end
319
- else
320
- output "Nessun QA trovato".red
321
- exit
322
322
  end
323
323
 
324
324
  cluster_stack_name = "ecs-cluster-#{env_hash}"
325
325
  if stack_exists?(cluster_stack_name)
326
326
  tags = get_stack_tags(cluster_stack_name)
327
- tag_keep_data = Aws::CloudFormation::Types::Tag.new({key:'AUTOMATIC_DELETION_PROTECTION', value:'true'})
327
+ tag_keep_data = Aws::CloudFormation::Types::Tag.new({ key: 'AUTOMATIC_DELETION_PROTECTION', value: 'true' })
328
328
  tags.push tag_keep_data
329
329
  end
330
330
 
331
331
  update_cluster_stack(cluster_stack_name, tags, get_stack_parameters(cluster_stack_name))
332
332
 
333
- output "Finito!".green
333
+ output 'Finito!'.green
334
334
  end
335
335
 
336
336
  def deploy_update!
337
- output "Deploy update menu"
337
+ output 'Deploy update menu'
338
338
  `git pull`
339
339
 
340
- output "Recupero le informazioni sui QA attivi..."
341
- stack_list, envs = get_stacks()
340
+ output 'Recupero le informazioni sui QA attivi...'
341
+ stack_list, envs = get_stacks
342
342
 
343
343
  env_hash = nil
344
- unless envs.empty?
344
+ if envs.empty?
345
+ output 'Nessun QA trovato'.red
346
+ exit
347
+ else
345
348
  env_hash = choose do |menu|
346
- menu.prompt = "Scegli il QA che vuoi aggiornare: ".cyan
349
+ menu.prompt = 'Scegli il QA che vuoi aggiornare: '.cyan
347
350
  menu.shell = true
348
351
  envs.each do |key, env|
349
- title = ""
352
+ title = ''
350
353
  env.each do |e|
351
354
  title << "\n#{e.key.upcase}: #{e.value}"
352
355
  end
353
- msg = "#{@prima.reduce_size(title, 1000)}".light_blue
356
+ msg = @prima.reduce_size(title, 1000).to_s.light_blue
354
357
  menu.choice(msg) { key }
355
358
  end
356
359
  end
357
- else
358
- output "Nessun QA trovato".red
359
- exit
360
360
  end
361
361
 
362
362
  envs[env_hash].each do |env|
363
- unless ['hostname_pattern_priority', 'AUTOMATIC_DELETION_PROTECTION'].include? env.key
363
+ unless %w[hostname_pattern_priority AUTOMATIC_DELETION_PROTECTION].include? env.key
364
364
  @projects[env.key] = select_branch_to_deploy(env.key, env.value)
365
365
  end
366
366
  end
367
367
  deploy_feature!
368
368
 
369
- output "Finito!".green
369
+ output 'Finito!'.green
370
370
  end
371
371
 
372
372
  def get_default_branch_name(projects)
373
373
  projects.each_key do |project|
374
- return projects[project]['name'] if not projects[project]['default_branch']
374
+ return projects[project]['name'] unless projects[project]['default_branch']
375
375
  end
376
376
  end
377
377
 
378
- def suite_py_branches()
379
- if File.exist?("suitepy-projects.yml")
380
- arg_projects = YAML.load(File.read("suitepy-projects.yml"))
378
+ def suite_py_branches
379
+ if File.exist?('suitepy-projects.yml')
380
+ arg_projects = YAML.load(File.read('suitepy-projects.yml'))
381
381
 
382
382
  @projects.merge!(arg_projects)
383
383
 
384
384
  `rm suitepy-projects.yml`
385
385
 
386
386
  @projects.each_key do |project|
387
- if @projects[project].empty?
388
- @projects[project] = choose_branch_to_deploy(project, true)
389
- end
387
+ @projects[project] = choose_branch_to_deploy(project, true) if @projects[project].empty?
390
388
  end
391
389
  end
392
390
  end
393
391
 
394
- def get_git_user()
392
+ def get_git_user
395
393
  `git config user.name`.gsub(/[^A-Za-z]/, '').gsub("\n", '')
396
394
  end
397
395
 
398
- def get_git_mail()
396
+ def get_git_mail
399
397
  `git config user.email`.gsub("\n", '')
400
398
  end
401
399
 
402
400
  def qainit_deploy!(quiet = false)
403
- `git checkout master && git pull && git remote prune origin`
401
+ `git checkout master && git fetch && git pull && git remote prune origin`
404
402
 
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`
403
+ `git fetch -p && for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}'); do git branch -D $branch; done`
406
404
 
407
405
  default_name = get_default_branch_name @projects
408
406
  feature_number = ''
@@ -419,7 +417,7 @@ class Release
419
417
  `git checkout -b #{branch_name}`
420
418
  end
421
419
 
422
- File.open("projects.yml", "w") { |file| file.write(@projects.to_yaml) }
420
+ File.open('projects.yml', 'w') { |file| file.write(@projects.to_yaml) }
423
421
 
424
422
  update_drone_yml!
425
423
 
@@ -438,7 +436,7 @@ class Release
438
436
  git_user = get_git_user
439
437
  # stampiamo la lista
440
438
  chosen_branch = choose do |menu|
441
- menu.prompt = "Scegli il QA che vuoi aggiornare: ".cyan
439
+ menu.prompt = 'Scegli il QA che vuoi aggiornare: '.cyan
442
440
  menu.shell = true
443
441
  former_branches.delete('master')
444
442
  former_branches.each_with_index do |branch, index|
@@ -453,14 +451,14 @@ class Release
453
451
  # aggiornare il commit (revision a cui fa riferimento)
454
452
 
455
453
  # leggo il file projects.yml / recupero i nomi dei branch / riscrivo tutto
456
- projects = YAML.load(File.read("projects.yml"))
454
+ projects = YAML.load(File.read('projects.yml'))
457
455
 
458
456
  projects.each do |key, project|
459
457
  @projects[key] = select_branch_to_deploy(key, project['name'])
460
458
  @projects[key]['default_branch'] = project['default_branch']
461
459
  end
462
460
 
463
- File.open("projects.yml", "w") { |file| file.write(@projects.to_yaml) }
461
+ File.open('projects.yml', 'w') { |file| file.write(@projects.to_yaml) }
464
462
 
465
463
  update_drone_yml!
466
464
 
@@ -476,7 +474,7 @@ class Release
476
474
  if selection.nil?
477
475
  # stampiamo la lista
478
476
  chosen_branch = choose do |menu|
479
- menu.prompt = "Scegli il QA che vuoi spegnere: ".cyan
477
+ menu.prompt = 'Scegli il QA che vuoi spegnere: '.cyan
480
478
  menu.shell = true
481
479
  git_user = get_git_user
482
480
  former_branches.delete('master')
@@ -495,10 +493,10 @@ class Release
495
493
  end
496
494
 
497
495
  def qainit_drone_shutdown!
498
- output "Recupero le informazioni sui QA attivi..."
496
+ output 'Recupero le informazioni sui QA attivi...'
499
497
  stack_list, envs = get_stacks
500
498
 
501
- env_hash = "qa-" + get_deploy_id
499
+ env_hash = 'qa-' + get_deploy_id
502
500
 
503
501
  cluster_stack_name = nil
504
502
  stacks_to_delete = []
@@ -508,6 +506,7 @@ class Release
508
506
  cluster_stack_name = stack.stack_name
509
507
  else
510
508
  break unless stack.stack_name.match(/#{env_hash}$/)
509
+
511
510
  stacks_to_delete.push(stack.stack_name)
512
511
  delete_stack(stack.stack_name)
513
512
  end
@@ -517,47 +516,45 @@ class Release
517
516
  cluster_stack_name = "ecs-cluster-#{env_hash}"
518
517
  if stack_exists?(cluster_stack_name)
519
518
  aggregator_enabled = get_stack_tags(cluster_stack_name).detect do |tag|
520
- tag.key === "hostname_pattern_priority" and tag.value === "1"
519
+ tag.key === 'hostname_pattern_priority' and tag.value === '1'
521
520
  end.is_a?(Aws::CloudFormation::Types::Tag)
522
521
 
523
- if aggregator_enabled
524
- dns_to_staging(env_hash)
525
- end
522
+ dns_to_staging(env_hash) if aggregator_enabled
526
523
  end
527
524
 
528
525
  # 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"
526
+ output 'Attendo 10 secondi per poter eliminare il cluster ECS'
530
527
 
531
528
  while stacks_to_delete.length > 0
532
529
  sleep 13
533
530
  stacks_to_delete.each do |stack_name|
534
- stacks_to_delete = stacks_to_delete - [stack_name] unless stack_exists?(stack_name)
531
+ stacks_to_delete -= [stack_name] unless stack_exists?(stack_name)
535
532
  end
536
- output "Stack ancora attivi: #{stacks_to_delete.length.to_s}. Attendo altri 10 secondi per eliminare il cluster ECS"
533
+ output "Stack ancora attivi: #{stacks_to_delete.length}. Attendo altri 10 secondi per eliminare il cluster ECS"
537
534
  end
538
535
 
539
536
  delete_stack(cluster_stack_name) if stack_exists?(cluster_stack_name)
540
537
  delete_stack(@base_stack_name_alb + env_hash[3..8]) if stack_exists?(@base_stack_name_alb + env_hash[3..8])
541
538
  delete_stack(@base_stack_name_alb_ws + env_hash[3..8]) if stack_exists?(@base_stack_name_alb_ws + env_hash[3..8])
542
539
  `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
540
+ output 'Cancello il record DNS utilizzato da Lighthouse'
541
+ delete_lighthouse_dns
542
+ output 'Finito!'.green
546
543
  end
547
544
 
548
545
  def qainit_write_output(file_message, output_message)
549
546
  `mkdir -p /etc/qainit-output`
550
- qa_file_name = "/etc/qainit-output/url_qa"
547
+ qa_file_name = '/etc/qainit-output/url_qa'
551
548
  File.open(qa_file_name + '.txt', 'w') { |file| file.write(file_message) }
552
549
  output "#{output_message} #{qa_file_name}".green
553
550
  end
554
551
 
555
- def update_drone_yml!()
552
+ def update_drone_yml!
556
553
  drone_yml = File.read('.drone.yml')
557
554
  @projects.each do |key, project|
558
555
  drone_yml = drone_yml.gsub(/#{key}@.+\n/, "#{key}@#{project['revision']}\n")
559
556
  end
560
- File.open(".drone.yml", "w") do |f|
557
+ File.open('.drone.yml', 'w') do |f|
561
558
  f.write(drone_yml)
562
559
  end
563
560
  end
@@ -572,10 +569,9 @@ class Release
572
569
  end
573
570
 
574
571
  def get_alb_host(stack_name)
575
- case
576
- when stack_name.include?('alb-http-public')
572
+ if stack_name.include?('alb-http-public')
577
573
  logical_resource_id = 'EcsApplicationLoadBalancerPublic'
578
- when stack_name.include?('alb-ws-public')
574
+ elsif stack_name.include?('alb-ws-public')
579
575
  logical_resource_id = 'EcsApplicationLoadBalancerPublic'
580
576
  end
581
577
  resp = describe_stack_resource(stack_name, logical_resource_id)
@@ -591,8 +587,8 @@ class Release
591
587
  def choose_branch_to_deploy(project_name, select_master = false)
592
588
  # chiamare api octokit per recuperare i branch/commit
593
589
  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]
590
+ branches = @gh.branches("primait/#{project_name}", { per_page: 100 })
591
+ master_branch = branches.select { |branch| branch[:name] == 'master' }[0]
596
592
 
597
593
  if select_master || branches.length == 1
598
594
  branch_name = 'master'
@@ -614,7 +610,7 @@ class Release
614
610
  end
615
611
  end
616
612
 
617
- chosen_branch = branches.select {|branch| branch[:name] == branch_name}[0]
613
+ chosen_branch = branches.select { |branch| branch[:name] == branch_name }[0]
618
614
  name = branch_name
619
615
  revision = chosen_branch[:commit][:sha]
620
616
  { 'name' => name, 'revision' => revision[0..14], 'default_branch' => select_master }
@@ -629,7 +625,7 @@ class Release
629
625
  { 'name' => name, 'revision' => revision[0..14], 'committer' => committer_email }
630
626
  end
631
627
 
632
- def get_stacks()
628
+ def get_stacks
633
629
  envs = {}
634
630
  stack_list = stack_list()
635
631
  stack_list.each do |stack|
@@ -638,10 +634,10 @@ class Release
638
634
  envs[env_hash] = stack.tags unless envs.has_key?(env_hash) || stack.tags.empty?
639
635
  end
640
636
  end
641
- return stack_list, envs
637
+ [stack_list, envs]
642
638
  end
643
639
 
644
- def get_clusters()
640
+ def get_clusters
645
641
  envs = {}
646
642
  cluster_list = cluster_list()
647
643
  cluster_list.each do |stack|
@@ -650,63 +646,65 @@ class Release
650
646
  envs[env_hash] = stack.tags unless envs.has_key?(env_hash) || stack.tags.empty?
651
647
  end
652
648
  end
653
- return cluster_list, envs
649
+ [cluster_list, envs]
654
650
  end
655
651
 
656
- def hostname_pattern_priority()
657
- (Time.now.to_i.to_s[-4..-1].to_i + Random.rand(40000)).to_s
652
+ def hostname_pattern_priority
653
+ (Time.now.to_i.to_s[-4..-1].to_i + Random.rand(40_000)).to_s
658
654
  end
659
655
 
660
656
  def select_branches(project_names = nil)
661
- output "Deploy feature menu"
657
+ output 'Deploy feature menu'
662
658
  if project_names.nil?
663
- @projects.each{ |key, value| @projects[key] = choose_branch_to_deploy(key) }
659
+ @projects.each { |key, _value| @projects[key] = choose_branch_to_deploy(key) }
664
660
  else
665
661
  project_names.each do |project|
666
662
  @projects[project] = choose_branch_to_deploy(project)
667
663
  end
668
664
  @projects.each_key do |branch_project|
669
- @projects[branch_project] = choose_branch_to_deploy(branch_project, true) unless project_names.include? branch_project
665
+ unless project_names.include? branch_project
666
+ @projects[branch_project] = choose_branch_to_deploy(branch_project, true)
667
+ end
670
668
  end
671
669
  end
672
670
  end
673
671
  end
674
672
 
675
673
  def help_content
676
- <<-HELP
674
+ <<~HELP
677
675
 
678
- twig-feature
679
- ===========
676
+ twig-feature
677
+ ===========
680
678
 
681
- Manage feature branches
679
+ Manage feature branches
682
680
 
683
- Synopsis
684
- --------
681
+ Synopsis
682
+ --------
685
683
 
686
- twig release start
687
- twig release finish
688
- twig release deploy
689
- twig release aggregator
684
+ twig release start
685
+ twig release finish
686
+ twig release deploy
687
+ twig release aggregator
690
688
 
691
- Description
692
- -----------
689
+ Description
690
+ -----------
693
691
 
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
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
699
697
 
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
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
707
705
 
708
- Subcommand for Twig: <http://rondevera.github.io/twig/>
709
- Author: Andrea Usuelli <https://github.com/andreausu>
706
+ Subcommand for Twig: <http://rondevera.github.io/twig/>
707
+ Author: Andrea Usuelli <https://github.com/andreausu>
710
708
 
711
709
  HELP
712
710
  end
@@ -719,9 +717,7 @@ if args.include?('--help')
719
717
  end
720
718
 
721
719
  gem_update = true
722
- if args.include?('no-gem-update')
723
- gem_update = false
724
- end
720
+ gem_update = false if args.include?('no-gem-update')
725
721
 
726
722
  args.delete('no-gem-update')
727
723
 
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.8
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: 2021-01-27 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