prima-twig 1.3.0 → 1.3.5

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: 94183c3b380822569fa755c6cd914da1eb15d36378d93a8faf827cf8b2a8a119
4
- data.tar.gz: 865c21d79254b4b4ad2e8034d665f74301585fd50f4fd20b019e0c6bde977183
3
+ metadata.gz: 975828594ae14f606a510643c544f4cd363ef6d86be3df0e2e3a1681e4422389
4
+ data.tar.gz: 6e30a88cd7ecf87e520b0c96c946a58cd6a5abd022840eae4fee841a9a5fd8d7
5
5
  SHA512:
6
- metadata.gz: 7604f33c35162fde446fb5e91e92451745d7eab126d09f417c36c835254949f2690c77c3f4ebbd8248c885c6c19b7786498da0cfbfe44adcb798b5641e53613f
7
- data.tar.gz: 24f093ea1a89deef5debd86afdf69b5dbb43f5f1a6aef9bc68f8a8a0b9e2e938baee20ba897116d8a2d66e5e8d7b8d60a9e1f6af267973003e7357c34d138884
6
+ metadata.gz: 7c2c214e6a37ee5103ff495cfb63717bde238d740810426dd2639d25d57b7d6825659749c423b8e55518f20866b05f4c940f465124d38b3a43cc50725bca322a
7
+ data.tar.gz: 1e7127439d07ff017821ca372dcde66465aa7eb43a25391ee6ccd7bd033e41f6639402edadfcecb434dfbc728a30b9a633b3e8bc1fddb41f59fbd0b8a03d1b4e
@@ -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,23 @@ class Release
47
47
  'legion' => {},
48
48
  'vianello' => {},
49
49
  'domus' => {},
50
- 'toretto' => {}
50
+ 'toretto' => {},
51
+ 'lira' => {},
52
+ 'frontale' => {},
53
+ 'baggio' => {}
51
54
  }
52
55
  @base_stack_name_alb = 'ecs-alb-http-public-qa-'
53
56
  @base_stack_name_alb_ws = 'ecs-alb-ws-public-qa-'
54
57
  @cloudflare = Rubyflare.connect_with(ENV['CLOUDFLARE_EMAIL'], ENV['CLOUDFLARE_APIKEY'])
55
58
  @config = YAML.load_file 'twig.yml'
56
- @gh = Octokit::Client.new(:access_token => @config['github'])
59
+ @gh = Octokit::Client.new(access_token: @config['github'])
57
60
  end
58
61
 
59
62
  def execute!(args)
60
63
  case args[0]
61
64
  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]
65
+ abort('Non sei nella cartella di qainit') unless Dir.pwd.match('qainit$') || Dir.pwd.match('/drone/src')
66
+ if %w[terminate stop shutdown halt destroy].include? args[1]
64
67
  qainit_deploy_shutdown!
65
68
  elsif 'update' == args[1]
66
69
  qainit_deploy_update!
@@ -75,13 +78,11 @@ class Release
75
78
  when 'suite'
76
79
  abort('Non sei nella cartella di qainit') unless Dir.pwd.match 'qainit$'
77
80
  if 'deploy' == args[1]
78
- suite_py_branches()
81
+ suite_py_branches
79
82
  qainit_deploy!(true)
80
83
  end
81
84
  when 'deploy'
82
- if 'lock' == args[1]
83
- deploy_lock!
84
- end
85
+ deploy_lock! if 'lock' == args[1]
85
86
  when 'aggregator'
86
87
  if 'enable' == args[1]
87
88
  aggregator_enable!
@@ -103,25 +104,25 @@ class Release
103
104
  def aggregator_disable!
104
105
  output 'Disable aggregator'
105
106
 
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()
107
+ output 'Recupero le informazioni relative al puntamento dei record DNS...'
108
+ output 'Recupero le informazioni sui QA attivi...'
109
+ stack_list, envs = get_stacks
109
110
 
110
111
  env_hash = nil
111
- unless envs.empty?
112
- env_hash = envs.detect do |key, tags|
112
+ if envs.empty?
113
+ output 'Nessun QA trovato'.red
114
+ exit
115
+ else
116
+ env_hash = envs.detect do |_key, tags|
113
117
  aggregator_enabled = tags.detect do |tag|
114
- tag.key === "hostname_pattern_priority" and tag.value === "1"
118
+ tag.key === 'hostname_pattern_priority' and tag.value === '1'
115
119
  end.is_a?(Aws::CloudFormation::Types::Tag)
116
120
  aggregator_enabled
117
121
  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())
122
+ 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]) })
123
+ stop_if dns_records.body[:result].empty?, 'I record DNS degli aggregatori non stanno puntando ad un QA'.red
124
+ change_hostname_priority(env_hash, hostname_pattern_priority)
121
125
  dns_to_staging(env_hash)
122
- else
123
- output 'Nessun QA trovato'.red
124
- exit
125
126
  end
126
127
 
127
128
  output 'Finito!'.green
@@ -134,46 +135,46 @@ class Release
134
135
  dns_records = @cloudflare.get('zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records', { per_page: 100, type: 'CNAME', content: 'staging.prima.it' })
135
136
  stop_if dns_records.body[:result].empty?, "I record DNS degli aggregatori stanno gia' puntando ad un QA".red
136
137
 
137
- output "Recupero le informazioni sui QA attivi..."
138
- stack_list, envs = get_stacks()
138
+ output 'Recupero le informazioni sui QA attivi...'
139
+ stack_list, envs = get_stacks
139
140
 
140
141
  env_hash = nil
141
- unless envs.empty?
142
+ if envs.empty?
143
+ output 'Nessun QA trovato'.red
144
+ exit
145
+ else
142
146
  env_hash = choose do |menu|
143
- menu.prompt = "Scegli il QA al quale vuoi far puntare gli ambienti di staging dei comparatori: ".cyan
147
+ menu.prompt = 'Scegli il QA al quale vuoi far puntare gli ambienti di staging dei comparatori: '.cyan
144
148
  menu.shell = true
145
149
  envs.each do |key, env|
146
- title = ""
150
+ title = ''
147
151
  env.each do |e|
148
152
  title << "\n#{e.key.upcase}: #{e.value}"
149
153
  end
150
- msg = "#{@prima.reduce_size(title, 1000)}".light_blue
154
+ msg = @prima.reduce_size(title, 1000).to_s.light_blue
151
155
  menu.choice(msg) { key }
152
156
  end
153
157
  end
154
- else
155
- output "Nessun QA trovato".red
156
- exit
157
158
  end
158
159
 
159
- change_hostname_priority(env_hash, "1")
160
+ change_hostname_priority(env_hash, '1')
160
161
 
161
162
  dns_records.body[:result].each do |dns|
