prima-twig 0.23.2 → 0.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/twig-feature +214 -11
- data/lib/prima_twig.rb +2 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cdb68fcab4e2545accf55a97e9727cc9afb43b5
|
4
|
+
data.tar.gz: a3ac16212ed2ea647d1fa56e33dc66ef89ccb616
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16b7da2afb3f16a1c6b934dcb76c64a61ff545b5ebac08695bbc3648fb715d615a7c3757c2e4e2cfd54e00d2fea8d012f379283e56021d6768f9a3dacff3cdba
|
7
|
+
data.tar.gz: 395805863bb009fbd464f032eb17b96728a5082aff89b80d48e0582ce95932290bcc8290f3e45819d960afb0ab87f047a79e7be28df874d09232e17dc97b0f82
|
data/bin/twig-feature
CHANGED
@@ -47,6 +47,14 @@ class Release
|
|
47
47
|
deploy_shutdown!
|
48
48
|
elsif "update" == args[1]
|
49
49
|
deploy_update!
|
50
|
+
elsif "aggregator" == args[1]
|
51
|
+
if args[2] and "enable" == args[2]
|
52
|
+
deploy_aggregator_enable!
|
53
|
+
elsif args[2] and "disable" == args[2]
|
54
|
+
deploy_aggregator_disable!
|
55
|
+
else
|
56
|
+
stop_for_wrong_args()
|
57
|
+
end
|
50
58
|
else
|
51
59
|
if args[1]
|
52
60
|
select_branches(args[1])
|
@@ -57,10 +65,14 @@ class Release
|
|
57
65
|
end
|
58
66
|
end
|
59
67
|
else
|
60
|
-
|
68
|
+
stop_for_wrong_args()
|
61
69
|
end
|
62
70
|
end
|
63
71
|
|
72
|
+
def stop_for_wrong_args
|
73
|
+
stop_if true, [:wrong_args, ['start', 'finish', 'deploy', 'deploy project_name', 'deploy stop', 'deploy update', 'deploy aggregator enable', 'deploy aggregator disable']]
|
74
|
+
end
|
75
|
+
|
64
76
|
def start_feature!
|
65
77
|
branch_name = @prima.clean_branch_name(ask('Inserisci il nome del branch (puoi omettere feature/): '.cyan))
|
66
78
|
stop_unless branch_name.length > 0, 'Devi inserire il nome del branch'
|
@@ -73,6 +85,159 @@ class Release
|
|
73
85
|
exec_step "git checkout -b " + branch_name
|
74
86
|
end
|
75
87
|
|
88
|
+
def deploy_aggregator_disable!
|
89
|
+
output "Disable aggregator"
|
90
|
+
|
91
|
+
output "Recupero le informazioni relative al puntamento dei record DNS..."
|
92
|
+
cloudflare = Rubyflare.connect_with(@prima.config['cloudflare_email'], @prima.config['cloudflare_apikey'])
|
93
|
+
dns_records = cloudflare.get("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records", {"per_page": 100, "type": "CNAME", "content": get_alb_host(@stack_name_alb)})
|
94
|
+
stop_if dns_records.body[:result].empty?, "I record DNS degli aggregatori non stanno puntando ad un QA".red
|
95
|
+
|
96
|
+
output "Recupero le informazioni sui QA attivi..."
|
97
|
+
stack_list, envs = get_stacks()
|
98
|
+
|
99
|
+
env_hash = nil
|
100
|
+
unless envs.empty?
|
101
|
+
env_hash = envs.detect do |key, tags|
|
102
|
+
aggregator_enabled = tags.detect do |tag|
|
103
|
+
tag.key === "hostname_pattern_priority" and tag.value === "1"
|
104
|
+
end.is_a?(Aws::CloudFormation::Types::Tag)
|
105
|
+
aggregator_enabled
|
106
|
+
end[0]
|
107
|
+
change_hostname_priority(env_hash, hostname_pattern_priority())
|
108
|
+
dns_to_staging()
|
109
|
+
else
|
110
|
+
output "Nessun QA trovato".red
|
111
|
+
exit
|
112
|
+
end
|
113
|
+
|
114
|
+
output "Finito!".green
|
115
|
+
end
|
116
|
+
|
117
|
+
def deploy_aggregator_enable!
|
118
|
+
output "Enable aggregator"
|
119
|
+
|
120
|
+
output "Recupero le informazioni relative al puntamento dei record DNS..."
|
121
|
+
cloudflare = Rubyflare.connect_with(@prima.config['cloudflare_email'], @prima.config['cloudflare_apikey'])
|
122
|
+
dns_records = cloudflare.get("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records", {"per_page": 100, "type": "CNAME", "content": "staging.prima.it"})
|
123
|
+
stop_if dns_records.body[:result].empty?, "I record DNS degli aggregatori stanno gia' puntando ad un QA".red
|
124
|
+
|
125
|
+
output "Recupero le informazioni sui QA attivi..."
|
126
|
+
stack_list, envs = get_stacks()
|
127
|
+
|
128
|
+
env_hash = nil
|
129
|
+
unless envs.empty?
|
130
|
+
env_hash = choose do |menu|
|
131
|
+
menu.prompt = "Scegli il QA al quale vuoi far puntare gli ambienti di staging dei comparatori: ".cyan
|
132
|
+
menu.shell = true
|
133
|
+
envs.each do |key, env|
|
134
|
+
title = ""
|
135
|
+
env.each do |e|
|
136
|
+
title << "\n#{e.key.upcase}: #{e.value}"
|
137
|
+
end
|
138
|
+
msg = "#{@prima.reduce_size(title, 1000)}".light_blue
|
139
|
+
menu.choice(msg) { key }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
else
|
143
|
+
output "Nessun QA trovato".red
|
144
|
+
exit
|
145
|
+
end
|
146
|
+
|
147
|
+
change_hostname_priority(env_hash, "1")
|
148
|
+
|
149
|
+
dns_records.body[:result].each do |dns|
|
150
|
+
if dns[:name] =~ /^\w+\-\w+\-staging\.prima\.it$/
|
151
|
+
output "Changing #{dns[:name]} DNS record"
|
152
|
+
cloudflare.put("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records/#{dns[:id]}", {"type": "CNAME", "name": dns[:name], "content": get_alb_host(@stack_name_alb), "proxied": true, "ttl": 1})
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
output "Finito!".green
|
157
|
+
end
|
158
|
+
|
159
|
+
def change_hostname_priority(env_hash, hostname_pattern_priority)
|
160
|
+
cluster_stack_name = "ecs-cluster-#{env_hash}"
|
161
|
+
tags = get_stack_tags(cluster_stack_name).map do |tag|
|
162
|
+
if tag.key === "hostname_pattern_priority"
|
163
|
+
{
|
164
|
+
key: "hostname_pattern_priority",
|
165
|
+
value: hostname_pattern_priority
|
166
|
+
}
|
167
|
+
else
|
168
|
+
tag
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
stack_list.each do |stack|
|
173
|
+
if stack.stack_name.match(/#{env_hash}$/)
|
174
|
+
stack_name = stack.stack_name
|
175
|
+
begin
|
176
|
+
@cf.update_stack({
|
177
|
+
stack_name: stack_name,
|
178
|
+
tags: tags,
|
179
|
+
parameters: get_stack_parameters(stack_name),
|
180
|
+
template_body: get_stack_template(stack_name),
|
181
|
+
capabilities: ["CAPABILITY_IAM"]
|
182
|
+
})
|
183
|
+
rescue Aws::CloudFormation::Errors::ValidationError => e
|
184
|
+
raise e
|
185
|
+
else
|
186
|
+
output "L'update dello stack #{stack_name} è stato avviato".green
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
stack_list.each do |stack|
|
192
|
+
if stack.stack_name.match(/#{env_hash}$/)
|
193
|
+
wait_for_stack_ready(stack.stack_name) unless stack_ready?(stack.stack_name)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
stack_name_web = "ecs-task-web-#{env_hash}"
|
198
|
+
parameters = get_stack_parameters(stack_name_web).map do |param|
|
199
|
+
if param.parameter_key === "HostnamePatternPriority"
|
200
|
+
{
|
201
|
+
parameter_key: "HostnamePatternPriority",
|
202
|
+
parameter_value: hostname_pattern_priority
|
203
|
+
}
|
204
|
+
elsif param.parameter_key === "HostnamePatternAggregatorPriority"
|
205
|
+
{
|
206
|
+
parameter_key: "HostnamePatternAggregatorPriority",
|
207
|
+
parameter_value: (hostname_pattern_priority.to_i + 1).to_s
|
208
|
+
}
|
209
|
+
else
|
210
|
+
param
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
begin
|
215
|
+
@cf.update_stack({
|
216
|
+
stack_name: stack_name_web,
|
217
|
+
template_body: get_stack_template(stack_name_web),
|
218
|
+
parameters: parameters,
|
219
|
+
capabilities: ["CAPABILITY_IAM"]
|
220
|
+
})
|
221
|
+
rescue Aws::CloudFormation::Errors::ValidationError => e
|
222
|
+
raise e
|
223
|
+
else
|
224
|
+
output "L'update dello stack #{stack_name_web} è stato avviato".green
|
225
|
+
end
|
226
|
+
wait_for_stack_ready(stack_name_web) unless stack_ready?(stack_name_web)
|
227
|
+
end
|
228
|
+
|
229
|
+
def dns_to_staging
|
230
|
+
output "Recupero le informazioni relative al puntamento dei record DNS..."
|
231
|
+
cloudflare = Rubyflare.connect_with(@prima.config['cloudflare_email'], @prima.config['cloudflare_apikey'])
|
232
|
+
dns_records = cloudflare.get("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records", {"per_page": 100, "type": "CNAME", "content": get_alb_host(@stack_name_alb)})
|
233
|
+
dns_records.body[:result].each do |dns|
|
234
|
+
if dns[:name] =~ /^\w+\-\w+\-staging\.prima\.it$/
|
235
|
+
output "Changing #{dns[:name]} DNS record"
|
236
|
+
cloudflare.put("zones/1fb634f19c43dfb0162cc4cb91915da2/dns_records/#{dns[:id]}", {"type": "CNAME", "name": dns[:name], "content": "staging.prima.it", "proxied": true, "ttl": 1})
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
76
241
|
def finish_feature!
|
77
242
|
current_branch_name = @prima.twig.current_branch_name
|
78
243
|
stop_unless (current_branch_name =~ /^feature\//), "Non sei su un branch di feature, non posso mergiare nulla"
|
@@ -127,6 +292,15 @@ class Release
|
|
127
292
|
end
|
128
293
|
end
|
129
294
|
|
295
|
+
cluster_stack_name = "ecs-cluster-#{env_hash}"
|
296
|
+
aggregator_enabled = get_stack_tags(cluster_stack_name).detect do |tag|
|
297
|
+
tag.key === "hostname_pattern_priority" and tag.value === "1"
|
298
|
+
end.is_a?(Aws::CloudFormation::Types::Tag)
|
299
|
+
|
300
|
+
if aggregator_enabled
|
301
|
+
dns_to_staging()
|
302
|
+
end
|
303
|
+
|
130
304
|
# Se non ha finito di cancellare le altre non si puo' cancellare il cluster
|
131
305
|
output "Attendo 60 secondi per poter eliminare il cluster ECS"
|
132
306
|
sleep 60
|
@@ -163,7 +337,9 @@ class Release
|
|
163
337
|
end
|
164
338
|
|
165
339
|
envs[env_hash].each do |env|
|
166
|
-
|
340
|
+
unless ['hostname_pattern_priority'].include? env.key
|
341
|
+
@projects[env.key] = select_branch_to_deploy(env.key, env.value)
|
342
|
+
end
|
167
343
|
end
|
168
344
|
|
169
345
|
deploy_feature!
|
@@ -177,7 +353,7 @@ class Release
|
|
177
353
|
|
178
354
|
deploy_id = Digest::MD5.hexdigest(@projects["prima"][:name] + @projects["backoffice"][:name] + @projects["urania"][:name] + @projects["ermes"][:name] + @projects["bburago"][:name] + @projects["hal9000"][:name] + @projects["fidaty"][:name])
|
179
355
|
@dns_record_identifier = deploy_id
|
180
|
-
|
356
|
+
hostname_pattern_priority = hostname_pattern_priority()
|
181
357
|
tags = [
|
182
358
|
{
|
183
359
|
key: "prima",
|
@@ -206,10 +382,22 @@ class Release
|
|
206
382
|
{
|
207
383
|
key: "fidaty",
|
208
384
|
value: @projects["fidaty"][:name]
|
385
|
+
},
|
386
|
+
{
|
387
|
+
key: "hostname_pattern_priority",
|
388
|
+
value: hostname_pattern_priority
|
209
389
|
}
|
210
390
|
]
|
211
391
|
|
212
392
|
cluster_stack_name = "ecs-cluster-qa-#{deploy_id}"
|
393
|
+
|
394
|
+
if stack_exists?(cluster_stack_name)
|
395
|
+
tags = get_stack_tags(cluster_stack_name)
|
396
|
+
hostname_pattern_priority = tags.detect do |tag|
|
397
|
+
tag.key === "hostname_pattern_priority"
|
398
|
+
end.value
|
399
|
+
end
|
400
|
+
|
213
401
|
create_cluster_stack(cluster_stack_name, tags) unless stack_exists?(cluster_stack_name)
|
214
402
|
wait_for_stack_ready(cluster_stack_name) unless stack_ready?(cluster_stack_name)
|
215
403
|
|
@@ -282,11 +470,11 @@ class Release
|
|
282
470
|
},
|
283
471
|
{
|
284
472
|
parameter_key: "HostnamePatternPriority",
|
285
|
-
parameter_value: hostname_pattern_priority
|
473
|
+
parameter_value: hostname_pattern_priority
|
286
474
|
},
|
287
475
|
{
|
288
476
|
parameter_key: "HostnamePatternAggregatorPriority",
|
289
|
-
parameter_value: hostname_pattern_priority
|
477
|
+
parameter_value: (hostname_pattern_priority.to_i + 1).to_s
|
290
478
|
}
|
291
479
|
]
|
292
480
|
if stack_exists?(stack_name_web)
|
@@ -350,7 +538,7 @@ class Release
|
|
350
538
|
},
|
351
539
|
{
|
352
540
|
parameter_key: "HostnamePatternPriority",
|
353
|
-
parameter_value: hostname_pattern_priority
|
541
|
+
parameter_value: hostname_pattern_priority
|
354
542
|
}
|
355
543
|
]
|
356
544
|
if stack_exists?(stack_name_urania)
|
@@ -414,7 +602,7 @@ class Release
|
|
414
602
|
},
|
415
603
|
{
|
416
604
|
parameter_key: "HostnamePatternPriority",
|
417
|
-
parameter_value: hostname_pattern_priority
|
605
|
+
parameter_value: hostname_pattern_priority
|
418
606
|
}
|
419
607
|
]
|
420
608
|
if stack_exists?(stack_name_bburago)
|
@@ -455,7 +643,7 @@ class Release
|
|
455
643
|
},
|
456
644
|
{
|
457
645
|
parameter_key: "HostnamePatternPriority",
|
458
|
-
parameter_value: hostname_pattern_priority
|
646
|
+
parameter_value: hostname_pattern_priority
|
459
647
|
}
|
460
648
|
]
|
461
649
|
if stack_exists?(stack_name_hal9000)
|
@@ -496,7 +684,7 @@ class Release
|
|
496
684
|
},
|
497
685
|
{
|
498
686
|
parameter_key: "HostnamePatternPriority",
|
499
|
-
parameter_value: hostname_pattern_priority
|
687
|
+
parameter_value: hostname_pattern_priority
|
500
688
|
}
|
501
689
|
]
|
502
690
|
if stack_exists?(stack_name_fidaty)
|
@@ -535,7 +723,7 @@ class Release
|
|
535
723
|
},
|
536
724
|
{
|
537
725
|
parameter_key: "HostnamePatternPriority",
|
538
|
-
parameter_value: hostname_pattern_priority
|
726
|
+
parameter_value: (hostname_pattern_priority.to_i + 10).to_s
|
539
727
|
}
|
540
728
|
]
|
541
729
|
if stack_exists?(stack_name_backoffice)
|
@@ -1040,6 +1228,21 @@ class Release
|
|
1040
1228
|
output "\nStack #{stack_name} pronto!\n".green
|
1041
1229
|
end
|
1042
1230
|
|
1231
|
+
def get_stack_tags(name)
|
1232
|
+
resp = @cf.describe_stacks({stack_name: name})
|
1233
|
+
resp.stacks[0].tags
|
1234
|
+
end
|
1235
|
+
|
1236
|
+
def get_stack_parameters(name)
|
1237
|
+
resp = @cf.describe_stacks({stack_name: name})
|
1238
|
+
resp.stacks[0].parameters
|
1239
|
+
end
|
1240
|
+
|
1241
|
+
def get_stack_template(name)
|
1242
|
+
resp = @cf.get_template({stack_name: name})
|
1243
|
+
resp.template_body
|
1244
|
+
end
|
1245
|
+
|
1043
1246
|
def stack_list
|
1044
1247
|
resp = @cf.describe_stacks
|
1045
1248
|
stacks = resp.stacks
|
@@ -1249,7 +1452,7 @@ class Release
|
|
1249
1452
|
def is_branch_compatible_with_current_twig_version?(project)
|
1250
1453
|
case
|
1251
1454
|
when project == 'prima'
|
1252
|
-
File.readlines("app/cloudformation/tasks/web.yml").grep(/
|
1455
|
+
File.readlines("app/cloudformation/tasks/web.yml").grep(/HostnamePatternAggregatorPriority/).size > 0
|
1253
1456
|
when project == 'urania'
|
1254
1457
|
File.readlines("deploy/deploy").grep(/HOSTNAME_PATTERN/).size > 0
|
1255
1458
|
when project == 'backoffice'
|
data/lib/prima_twig.rb
CHANGED
@@ -5,6 +5,7 @@ require 'yaml'
|
|
5
5
|
require 'rugged'
|
6
6
|
require 'highline/import'
|
7
7
|
require 'aws-sdk'
|
8
|
+
require 'rubyflare'
|
8
9
|
|
9
10
|
class Prima
|
10
11
|
LABEL_REVIEW='review'
|
@@ -12,7 +13,7 @@ class Prima
|
|
12
13
|
LABEL_HOTFIX='hotfix'
|
13
14
|
LABEL_NEXT_RELEASE='next release'
|
14
15
|
LABEL_IN_STAGING='in staging'
|
15
|
-
CONFIG_KEYS=['github', 'mandrill', 'sparkpost']
|
16
|
+
CONFIG_KEYS=['github', 'mandrill', 'sparkpost', 'cloudflare_email', 'cloudflare_apikey']
|
16
17
|
attr_reader :gh, :twig, :config, :rugged, :aws
|
17
18
|
|
18
19
|
def initialize
|
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: 0.
|
4
|
+
version: 0.24.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matteo Giachino
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2017-06-
|
15
|
+
date: 2017-06-15 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: twig
|
@@ -140,6 +140,20 @@ dependencies:
|
|
140
140
|
- - "~>"
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: '2.6'
|
143
|
+
- !ruby/object:Gem::Dependency
|
144
|
+
name: rubyflare
|
145
|
+
requirement: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :runtime
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
143
157
|
description: Our tools to manage git and github
|
144
158
|
email: matteo.giachino@prima.it
|
145
159
|
executables:
|