prima-twig 1.3.0 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/twig-feature +156 -160
- data/lib/command.rb +2 -2
- data/lib/prima_aws_client.rb +131 -157
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 975828594ae14f606a510643c544f4cd363ef6d86be3df0e2e3a1681e4422389
|
4
|
+
data.tar.gz: 6e30a88cd7ecf87e520b0c96c946a58cd6a5abd022840eae4fee841a9a5fd8d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c2c214e6a37ee5103ff495cfb63717bde238d740810426dd2639d25d57b7d6825659749c423b8e55518f20866b05f4c940f465124d38b3a43cc50725bca322a
|
7
|
+
data.tar.gz: 1e7127439d07ff017821ca372dcde66465aa7eb43a25391ee6ccd7bd033e41f6639402edadfcecb434dfbc728a30b9a633b3e8bc1fddb41f59fbd0b8a03d1b4e
|
data/bin/twig-feature
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
-
require_relative '../lib/prima_twig
|
5
|
-
require_relative '../lib/prima_aws_client
|
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
|
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(:
|
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
|
63
|
-
if [
|
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
|
107
|
-
output
|
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
|
-
|
112
|
-
|
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 ===
|
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(
|
119
|
-
stop_if dns_records.body[:result].empty?,
|
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
|
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
|
-
|
142
|
+
if envs.empty?
|
143
|
+
output 'Nessun QA trovato'.red
|
144
|
+
exit
|
145
|
+
else
|
142
146
|
env_hash = choose do |menu|
|
143
|
-
menu.prompt =
|
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 =
|
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,
|
160
|
+
change_hostname_priority(env_hash, '1')
|
160
161
|
|
161
162
|
dns_records.body[:result].each do |dns|
|
162
|
-
if dns[:name] =~ /^\w
|
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
|
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 ===
|
175
|
+
if tag.key === 'hostname_pattern_priority'
|
175
176
|
{
|
176
|
-
key:
|
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 ===
|
202
|
+
if param.parameter_key === 'HostnamePatternPriority'
|
202
203
|
{
|
203
|
-
parameter_key:
|
204
|
+
parameter_key: 'HostnamePatternPriority',
|
204
205
|
parameter_value: hostname_pattern_priority
|
205
206
|
}
|
206
|
-
elsif param.parameter_key ===
|
207
|
+
elsif param.parameter_key === 'HostnamePatternAggregatorPriority'
|
207
208
|
{
|
208
|
-
parameter_key:
|
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
|
223
|
-
dns_records = @cloudflare.get(
|
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
|
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
|
234
|
+
output 'Recupero le informazioni sui QA attivi...'
|
234
235
|
stack_list, envs = get_stacks
|
235
236
|
|
236
237
|
env_hash = nil
|
237
|
-
|
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 ===
|
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
|
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
|
285
|
+
stacks_to_delete -= [stack_name] unless stack_exists?(stack_name)
|
286
286
|
end
|
287
|
-
output "Stack ancora attivi: #{stacks_to_delete.length
|
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
|
293
|
+
output 'Finito!'.green
|
294
294
|
end
|
295
295
|
|
296
296
|
def deploy_lock!
|
297
|
-
output
|
297
|
+
output 'Deploy update menu'
|
298
298
|
`git pull`
|
299
299
|
|
300
|
-
output
|
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
|
-
|
304
|
+
if envs.empty?
|
305
|
+
output 'Nessun QA trovato'.red
|
306
|
+
exit
|
307
|
+
else
|
305
308
|
env_hash = choose do |menu|
|
306
|
-
menu.prompt =
|
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 <<
|
314
|
+
title << e.value.to_s if e.key == 'qainit'
|
312
315
|
end
|
313
|
-
msg =
|
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
|
331
|
+
output 'Finito!'.green
|
332
332
|
end
|
333
333
|
|
334
334
|
def deploy_update!
|
335
|
-
output
|
335
|
+
output 'Deploy update menu'
|
336
336
|
`git pull`
|
337
337
|
|
338
|
-
output
|
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
|
-
|
342
|
+
if envs.empty?
|
343
|
+
output 'Nessun QA trovato'.red
|
344
|
+
exit
|
345
|
+
else
|
343
346
|
env_hash = choose do |menu|
|
344
|
-
menu.prompt =
|
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 =
|
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 [
|
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
|
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']
|
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?(
|
378
|
-
arg_projects = YAML.load(File.read(
|
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
|
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(
|
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 =
|
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(
|
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(
|
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 =
|
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
|
494
|
+
output 'Recupero le informazioni sui QA attivi...'
|
497
495
|
stack_list, envs = get_stacks
|
498
496
|
|
499
|
-
env_hash =
|
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 ===
|
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
|
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
|
529
|
+
stacks_to_delete -= [stack_name] unless stack_exists?(stack_name)
|
533
530
|
end
|
534
|
-
output "Stack ancora attivi: #{stacks_to_delete.length
|
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
|
542
|
-
delete_lighthouse_dns
|
543
|
-
output
|
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 =
|
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(
|
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
|
-
|
574
|
-
when stack_name.include?('alb-http-public')
|
570
|
+
if stack_name.include?('alb-http-public')
|
575
571
|
logical_resource_id = 'EcsApplicationLoadBalancerPublic'
|
576
|
-
|
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
|
-
|
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
|
-
|
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(
|
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
|
655
|
+
output 'Deploy feature menu'
|
660
656
|
if project_names.nil?
|
661
|
-
@projects.each{ |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
|
-
|
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
|
-
|
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
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
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
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
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
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
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
|
|
data/lib/command.rb
CHANGED
@@ -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 "
|
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'),
|
71
|
+
stop_if (color == 'red'), 'Error'.red
|
72
72
|
end
|
73
73
|
end
|
data/lib/prima_aws_client.rb
CHANGED
@@ -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
|
-
|
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 "
|
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
|
-
|
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 "
|
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
|
-
|
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 "
|
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
|
-
|
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 "
|
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
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
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
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
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 = [
|
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 "
|
235
|
-
|
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}
|
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 "
|
253
|
-
|
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
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
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
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
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
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
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 = [
|
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
|
-
|
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 = [
|
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 "
|
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 =
|
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}
|
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 "
|
355
|
+
output "Wating that artifact #{path} becomes ready...\n".yellow
|
370
356
|
retries = 0
|
371
|
-
|
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
|
369
|
+
output "\n Artifact #{path} timed out\n".red
|
383
370
|
exit
|
384
371
|
end
|
385
372
|
end
|
386
|
-
output "\
|
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
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
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
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
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
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
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
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
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
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
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
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
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
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
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.
|
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-
|
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
|