162
- if dns[:name] =~ /^\w+\-\w+\-staging\.prima\.it$/
163
+ if dns[:name] =~ /^\w+-\w+-staging\.prima\.it$/
163
164
  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})
165
+ @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
166
  end
166
167
  end
167
168
 
168
- output "Finito!".green
169
+ output 'Finito!'.green
169
170
  end
170
171
 
171
172
  def change_hostname_priority(env_hash, hostname_pattern_priority)
172
173
  cluster_stack_name = "ecs-cluster-#{env_hash}"
173
174
  tags = get_stack_tags(cluster_stack_name).map do |tag|
174
- if tag.key === "hostname_pattern_priority"
175
+ if tag.key === 'hostname_pattern_priority'
175
176
  {
176
- key: "hostname_pattern_priority",
177
+ key: 'hostname_pattern_priority',
177
178
  value: hostname_pattern_priority
178
179
  }
179
180
  else
@@ -198,14 +199,14 @@ class Release
198
199
 
199
200
  stack_name_web = "ecs-task-web-#{env_hash}"
200
201
  parameters = get_stack_parameters(stack_name_web).map do |param|
201
- if param.parameter_key === "HostnamePatternPriority"
202
+ if param.parameter_key === 'HostnamePatternPriority'
202
203
  {
203
- parameter_key: "HostnamePatternPriority",
204
+ parameter_key: 'HostnamePatternPriority',
204
205
  parameter_value: hostname_pattern_priority
205
206
  }
206
- elsif param.parameter_key === "HostnamePatternAggregatorPriority"
207
+ elsif param.parameter_key === 'HostnamePatternAggregatorPriority'
207
208
  {
208
- parameter_key: "HostnamePatternAggregatorPriority",
209
+ parameter_key: 'HostnamePatternAggregatorPriority',
209
210
  parameter_value: (hostname_pattern_priority.to_i + 1).to_s
210
211
  }
211
212
  else
@@ -219,22 +220,25 @@ class Release
219
220
  end
220
221
 
221
222
  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])})
223
+ output 'Recupero le informazioni relative al puntamento dei record DNS...'
224
+ 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
225
  dns_records.body[:result].each do |dns|
225
- if dns[:name] =~ /^\w+\-\w+\-staging\.prima\.it$/
226
+ if dns[:name] =~ /^\w+-\w+-staging\.prima\.it$/
226
227
  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})
228
+ @cloudflare.put("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records/#{dns[:id]}", { type: 'CNAME', name: dns[:name], content: 'staging.prima.it', proxied: true, ttl: 1 })
228
229
  end
229
230
  end
230
231
  end
231
232
 
232
233
  def deploy_shutdown!
233
- output "Recupero le informazioni sui QA attivi..."
234
+ output 'Recupero le informazioni sui QA attivi...'
234
235
  stack_list, envs = get_stacks
235
236
 
236
237
  env_hash = nil
237
- unless envs.empty?
238
+ if envs.empty?
239
+ output 'Nessun environment trovato'.red
240
+ exit
241
+ else
238
242
  env_hash = choose do |menu|
239
243
  menu.prompt = "Scegli l'environment che vuoi spegnere: ".cyan
240
244
  menu.shell = true
@@ -248,9 +252,6 @@ class Release
248
252
  menu.choice(msg) { key }
249
253
  end
250
254
  end
251
- else
252
- output 'Nessun environment trovato'.red
253
- exit
254
255
  end
255
256
 
256
257
  cluster_stack_name = nil
@@ -261,6 +262,7 @@ class Release
261
262
  cluster_stack_name = stack.stack_name
262
263
  else
263
264
  break unless stack.stack_name.match(/#{env_hash}$/)
265
+
264
266
  stacks_to_delete.push(stack.stack_name)
265
267
  delete_stack(stack.stack_name)
266
268
  end
@@ -269,138 +271,134 @@ class Release
269
271
 
270
272
  cluster_stack_name = "ecs-cluster-#{env_hash}"
271
273
  aggregator_enabled = get_stack_tags(cluster_stack_name).detect do |tag|
272
- tag.key === "hostname_pattern_priority" and tag.value === "1"
274
+ tag.key === 'hostname_pattern_priority' and tag.value === '1'
273
275
  end.is_a?(Aws::CloudFormation::Types::Tag)
274
276
 
275
- if aggregator_enabled
276
- dns_to_staging(env_hash)
277
- end
277
+ dns_to_staging(env_hash) if aggregator_enabled
278
278
 
279
279
  # 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"
280
+ output 'Attendo 10 secondi per poter eliminare il cluster ECS'
281
281
 
282
282
  while stacks_to_delete.length > 0
283
283
  sleep 13
284
284
  stacks_to_delete.each do |stack_name|
285
- stacks_to_delete = stacks_to_delete - [stack_name] unless stack_exists?(stack_name)
285
+ stacks_to_delete -= [stack_name] unless stack_exists?(stack_name)
286
286
  end
287
- output "Stack ancora attivi: #{stacks_to_delete.length.to_s}. Attendo altri 10 secondi per eliminare il cluster ECS"
287
+ output "Stack ancora attivi: #{stacks_to_delete.length}. Attendo altri 10 secondi per eliminare il cluster ECS"
288
288
  end
289
289
 
290
290
  delete_stack(cluster_stack_name)
291
291
  delete_stack(@base_stack_name_alb + env_hash[3..8])
292
292
  delete_stack(@base_stack_name_alb_ws + env_hash[3..8])
293
- output "Finito!".green
293
+ output 'Finito!'.green
294
294
  end
295
295
 
296
296
  def deploy_lock!
297
- output "Deploy update menu"
297
+ output 'Deploy update menu'
298
298
  `git pull`
299
299
 
300
- output "Recupero le informazioni sui QA attivi..."
301
- stack_list, envs = get_clusters()
300
+ output 'Recupero le informazioni sui QA attivi...'
301
+ stack_list, envs = get_clusters
302
302
 
303
303
  env_hash = nil
304
- unless envs.empty?
304
+ if envs.empty?
305
+ output 'Nessun QA trovato'.red
306
+ exit
307
+ else
305
308
  env_hash = choose do |menu|
306
- menu.prompt = "Scegli il QA che vuoi proteggere dallo spegnimento automatico: ".cyan
309
+ menu.prompt = 'Scegli il QA che vuoi proteggere dallo spegnimento automatico: '.cyan
307
310
  menu.shell = true
308
311
  envs.each do |key, env|
309
- title = ""
312
+ title = ''
310
313
  env.each do |e|
311
- title << "#{e.value}" if e.key == 'qainit'
314
+ title << e.value.to_s if e.key == 'qainit'
312
315
  end
313
- msg = "#{@prima.reduce_size(title, 1000)}".light_blue
316
+ msg = @prima.reduce_size(title, 1000).to_s.light_blue
314
317
  menu.choice(msg) { key }
315
318
  end
316
319
  end
317
- else
318
- output "Nessun QA trovato".red
319
- exit
320
320
  end
321
321
 
322
322
  cluster_stack_name = "ecs-cluster-#{env_hash}"
323
323
  if stack_exists?(cluster_stack_name)
324
324
  tags = get_stack_tags(cluster_stack_name)
325
- tag_keep_data = Aws::CloudFormation::Types::Tag.new({key:'AUTOMATIC_DELETION_PROTECTION', value:'true'})
325
+ tag_keep_data = Aws::CloudFormation::Types::Tag.new({ key: 'AUTOMATIC_DELETION_PROTECTION', value: 'true' })
326
326
  tags.push tag_keep_data
327
327
  end
328
328
 
329
329
  update_cluster_stack(cluster_stack_name, tags, get_stack_parameters(cluster_stack_name))
330
330
 
331
- output "Finito!".green
331
+ output 'Finito!'.green
332
332
  end
333
333
 
334
334
  def deploy_update!
335
- output "Deploy update menu"
335
+ output 'Deploy update menu'
336
336
  `git pull`
337
337
 
338
- output "Recupero le informazioni sui QA attivi..."
339
- stack_list, envs = get_stacks()
338
+ output 'Recupero le informazioni sui QA attivi...'
339
+ stack_list, envs = get_stacks
340
340
 
341
341
  env_hash = nil
342
- unless envs.empty?
342
+ if envs.empty?
343
+ output 'Nessun QA trovato'.red
344
+ exit
345
+ else
343
346
  env_hash = choose do |menu|
344
- menu.prompt = "Scegli il QA che vuoi aggiornare: ".cyan
347
+ menu.prompt = 'Scegli il QA che vuoi aggiornare: '.cyan
345
348
  menu.shell = true
346
349
  envs.each do |key, env|
347
- title = ""
350
+ title = ''
348
351
  env.each do |e|
349
352
  title << "\n#{e.key.upcase}: #{e.value}"
350
353
  end
351
- msg = "#{@prima.reduce_size(title, 1000)}".light_blue
354
+ msg = @prima.reduce_size(title, 1000).to_s.light_blue
352
355
  menu.choice(msg) { key }
353
356
  end
354
357
  end
355
- else
356
- output "Nessun QA trovato".red
357
- exit
358
358
  end
359
359
 
360
360
  envs[env_hash].each do |env|
361
- unless ['hostname_pattern_priority', 'AUTOMATIC_DELETION_PROTECTION'].include? env.key
361
+ unless %w[hostname_pattern_priority AUTOMATIC_DELETION_PROTECTION].include? env.key
362
362
  @projects[env.key] = select_branch_to_deploy(env.key, env.value)
363
363
  end
364
364
  end
365
365
  deploy_feature!
366
366
 
367
- output "Finito!".green
367
+ output 'Finito!'.green
368
368
  end
369
369
 
370
370
  def get_default_branch_name(projects)
371
371
  projects.each_key do |project|
372
- return projects[project]['name'] if not projects[project]['default_branch']
372
+ return projects[project]['name'] unless projects[project]['default_branch']
373
373
  end
374
374
  end
375
375
 
376
- def suite_py_branches()
377
- if File.exist?("suitepy-projects.yml")
378
- arg_projects = YAML.load(File.read("suitepy-projects.yml"))
376
+ def suite_py_branches
377
+ if File.exist?('suitepy-projects.yml')
378
+ arg_projects = YAML.load(File.read('suitepy-projects.yml'))
379
379
 
380
380
  @projects.merge!(arg_projects)
381
381
 
382
382
  `rm suitepy-projects.yml`
383
383
 
384
384
  @projects.each_key do |project|
385
- if @projects[project].empty?
386
- @projects[project] = choose_branch_to_deploy(project, true)
387
- end
385
+ @projects[project] = choose_branch_to_deploy(project, true) if @projects[project].empty?
388
386
  end
389
387
  end
390
388
  end
391
389
 
392
- def get_git_user()
390
+ def get_git_user
393
391
  `git config user.name`.gsub(/[^A-Za-z]/, '').gsub("\n", '')
394
392
  end
395
393
 
396
- def get_git_mail()
394
+ def get_git_mail
397
395
  `git config user.email`.gsub("\n", '')
398
396
  end
399
397
 
400
398
  def qainit_deploy!(quiet = false)
401
- `git checkout master && git pull && git remote prune origin`
399
+ `git checkout master && git fetch && git pull && git remote prune origin`
402
400
 
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`
401
+ `git fetch -p && for branch in $(git branch -vv | grep ': gone]' | awk '{print $1}'); do git branch -D $branch; done`
404
402
 
405
403
  default_name = get_default_branch_name @projects
406
404
  feature_number = ''
@@ -417,7 +415,7 @@ class Release
417
415
  `git checkout -b #{branch_name}`
418
416
  end
419
417
 
420
- File.open("projects.yml", "w") { |file| file.write(@projects.to_yaml) }
418
+ File.open('projects.yml', 'w') { |file| file.write(@projects.to_yaml) }
421
419
 
422
420
  update_drone_yml!
423
421
 
@@ -436,7 +434,7 @@ class Release
436
434
  git_user = get_git_user
437
435
  # stampiamo la lista
438
436
  chosen_branch = choose do |menu|
439
- menu.prompt = "Scegli il QA che vuoi aggiornare: ".cyan
437
+ menu.prompt = 'Scegli il QA che vuoi aggiornare: '.cyan
440
438
  menu.shell = true
441
439
  former_branches.delete('master')
442
440
  former_branches.each_with_index do |branch, index|
@@ -451,14 +449,14 @@ class Release
451
449
  # aggiornare il commit (revision a cui fa riferimento)
452
450
 
453
451
  # leggo il file projects.yml / recupero i nomi dei branch / riscrivo tutto
454
- projects = YAML.load(File.read("projects.yml"))
452
+ projects = YAML.load(File.read('projects.yml'))
455
453
 
456
454
  projects.each do |key, project|
457
455
  @projects[key] = select_branch_to_deploy(key, project['name'])
458
456
  @projects[key]['default_branch'] = project['default_branch']
459
457
  end
460
458
 
461
- File.open("projects.yml", "w") { |file| file.write(@projects.to_yaml) }
459
+ File.open('projects.yml', 'w') { |file| file.write(@projects.to_yaml) }
462
460
 
463
461
  update_drone_yml!
464
462
 
@@ -474,7 +472,7 @@ class Release
474
472
  if selection.nil?
475
473
  # stampiamo la lista
476
474
  chosen_branch = choose do |menu|
477
- menu.prompt = "Scegli il QA che vuoi spegnere: ".cyan
475
+ menu.prompt = 'Scegli il QA che vuoi spegnere: '.cyan
478
476
  menu.shell = true
479
477
  git_user = get_git_user
480
478
  former_branches.delete('master')
@@ -493,10 +491,10 @@ class Release
493
491
  end
494
492
 
495
493
  def qainit_drone_shutdown!
496
- output "Recupero le informazioni sui QA attivi..."
494
+ output 'Recupero le informazioni sui QA attivi...'
497
495
  stack_list, envs = get_stacks
498
496
 
499
- env_hash = "qa-" + get_deploy_id
497
+ env_hash = 'qa-' + get_deploy_id
500
498
 
501
499
  cluster_stack_name = nil
502
500
  stacks_to_delete = []
@@ -506,6 +504,7 @@ class Release
506
504
  cluster_stack_name = stack.stack_name
507
505
  else
508
506
  break unless stack.stack_name.match(/#{env_hash}$/)
507
+
509
508
  stacks_to_delete.push(stack.stack_name)
510
509
  delete_stack(stack.stack_name)
511
510
  end
@@ -515,47 +514,45 @@ class Release
515
514
  cluster_stack_name = "ecs-cluster-#{env_hash}"
516
515
  if stack_exists?(cluster_stack_name)
517
516
  aggregator_enabled = get_stack_tags(cluster_stack_name).detect do |tag|
518
- tag.key === "hostname_pattern_priority" and tag.value === "1"
517
+ tag.key === 'hostname_pattern_priority' and tag.value === '1'
519
518
  end.is_a?(Aws::CloudFormation::Types::Tag)
520
519
 
521
- if aggregator_enabled
522
- dns_to_staging(env_hash)
523
- end
520
+ dns_to_staging(env_hash) if aggregator_enabled
524
521
  end
525
522
 
526
523
  # 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"
524
+ output 'Attendo 10 secondi per poter eliminare il cluster ECS'
528
525
 
529
526
  while stacks_to_delete.length > 0
530
527
  sleep 13
531
528
  stacks_to_delete.each do |stack_name|
532
- stacks_to_delete = stacks_to_delete - [stack_name] unless stack_exists?(stack_name)
529
+ stacks_to_delete -= [stack_name] unless stack_exists?(stack_name)
533
530
  end
534
- output "Stack ancora attivi: #{stacks_to_delete.length.to_s}. Attendo altri 10 secondi per eliminare il cluster ECS"
531
+ output "Stack ancora attivi: #{stacks_to_delete.length}. Attendo altri 10 secondi per eliminare il cluster ECS"
535
532
  end
536
533
 
537
534
  delete_stack(cluster_stack_name) if stack_exists?(cluster_stack_name)
538
535
  delete_stack(@base_stack_name_alb + env_hash[3..8]) if stack_exists?(@base_stack_name_alb + env_hash[3..8])
539
536
  delete_stack(@base_stack_name_alb_ws + env_hash[3..8]) if stack_exists?(@base_stack_name_alb_ws + env_hash[3..8])
540
537
  `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
538
+ output 'Cancello il record DNS utilizzato da Lighthouse'
539
+ delete_lighthouse_dns
540
+ output 'Finito!'.green
544
541
  end
545
542
 
546
543
  def qainit_write_output(file_message, output_message)
547
544
  `mkdir -p /etc/qainit-output`
548
- qa_file_name = "/etc/qainit-output/url_qa"
545
+ qa_file_name = '/etc/qainit-output/url_qa'
549
546
  File.open(qa_file_name + '.txt', 'w') { |file| file.write(file_message) }
550
547
  output "#{output_message} #{qa_file_name}".green
551
548
  end
552
549
 
553
- def update_drone_yml!()
550
+ def update_drone_yml!
554
551
  drone_yml = File.read('.drone.yml')
555
552
  @projects.each do |key, project|
556
553
  drone_yml = drone_yml.gsub(/#{key}@.+\n/, "#{key}@#{project['revision']}\n")
557
554
  end
558
- File.open(".drone.yml", "w") do |f|
555
+ File.open('.drone.yml', 'w') do |f|
559
556
  f.write(drone_yml)
560
557
  end
561
558
  end
@@ -570,10 +567,9 @@ class Release
570
567
  end
571
568
 
572
569
  def get_alb_host(stack_name)
573
- case
574
- when stack_name.include?('alb-http-public')
570
+ if stack_name.include?('alb-http-public')
575
571
  logical_resource_id = 'EcsApplicationLoadBalancerPublic'
576
- when stack_name.include?('alb-ws-public')
572
+ elsif stack_name.include?('alb-ws-public')
577
573
  logical_resource_id = 'EcsApplicationLoadBalancerPublic'
578
574
  end
579
575
  resp = describe_stack_resource(stack_name, logical_resource_id)
@@ -589,8 +585,8 @@ class Release
589
585
  def choose_branch_to_deploy(project_name, select_master = false)
590
586
  # chiamare api octokit per recuperare i branch/commit
591
587
  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]
588
+ branches = @gh.branches("primait/#{project_name}", { per_page: 100 })
589
+ master_branch = branches.select { |branch| branch[:name] == 'master' }[0]
594
590
 
595
591
  if select_master || branches.length == 1
596
592
  branch_name = 'master'
@@ -612,7 +608,7 @@ class Release
612
608
  end
613
609
  end
614
610
 
615
- chosen_branch = branches.select {|branch| branch[:name] == branch_name}[0]
611
+ chosen_branch = branches.select { |branch| branch[:name] == branch_name }[0]
616
612
  name = branch_name
617
613
  revision = chosen_branch[:commit][:sha]
618
614
  { 'name' => name, 'revision' => revision[0..14], 'default_branch' => select_master }
@@ -627,7 +623,7 @@ class Release
627
623
  { 'name' => name, 'revision' => revision[0..14], 'committer' => committer_email }
628
624
  end
629
625
 
630
- def get_stacks()
626
+ def get_stacks
631
627
  envs = {}
632
628
  stack_list = stack_list()
633
629
  stack_list.each do |stack|
@@ -636,10 +632,10 @@ class Release
636
632
  envs[env_hash] = stack.tags unless envs.has_key?(env_hash) || stack.tags.empty?
637
633
  end
638
634
  end
639
- return stack_list, envs
635
+ [stack_list, envs]
640
636
  end
641
637
 
642
- def get_clusters()
638
+ def get_clusters
643
639
  envs = {}
644
640
  cluster_list = cluster_list()
645
641
  cluster_list.each do |stack|
@@ -648,63 +644,65 @@ class Release
648
644
  envs[env_hash] = stack.tags unless envs.has_key?(env_hash) || stack.tags.empty?
649
645
  end
650
646
  end
651
- return cluster_list, envs
647
+ [cluster_list, envs]
652
648
  end
653
649
 
654
- def hostname_pattern_priority()
655
- (Time.now.to_i.to_s[-4..-1].to_i + Random.rand(40000)).to_s
650
+ def hostname_pattern_priority
651
+ (Time.now.to_i.to_s[-4..-1].to_i + Random.rand(40_000)).to_s
656
652
  end
657
653
 
658
654
  def select_branches(project_names = nil)
659
- output "Deploy feature menu"
655
+ output 'Deploy feature menu'
660
656
  if project_names.nil?
661
- @projects.each{ |key, value| @projects[key] = choose_branch_to_deploy(key) }
657
+ @projects.each { |key, _value| @projects[key] = choose_branch_to_deploy(key) }
662
658
  else
663
659
  project_names.each do |project|
664
660
  @projects[project] = choose_branch_to_deploy(project)
665
661
  end
666
662
  @projects.each_key do |branch_project|
667
- @projects[branch_project] = choose_branch_to_deploy(branch_project, true) unless project_names.include? branch_project
663
+ unless project_names.include? branch_project
664
+ @projects[branch_project] = choose_branch_to_deploy(branch_project, true)
665
+ end
668
666
  end
669
667
  end
670
668
  end
671
669
  end
672
670
 
673
671
  def help_content
674
- <<-HELP
672
+ <<~HELP
675
673
 
676
- twig-feature
677
- ===========
674
+ twig-feature
675
+ ===========
678
676
 
679
- Manage feature branches
677
+ Manage feature branches
680
678
 
681
- Synopsis
682
- --------
679
+ Synopsis
680
+ --------
683
681
 
684
- twig release start
685
- twig release finish
686
- twig release deploy
687
- twig release aggregator
682
+ twig release start
683
+ twig release finish
684
+ twig release deploy
685
+ twig release aggregator
688
686
 
689
- Description
690
- -----------
687
+ Description
688
+ -----------
691
689
 
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
690
+ start creates a new feature branch
691
+ finish finishes the feature by merging to dev and master
692
+ qainit deploys a new environment with selected branches from every project
693
+ qainit $PROJECT_NAME deploys a new environment allowing to selected a branch from the input project (everything else is master)
694
+ qainit shutdown deletes a specific qa environment
697
695
 
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
696
+ Available only to devops (from artemide)
697
+ -----------
698
+ deploy deploys the feature branch to a temporary AWS Elastic Beanstalk env
699
+ deploy stop destroys the AWS Elastic Beanstalk env
700
+ deploy update updates a feature branch with current branches
701
+ deploy lock protects a qa environment from automatic deletion
702
+ aggregator enable/disable directs comparator's staging environments to a qa/staging
705
703
 
706
- Subcommand for Twig: <http://rondevera.github.io/twig/>
707
- Author: Andrea Usuelli <https://github.com/andreausu>
704
+ Subcommand for Twig: <http://rondevera.github.io/twig/>
705
+ Author: Andrea Usuelli <https://github.com/andreausu>
708
706
 
709
707
  HELP
710
708
  end
@@ -717,9 +715,7 @@ if args.include?('--help')
717
715
  end
718
716
 
719
717
  gem_update = true
720
- if args.include?('no-gem-update')
721
- gem_update = false
722
- end
718
+ gem_update = false if args.include?('no-gem-update')
723
719
 
724
720
  args.delete('no-gem-update')
725
721
 
@@ -64,10 +64,10 @@ module Command
64
64
 
65
65
  # executes command and returns properly colored output
66
66
  def execute_command(cmd)
67
- output "Eseguo #{cmd}".yellow
67
+ output "Executing #{cmd}".yellow
68
68
  res = `#{cmd}`
69
69
  color = $CHILD_STATUS.exitstatus.zero? ? 'green' : 'red'
70
70
  output res.send color
71
- stop_if (color == 'red'), "Errore durante la build dell'artifact".red
71
+ stop_if (color == 'red'), 'Error'.red
72
72
  end
73
73
  end
@@ -7,7 +7,6 @@ require 'aws-sdk-ecs'
7
7
  require 'aws-sdk-elasticloadbalancingv2'
8
8
  require 'aws-sdk-s3'
9
9
  require 'colorize'
10
- #
11
10
  module PrimaAwsClient
12
11
  def s3_client
13
12
  @s3 ||= Aws::S3::Client.new
@@ -48,6 +47,7 @@ module PrimaAwsClient
48
47
  end
49
48
  stacks += resp.stacks
50
49
  break unless resp.next_token
50
+
51
51
  next_token = resp.next_token
52
52
  end
53
53
  puts '.'.yellow; STDOUT.flush
@@ -70,6 +70,7 @@ module PrimaAwsClient
70
70
  end
71
71
  stacks += resp.stacks
72
72
  break unless resp.next_token
73
+
73
74
  next_token = resp.next_token
74
75
  end
75
76
  puts '.'.yellow; STDOUT.flush
@@ -92,6 +93,7 @@ module PrimaAwsClient
92
93
  end
93
94
  exports += resp.exports
94
95
  break unless resp.next_token
96
+
95
97
  next_token = resp.next_token
96
98
  end
97
99
  puts '.'.yellow; STDOUT.flush
@@ -108,9 +110,7 @@ module PrimaAwsClient
108
110
  on_failure: 'ROLLBACK'
109
111
  }
110
112
 
111
- if role != nil then
112
- cf_args.merge!(role_arn: role)
113
- end
113
+ cf_args.merge!(role_arn: role) unless role.nil?
114
114
 
115
115
  begin
116
116
  cf_client.create_stack(cf_args)
@@ -119,7 +119,7 @@ module PrimaAwsClient
119
119
  sleep 15
120
120
  create_stack(stack_name, stack_body, parameters = [], tags = [])
121
121
  else
122
- output "La creazione dello stack #{stack_name} è stata avviata".green
122
+ output "CloudFormation stack #{stack_name} creation started".green
123
123
  end
124
124
  end
125
125
 
@@ -132,9 +132,7 @@ module PrimaAwsClient
132
132
  capabilities: ['CAPABILITY_IAM']
133
133
  }
134
134
 
135
- if role != nil then
136
- cf_args.merge!(role_arn: role)
137
- end
135
+ cf_args.merge!(role_arn: role) unless role.nil?
138
136
 
139
137
  begin
140
138
  cf_client.update_stack(cf_args)
@@ -145,7 +143,7 @@ module PrimaAwsClient
145
143
  rescue Aws::CloudFormation::Errors::ValidationError => e
146
144
  raise e
147
145
  else
148
- output "L'update dello stack #{stack_name} è stato avviato".green
146
+ output "CloudFormation stack #{stack_name} update started".green
149
147
  end
150
148
  end
151
149
 
@@ -158,9 +156,7 @@ module PrimaAwsClient
158
156
  capabilities: ['CAPABILITY_IAM']
159
157
  }
160
158
 
161
- if role != nil then
162
- cf_args.merge!(role_arn: role)
163
- end
159
+ cf_args.merge!(role_arn: role) unless role.nil?
164
160
 
165
161
  begin
166
162
  cf_client.update_stack(cf_args)
@@ -171,7 +167,7 @@ module PrimaAwsClient
171
167
  rescue Aws::CloudFormation::Errors::ValidationError => e
172
168
  raise e
173
169
  else
174
- output "L'update dello stack #{stack_name} è stato avviato".green
170
+ output "CloudFormation stack #{stack_name} update started".green
175
171
  end
176
172
  end
177
173
 
@@ -184,9 +180,7 @@ module PrimaAwsClient
184
180
  capabilities: ['CAPABILITY_IAM']
185
181
  }
186
182
 
187
- if role != nil then
188
- cf_args.merge!(role_arn: role)
189
- end
183
+ cf_args.merge!(role_arn: role) unless role.nil?
190
184
 
191
185
  begin
192
186
  cf_client.update_stack(cf_args)
@@ -197,64 +191,63 @@ module PrimaAwsClient
197
191
  rescue Aws::CloudFormation::Errors::ValidationError => e
198
192
  raise e
199
193
  else
200
- output "L'update dello stack #{stack_name} è stato avviato".green
194
+ output "CloudFormation stack #{stack_name} update started".green
201
195
  end
202
196
  end
203
197
 
204
198
  def stack_exists?(stack_name)
205
- begin
206
- cf_client.describe_stacks(stack_name: stack_name)
207
- rescue Aws::CloudFormation::Errors::Throttling => e
208
- output 'Throttling, retrying in 15 seconds'.red
209
- sleep 15
210
- stack_exists?(stack_name)
211
- rescue Aws::CloudFormation::Errors::ValidationError => e
212
- return false if e.message.include? 'does not exist'
213
- raise e
214
- else
215
- true
216
- end
199
+ cf_client.describe_stacks(stack_name: stack_name)
200
+ rescue Aws::CloudFormation::Errors::Throttling => e
201
+ output 'Throttling, retrying in 15 seconds'.red
202
+ sleep 15
203
+ stack_exists?(stack_name)
204
+ rescue Aws::CloudFormation::Errors::ValidationError => e
205
+ return false if e.message.include? 'does not exist'
206
+
207
+ raise e
208
+ else
209
+ true
217
210
  end
218
211
 
219
212
  def delete_stack(stack_name)
220
- begin
221
- cf_client.delete_stack(stack_name: stack_name)
222
- rescue Aws::CloudFormation::Errors::Throttling => e
223
- output 'Throttling, retrying in 15 seconds'.red
224
- sleep 15
225
- delete_stack(stack_name)
226
- else
227
- output "Stack #{stack_name} spenta con successo\n".green
228
- end
213
+ cf_client.delete_stack(stack_name: stack_name)
214
+ rescue Aws::CloudFormation::Errors::Throttling => e
215
+ output 'Throttling, retrying in 15 seconds'.red
216
+ sleep 15
217
+ delete_stack(stack_name)
218
+ else
219
+ output "Stack #{stack_name} shutdown succesfully\n".green
229
220
  end
230
221
 
231
- def wait_for_stack_ready(stack_name, failed_statuses = ['CREATE_FAILED', 'ROLLBACK_IN_PROGRESS', 'ROLLBACK_FAILED', 'DELETE_IN_PROGRESS', 'DELETE_FAILED', 'DELETE_COMPLETE', 'UPDATE_ROLLBACK_FAILED', 'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS'])
222
+ def wait_for_stack_ready(stack_name, failed_statuses = %w[CREATE_FAILED ROLLBACK_IN_PROGRESS ROLLBACK_FAILED DELETE_IN_PROGRESS DELETE_FAILED DELETE_COMPLETE UPDATE_ROLLBACK_FAILED UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS])
232
223
  ready = false
233
224
  sleep_seconds = 13
234
- output "Attendo che lo stack #{stack_name} finisca di essere inizializzato...\n".yellow
235
- while !ready
225
+ output "Waiting for stack #{stack_name}...\n".yellow
226
+ until ready
236
227
  ready = true if stack_ready?(stack_name, failed_statuses)
237
228
  seconds_elapsed = 0
238
229
  loop do
239
230
  break if seconds_elapsed >= sleep_seconds
231
+
240
232
  print '.'.yellow; STDOUT.flush
241
233
  sleep 1
242
234
  seconds_elapsed += 1
243
235
  end
244
236
  end
245
- output "\nStack #{stack_name} pronto!\n".green
237
+ output "\nStack #{stack_name} ready!\n".green
246
238
  end
247
239
 
248
240
  def wait_for_stack_removal(stack_name)
249
241
  ready = false
250
242
  sleep_seconds = 13
251
243
  sleep 10
252
- output "Attendo che lo stack #{stack_name} finisca di essere cancellato...\n".yellow
253
- while !ready
244
+ output "Waiting for stack #{stack_name}...\n".yellow
245
+ until ready
254
246
  ready = true if stack_deleted?(stack_name)
255
247
  seconds_elapsed = 0
256
248
  loop do
257
249
  break if seconds_elapsed >= sleep_seconds
250
+
258
251
  print '.'.yellow; STDOUT.flush
259
252
  sleep 1
260
253
  seconds_elapsed += 1
@@ -264,55 +257,46 @@ module PrimaAwsClient
264
257
  end
265
258
 
266
259
  def get_stack_tags(name)
267
- begin
268
- resp = cf_client.describe_stacks(stack_name: name)
269
- rescue Aws::CloudFormation::Errors::Throttling => e
270
- output 'Throttling, retrying in 15 seconds'.red
271
- sleep 15
272
- get_stack_tags(name)
273
- else
274
- resp.stacks[0].tags
275
- end
260
+ resp = cf_client.describe_stacks(stack_name: name)
261
+ rescue Aws::CloudFormation::Errors::Throttling => e
262
+ output 'Throttling, retrying in 15 seconds'.red
263
+ sleep 15
264
+ get_stack_tags(name)
265
+ else
266
+ resp.stacks[0].tags
276
267
  end
277
268
 
278
269
  def get_stack_parameters(name)
279
- begin
280
- resp = cf_client.describe_stacks(stack_name: name)
281
- rescue Aws::CloudFormation::Errors::Throttling => e
282
- output 'Throttling, retrying in 15 seconds'.red
283
- sleep 15
284
- get_stack_parameters(name)
285
- else
286
- resp.stacks[0].parameters
287
- end
270
+ resp = cf_client.describe_stacks(stack_name: name)
271
+ rescue Aws::CloudFormation::Errors::Throttling => e
272
+ output 'Throttling, retrying in 15 seconds'.red
273
+ sleep 15
274
+ get_stack_parameters(name)
275
+ else
276
+ resp.stacks[0].parameters
288
277
  end
289
278
 
290
279
  def get_stack_outputs(name)
291
- begin
292
- resp = cf_client.describe_stacks(stack_name: name)
293
- rescue Aws::CloudFormation::Errors::Throttling => e
294
- output 'Throttling, retrying in 15 seconds'.red
295
- sleep 15
296
- get_stack_outputs(name)
297
- else
298
- resp.stacks[0].outputs
299
- end
280
+ resp = cf_client.describe_stacks(stack_name: name)
281
+ rescue Aws::CloudFormation::Errors::Throttling => e
282
+ output 'Throttling, retrying in 15 seconds'.red
283
+ sleep 15
284
+ get_stack_outputs(name)
285
+ else
286
+ resp.stacks[0].outputs
300
287
  end
301
288
 
302
289
  def get_stack_template(name)
303
- begin
304
- resp = cf_client.get_template(stack_name: name)
305
- rescue Aws::CloudFormation::Errors::Throttling => e
306
- output 'Throttling, retrying in 15 seconds'.red
307
- sleep 15
308
- get_stack_template(name)
309
- else
310
- resp.template_body
311
- end
312
-
290
+ resp = cf_client.get_template(stack_name: name)
291
+ rescue Aws::CloudFormation::Errors::Throttling => e
292
+ output 'Throttling, retrying in 15 seconds'.red
293
+ sleep 15
294
+ get_stack_template(name)
295
+ else
296
+ resp.template_body
313
297
  end
314
298
 
315
- def stack_ready?(stack_name, failed_statuses = ['CREATE_FAILED', 'ROLLBACK_IN_PROGRESS', 'ROLLBACK_FAILED', 'DELETE_IN_PROGRESS', 'DELETE_FAILED', 'DELETE_COMPLETE', 'UPDATE_ROLLBACK_FAILED', 'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS'])
299
+ def stack_ready?(stack_name, failed_statuses = %w[CREATE_FAILED ROLLBACK_IN_PROGRESS ROLLBACK_FAILED DELETE_IN_PROGRESS DELETE_FAILED DELETE_COMPLETE UPDATE_ROLLBACK_FAILED UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS])
316
300
  begin
317
301
  resp = cf_client.describe_stacks(
318
302
  stack_name: stack_name
@@ -323,10 +307,11 @@ module PrimaAwsClient
323
307
  return false
324
308
  end
325
309
  raise "The stack #{stack_name} errored out" if failed_statuses.include? stack_status
326
- ['CREATE_COMPLETE', 'UPDATE_COMPLETE', 'UPDATE_ROLLBACK_COMPLETE', 'ROLLBACK_COMPLETE'].include? stack_status
310
+
311
+ %w[CREATE_COMPLETE UPDATE_COMPLETE UPDATE_ROLLBACK_COMPLETE ROLLBACK_COMPLETE].include? stack_status
327
312
  end
328
313
 
329
- def stack_deleted?(stack_name, failed_statuses = ['ROLLBACK_IN_PROGRESS', 'ROLLBACK_FAILED', 'DELETE_FAILED', 'UPDATE_ROLLBACK_FAILED', 'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS'])
314
+ def stack_deleted?(stack_name, failed_statuses = %w[ROLLBACK_IN_PROGRESS ROLLBACK_FAILED DELETE_FAILED UPDATE_ROLLBACK_FAILED UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS])
330
315
  begin
331
316
  resp = cf_client.describe_stacks(
332
317
  stack_name: stack_name
@@ -340,6 +325,7 @@ module PrimaAwsClient
340
325
  return true
341
326
  end
342
327
  raise "The stack #{stack_name} errored out" if failed_statuses.include? stack_status
328
+
343
329
  ['DELETE_COMPLETE'].include? stack_status
344
330
  end
345
331
 
@@ -352,38 +338,39 @@ module PrimaAwsClient
352
338
  !resp.contents.empty?
353
339
  end
354
340
 
355
- def upload_artifact(source_path, destination_path, bucket_name_override=nil)
356
- output "Upload dell'artifact in corso (#{(File.size(source_path).to_f / 2**20).round(2)} MiB)\n".yellow
341
+ def upload_artifact(source_path, destination_path, bucket_name_override = nil)
342
+ output "Uploading artifact (#{(File.size(source_path).to_f / 2**20).round(2)} MiB)\n".yellow
357
343
  s3 = Aws::S3::Resource.new
358
- s3_bucket = if !bucket_name_override.nil? then bucket_name_override else @s3_bucket end
344
+ s3_bucket = !bucket_name_override.nil? ? bucket_name_override : @s3_bucket
359
345
  puts s3_bucket
360
346
  obj = s3.bucket(s3_bucket).object(destination_path)
361
347
  obj.upload_file(source_path)
362
348
 
363
- output "#{s3_bucket}/#{destination_path} uploadato con successo!\n".green
349
+ output "#{s3_bucket}/#{destination_path} upload success!\n".green
364
350
  end
365
351
 
366
352
  def wait_for_artifact(bucket, path)
367
353
  ready = artifact_exists?(bucket, path)
368
354
  sleep_seconds = 13
369
- output "Attendo che sia pronto l'artefatto #{path}...\n".yellow
355
+ output "Wating that artifact #{path} becomes ready...\n".yellow
370
356
  retries = 0
371
- while !ready
357
+ until ready
372
358
  ready = true if artifact_exists?(bucket, path)
373
359
  seconds_elapsed = 0
374
360
  loop do
375
361
  break if seconds_elapsed >= sleep_seconds
362
+
376
363
  print '.'.yellow; STDOUT.flush
377
364
  sleep 1
378
365
  seconds_elapsed += 1
379
366
  end
380
367
  retries += 1
381
368
  if retries > 150
382
- output "\n Timeout raggiunto aspettando #{path}\n".red
369
+ output "\n Artifact #{path} timed out\n".red
383
370
  exit
384
371
  end
385
372
  end
386
- output "\nArtefatto #{path} creato!\n".green
373
+ output "\nArtifact #{path} created!\n".green
387
374
  end
388
375
 
389
376
  def list_import_stacks(export_name)
@@ -391,7 +378,7 @@ module PrimaAwsClient
391
378
  next_token = ''
392
379
  loop do
393
380
  print '.'.yellow; STDOUT.flush
394
- options = next_token != '' ? { export_name: export_name, next_token: next_token } : {export_name: export_name}
381
+ options = next_token != '' ? { export_name: export_name, next_token: next_token } : { export_name: export_name }
395
382
  begin
396
383
  resp = cf_client.list_imports(options)
397
384
  rescue Aws::CloudFormation::Errors::Throttling => e
@@ -401,94 +388,81 @@ module PrimaAwsClient
401
388
  end
402
389
  stacks += resp.imports
403
390
  break unless resp.next_token
391
+
404
392
  next_token = resp.next_token
405
393
  end
406
394
  stacks
407
395
  end
408
396
 
409
397
  def describe_stack_resource(cluster_stack_name, logical_resource_id)
410
- begin
411
- resp = cf_client.describe_stack_resource({stack_name: cluster_stack_name, logical_resource_id: logical_resource_id})
412
- rescue Aws::CloudFormation::Errors::Throttling => e
413
- output 'Throttling, retrying in 15 seconds'.red
414
- sleep 15
415
- resp = describe_stack_resource(cluster_stack_name, logical_resource_id)
416
- end
398
+ resp = cf_client.describe_stack_resource({ stack_name: cluster_stack_name, logical_resource_id: logical_resource_id })
399
+ rescue Aws::CloudFormation::Errors::Throttling => e
400
+ output 'Throttling, retrying in 15 seconds'.red
401
+ sleep 15
402
+ resp = describe_stack_resource(cluster_stack_name, logical_resource_id)
417
403
  end
418
404
 
419
405
  def describe_instances(instance_ids)
420
- begin
421
- resp = ec2_client.describe_instances({instance_ids: instance_ids})
422
- rescue Aws::CloudFormation::Errors::Throttling => e
423
- output 'Throttling, retrying in 15 seconds'.red
424
- sleep 15
425
- resp = describe_instances(instance_ids)
426
- end
406
+ resp = ec2_client.describe_instances({ instance_ids: instance_ids })
407
+ rescue Aws::CloudFormation::Errors::Throttling => e
408
+ output 'Throttling, retrying in 15 seconds'.red
409
+ sleep 15
410
+ resp = describe_instances(instance_ids)
427
411
  end
428
412
 
429
413
  def describe_auto_scaling_groups(auto_scaling_group_names, max_records)
430
- begin
431
- resp = asg_client.describe_auto_scaling_groups({
432
- auto_scaling_group_names: auto_scaling_group_names,
433
- max_records: max_records
434
- })
435
- rescue Aws::CloudFormation::Errors::Throttling => e
436
- output 'Throttling, retrying in 15 seconds'.red
437
- sleep 15
438
- resp = describe_auto_scaling_groups(auto_scaling_group_names, max_records)
439
- end
414
+ resp = asg_client.describe_auto_scaling_groups({
415
+ auto_scaling_group_names: auto_scaling_group_names,
416
+ max_records: max_records
417
+ })
418
+ rescue Aws::CloudFormation::Errors::Throttling => e
419
+ output 'Throttling, retrying in 15 seconds'.red
420
+ sleep 15
421
+ resp = describe_auto_scaling_groups(auto_scaling_group_names, max_records)
440
422
  end
441
423
 
442
424
  def describe_load_balancers(load_balancer_arns)
443
- begin
444
- resp = alb_client.describe_load_balancers({load_balancer_arns: load_balancer_arns})
445
- rescue Aws::ElasticLoadBalancingV2::Errors::Throttling => e
446
- output 'Throttling, retrying in 15 seconds'.red
447
- sleep 15
448
- resp = describe_load_balancers(load_balancer_arns)
449
- end
425
+ resp = alb_client.describe_load_balancers({ load_balancer_arns: load_balancer_arns })
426
+ rescue Aws::ElasticLoadBalancingV2::Errors::Throttling => e
427
+ output 'Throttling, retrying in 15 seconds'.red
428
+ sleep 15
429
+ resp = describe_load_balancers(load_balancer_arns)
450
430
  end
451
431
 
452
432
  def update_ecs_service(cluster, service, deployment_configuration)
453
- begin
454
- resp = ecs_client.update_service(
455
- cluster: cluster,
456
- service: service,
457
- deployment_configuration: deployment_configuration
458
- )
459
- rescue Aws::CloudFormation::Errors::Throttling => e
460
- output 'Throttling, retrying in 15 seconds'.red
461
- sleep 15
462
- resp = update_ecs_service(cluster, service, deployment_configuration)
463
- end
433
+ resp = ecs_client.update_service(
434
+ cluster: cluster,
435
+ service: service,
436
+ deployment_configuration: deployment_configuration
437
+ )
438
+ rescue Aws::CloudFormation::Errors::Throttling => e
439
+ output 'Throttling, retrying in 15 seconds'.red
440
+ sleep 15
441
+ resp = update_ecs_service(cluster, service, deployment_configuration)
464
442
  end
465
443
 
466
444
  def describe_ecs_tasks(cluster, tasks)
467
- begin
468
- resp = ecs_client.describe_tasks({
469
- cluster: cluster,
470
- tasks: tasks
471
- })
472
- rescue Aws::CloudFormation::Errors::Throttling => e
473
- output 'Throttling, retrying in 15 seconds'.red
474
- sleep 15
475
- resp = describe_ecs_tasks(cluster, tasks)
476
- end
445
+ resp = ecs_client.describe_tasks({
446
+ cluster: cluster,
447
+ tasks: tasks
448
+ })
449
+ rescue Aws::CloudFormation::Errors::Throttling => e
450
+ output 'Throttling, retrying in 15 seconds'.red
451
+ sleep 15
452
+ resp = describe_ecs_tasks(cluster, tasks)
477
453
  end
478
454
 
479
455
  def run_ecs_task(cluster, task_definition, overrides, count)
480
- begin
481
- resp = ecs_client.run_task({
482
- cluster: cluster,
483
- task_definition: task_definition,
484
- overrides: overrides,
485
- count: count
486
- })
487
- rescue Aws::CloudFormation::Errors::Throttling => e
488
- output 'Throttling, retrying in 15 seconds'.red
489
- sleep 15
490
- resp = run_ecs_task(cluster, task_definition, overrides, count)
491
- end
456
+ resp = ecs_client.run_task({
457
+ cluster: cluster,
458
+ task_definition: task_definition,
459
+ overrides: overrides,
460
+ count: count
461
+ })
462
+ rescue Aws::CloudFormation::Errors::Throttling => e
463
+ output 'Throttling, retrying in 15 seconds'.red
464
+ sleep 15
465
+ resp = run_ecs_task(cluster, task_definition, overrides, count)
492
466
  end
493
467
 
494
468
  def get_autoscaling_capacity(asg_name)
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.0
4
+ version: 1.3.5
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-16 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