prima-twig 0.34.2 → 0.34.3
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-deploy +1 -103
- data/lib/prima_aws_client.rb +122 -49
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ed959d3bfd3095221f0b4604ef99aa4d693b072c
|
|
4
|
+
data.tar.gz: 8f3dc8f766d9be743bfd1542a24a50198b43f547
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a6d2cf4c82c3c8b2ce2d96c2bd79badaff4aa40c0b6251bbbe39d951404e863b007107c395a4e62964987bcdf50aa7064746471a4e20d75a670280ce3bf66dca
|
|
7
|
+
data.tar.gz: 7c511d17627c06f05ad3c9d655f90be6449d15fedbbc98d34eb0009107ccd18990cf54b0a429353ea43b4f5f739d3f0075a1f001e68849f8030c8c248344d2e3
|
data/bin/twig-deploy
CHANGED
|
@@ -12,7 +12,6 @@ require 'erb'
|
|
|
12
12
|
require 'base64'
|
|
13
13
|
require 'rubyflare'
|
|
14
14
|
require 'pp'
|
|
15
|
-
require 'pry'
|
|
16
15
|
|
|
17
16
|
def help_content
|
|
18
17
|
<<-HELP
|
|
@@ -65,8 +64,7 @@ class Review
|
|
|
65
64
|
when "parameters"
|
|
66
65
|
reload_parameters!
|
|
67
66
|
else
|
|
68
|
-
|
|
69
|
-
# stop_if true, [:wrong_args, ['parameters']]
|
|
67
|
+
stop_if true, [:wrong_args, ['parameters']]
|
|
70
68
|
end
|
|
71
69
|
else
|
|
72
70
|
deploy_revision!
|
|
@@ -146,70 +144,6 @@ class Review
|
|
|
146
144
|
exec_step "terminal-notifier -message 'Deploy terminato'" if which 'terminal-notifier'
|
|
147
145
|
end
|
|
148
146
|
|
|
149
|
-
def deploy_current!(project_name)
|
|
150
|
-
binding.pry
|
|
151
|
-
stop_if @prima.head_detached?, :detached_head
|
|
152
|
-
stop_if @prima.repo_has_modified_files?, "Non posso deployare con file non commitati"
|
|
153
|
-
|
|
154
|
-
output "Recupero degli artifacts in corso, attendi qualche secondo...".yellow
|
|
155
|
-
artifacts = get_artifacts(project_name)[0..49]
|
|
156
|
-
|
|
157
|
-
artifact_rev = choose do |menu|
|
|
158
|
-
menu.prompt = 'Scegli la release da deployare: '.cyan
|
|
159
|
-
menu.shell = true
|
|
160
|
-
|
|
161
|
-
artifacts.each do |v|
|
|
162
|
-
title = @prima.reduce_size(v[:branch], 100)
|
|
163
|
-
commit_msg = @prima.reduce_size(v[:commit_msg], 250)
|
|
164
|
-
msg = "#{title} #{v[:created_at].strftime('%d/%m/%Y %H:%M:%S')} #{v[:rev]} #{commit_msg}".light_blue
|
|
165
|
-
menu.choice(msg) {v[:rev]}
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
user = `git config user.name`.delete "\n"
|
|
170
|
-
artifact = artifacts.select {|v| v[:rev] == artifact_rev}.first
|
|
171
|
-
|
|
172
|
-
do_deploy! artifact_rev, project_name, false
|
|
173
|
-
|
|
174
|
-
mail = Mail.new do
|
|
175
|
-
from 'deploy@prima.it'
|
|
176
|
-
to 'deploy@prima.it'
|
|
177
|
-
subject "#{user} ha effettuato il deploy della revision #{artifact[:rev]}"
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
commit_msg = clean_commit_message(artifact[:commit_msg])
|
|
181
|
-
|
|
182
|
-
body = "## Deploy in produzione effettuato con successo\n\n"
|
|
183
|
-
body << "Data: #{Time.now.strftime('%d/%m/%Y %H:%M:%S')}\n\n"
|
|
184
|
-
body << "Utente: #{user}\n\n"
|
|
185
|
-
body << "Revision: [#{artifact[:rev]}](https://github.com/primait/#{project_name}/commit/#{artifact[:rev]}) del #{artifact[:created_at].strftime('%d/%m/%Y %H:%M:%S')}\n\n"
|
|
186
|
-
body << "Branch: [#{artifact[:branch]}](https://github.com/primait/#{project_name}/tree/#{artifact[:branch]})\n\n"
|
|
187
|
-
body << "Commit: #{commit_msg.gsub(/_/, '\_')}\n\n"
|
|
188
|
-
|
|
189
|
-
htmlBody = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new).render body
|
|
190
|
-
|
|
191
|
-
html_part = Mail::Part.new do
|
|
192
|
-
content_type 'text/html; charset=UTF-8'
|
|
193
|
-
body htmlBody
|
|
194
|
-
end
|
|
195
|
-
text_part = Mail::Part.new do
|
|
196
|
-
body htmlBody.gsub(/<br\s?\/?>/, "\r\n").gsub(/<\/?[^>]*>/, '')
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
mail.html_part = html_part
|
|
200
|
-
mail.text_part = text_part
|
|
201
|
-
|
|
202
|
-
opts = {address: 'email-smtp.eu-west-1.amazonaws.com', port: '587'}
|
|
203
|
-
opts[:user_name] = @prima.config['aws_username']
|
|
204
|
-
opts[:password] = @prima.config['aws_password']
|
|
205
|
-
|
|
206
|
-
mail.delivery_method(:smtp, opts)
|
|
207
|
-
mail.deliver
|
|
208
|
-
|
|
209
|
-
exec_step "git checkout master"
|
|
210
|
-
exec_step "terminal-notifier -message 'Deploy terminato'" if which 'terminal-notifier'
|
|
211
|
-
end
|
|
212
|
-
|
|
213
147
|
def reload_parameters!
|
|
214
148
|
artifact_rev = ''
|
|
215
149
|
resp = @cf.describe_stacks({
|
|
@@ -250,27 +184,6 @@ class Review
|
|
|
250
184
|
wait_for_stack_ready(stack_name_cron) unless stack_ready?(stack_name_cron)
|
|
251
185
|
end
|
|
252
186
|
|
|
253
|
-
def do_deploy!(artifact_rev, project_name, reload_parameters=false)
|
|
254
|
-
binding.pry
|
|
255
|
-
deploy_command = "deploy/set_artifact_version #{artifact_rev}"
|
|
256
|
-
|
|
257
|
-
output "Il comando per il deploy sara': #{deploy_command}".yellow
|
|
258
|
-
confirm_message = "Sei sicuro di voler effettuare il deploy in produzione?"
|
|
259
|
-
|
|
260
|
-
exit unless @prima.yesno confirm_message.blue
|
|
261
|
-
|
|
262
|
-
# exec_step "git fetch"
|
|
263
|
-
# exec_step "git checkout #{artifact_rev}"
|
|
264
|
-
exec_step deploy_command
|
|
265
|
-
|
|
266
|
-
# stack_name_web = 'ecs-task-web-production'
|
|
267
|
-
# stack_name_consumer = 'ecs-task-consumer-production'
|
|
268
|
-
# stack_name_cron = 'ecs-task-consumer-production'
|
|
269
|
-
# wait_for_stack_ready(stack_name_web) unless stack_ready?(stack_name_web)
|
|
270
|
-
# wait_for_stack_ready(stack_name_consumer) unless stack_ready?(stack_name_consumer)
|
|
271
|
-
# wait_for_stack_ready(stack_name_cron) unless stack_ready?(stack_name_cron)
|
|
272
|
-
end
|
|
273
|
-
|
|
274
187
|
def get_artifacts
|
|
275
188
|
artifacts = []
|
|
276
189
|
resp = @s3.list_objects(bucket: @s3_bucket, prefix: 'prima')
|
|
@@ -286,21 +199,6 @@ class Review
|
|
|
286
199
|
artifacts.sort_by { |v| v[:created_at] }.reverse
|
|
287
200
|
end
|
|
288
201
|
|
|
289
|
-
def get_artifacts(project_name)
|
|
290
|
-
artifacts = []
|
|
291
|
-
resp = @s3.list_objects(bucket: @s3_bucket, prefix: "microservices/#{project_name}")
|
|
292
|
-
resp.contents.each do |s3_object|
|
|
293
|
-
rev = s3_object.key.match("#{project_name}\\/\\d+\\.\\d+\\.\\d+.tar.gz$").to_s
|
|
294
|
-
if rev
|
|
295
|
-
object = @s3.head_object(bucket: @s3_bucket, key: s3_object.key)
|
|
296
|
-
commit_msg = ''
|
|
297
|
-
commit_msg = Base64.decode64(object.metadata['commit_msg']).strip if object.metadata.has_key? 'commit_msg'
|
|
298
|
-
artifacts << {rev: rev, created_at: object.last_modified, branch: object.metadata['branch'], commit_msg: commit_msg } if object.metadata.has_key? 'branch'
|
|
299
|
-
end
|
|
300
|
-
end
|
|
301
|
-
artifacts.sort_by { |v| v[:created_at] }.reverse
|
|
302
|
-
end
|
|
303
|
-
|
|
304
202
|
def launch_paparatzinger(job_name)
|
|
305
203
|
@s3.get_object(
|
|
306
204
|
response_target: '/tmp/paparatzinger_twig.yml',
|
data/lib/prima_aws_client.rb
CHANGED
|
@@ -24,7 +24,13 @@ module PrimaAwsClient
|
|
|
24
24
|
loop do
|
|
25
25
|
print '.'.yellow; STDOUT.flush
|
|
26
26
|
options = next_token != '' ? { next_token: next_token } : {}
|
|
27
|
-
|
|
27
|
+
begin
|
|
28
|
+
resp = cf_client.describe_stacks(options)
|
|
29
|
+
rescue Aws::CloudFormation::Errors::Throttling => e
|
|
30
|
+
output 'Throttling, retrying in 15 seconds'.red
|
|
31
|
+
sleep 15
|
|
32
|
+
resp = cf_client.describe_stacks(options)
|
|
33
|
+
end
|
|
28
34
|
stacks += resp.stacks
|
|
29
35
|
break unless resp.next_token
|
|
30
36
|
next_token = resp.next_token
|
|
@@ -35,57 +41,89 @@ module PrimaAwsClient
|
|
|
35
41
|
end
|
|
36
42
|
|
|
37
43
|
def create_stack(stack_name, stack_body, parameters = [], tags = [])
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
begin
|
|
45
|
+
cf_client.create_stack(
|
|
46
|
+
stack_name: stack_name,
|
|
47
|
+
template_body: stack_body,
|
|
48
|
+
parameters: parameters,
|
|
49
|
+
tags: tags,
|
|
50
|
+
capabilities: ['CAPABILITY_IAM'],
|
|
51
|
+
on_failure: 'ROLLBACK'
|
|
52
|
+
)
|
|
53
|
+
rescue Aws::CloudFormation::Errors::Throttling => e
|
|
54
|
+
output 'Throttling, retrying in 15 seconds'.red
|
|
55
|
+
sleep 15
|
|
56
|
+
create_stack(stack_name, stack_body, parameters = [], tags = [])
|
|
57
|
+
else
|
|
58
|
+
output "La creazione dello stack #{stack_name} è stata avviata".green
|
|
59
|
+
end
|
|
47
60
|
end
|
|
48
61
|
|
|
49
62
|
def update_stack(stack_name, template_body, parameters = [], tags = [])
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
begin
|
|
64
|
+
cf_client.update_stack(
|
|
65
|
+
stack_name: stack_name,
|
|
66
|
+
template_body: template_body,
|
|
67
|
+
parameters: parameters,
|
|
68
|
+
tags: tags,
|
|
69
|
+
capabilities: ['CAPABILITY_IAM']
|
|
70
|
+
)
|
|
71
|
+
rescue Aws::CloudFormation::Errors::Throttling => e
|
|
72
|
+
output 'Throttling, retrying in 15 seconds'.red
|
|
73
|
+
sleep 15
|
|
74
|
+
update_stack(stack_name, template_body, parameters = [], tags = [])
|
|
75
|
+
rescue Aws::CloudFormation::Errors::ValidationError => e
|
|
76
|
+
raise e
|
|
77
|
+
else
|
|
78
|
+
output "L'update dello stack #{stack_name} è stato avviato".green
|
|
79
|
+
end
|
|
61
80
|
end
|
|
62
81
|
|
|
63
82
|
def update_stack_url(stack_name, template_url, parameters = [], tags = [])
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
begin
|
|
84
|
+
cf_client.update_stack(
|
|
85
|
+
stack_name: stack_name,
|
|
86
|
+
template_url: template_url,
|
|
87
|
+
parameters: parameters,
|
|
88
|
+
tags: tags,
|
|
89
|
+
capabilities: ['CAPABILITY_IAM']
|
|
90
|
+
)
|
|
91
|
+
rescue Aws::CloudFormation::Errors::Throttling => e
|
|
92
|
+
output 'Throttling, retrying in 15 seconds'.red
|
|
93
|
+
sleep 15
|
|
94
|
+
update_stack_url(stack_name, template_url, parameters = [], tags = [])
|
|
95
|
+
rescue Aws::CloudFormation::Errors::ValidationError => e
|
|
96
|
+
raise e
|
|
97
|
+
else
|
|
98
|
+
output "L'update dello stack #{stack_name} è stato avviato".green
|
|
99
|
+
end
|
|
75
100
|
end
|
|
76
101
|
|
|
77
102
|
def stack_exists?(stack_name)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
103
|
+
begin
|
|
104
|
+
cf_client.describe_stacks(stack_name: stack_name)
|
|
105
|
+
rescue Aws::CloudFormation::Errors::Throttling => e
|
|
106
|
+
output 'Throttling, retrying in 15 seconds'.red
|
|
107
|
+
sleep 15
|
|
108
|
+
stack_exists?(stack_name)
|
|
109
|
+
rescue Aws::CloudFormation::Errors::ValidationError => e
|
|
110
|
+
return false if e.message.include? 'does not exist'
|
|
111
|
+
raise e
|
|
112
|
+
else
|
|
113
|
+
true
|
|
114
|
+
end
|
|
84
115
|
end
|
|
85
116
|
|
|
86
117
|
def delete_stack(stack_name)
|
|
87
|
-
|
|
88
|
-
|
|
118
|
+
begin
|
|
119
|
+
cf_client.delete_stack(stack_name: stack_name)
|
|
120
|
+
rescue Aws::CloudFormation::Errors::Throttling => e
|
|
121
|
+
output 'Throttling, retrying in 15 seconds'.red
|
|
122
|
+
sleep 15
|
|
123
|
+
delete_stack(stack_name)
|
|
124
|
+
else
|
|
125
|
+
output "Stack #{stack_name} spenta con successo\n".green
|
|
126
|
+
end
|
|
89
127
|
end
|
|
90
128
|
|
|
91
129
|
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'])
|
|
@@ -106,23 +144,52 @@ module PrimaAwsClient
|
|
|
106
144
|
end
|
|
107
145
|
|
|
108
146
|
def get_stack_tags(name)
|
|
109
|
-
|
|
110
|
-
|
|
147
|
+
begin
|
|
148
|
+
resp = cf_client.describe_stacks(stack_name: name)
|
|
149
|
+
rescue Aws::CloudFormation::Errors::Throttling => e
|
|
150
|
+
output 'Throttling, retrying in 15 seconds'.red
|
|
151
|
+
sleep 15
|
|
152
|
+
get_stack_tags(name)
|
|
153
|
+
else
|
|
154
|
+
resp.stacks[0].tags
|
|
155
|
+
end
|
|
111
156
|
end
|
|
112
157
|
|
|
113
158
|
def get_stack_parameters(name)
|
|
114
|
-
|
|
115
|
-
|
|
159
|
+
begin
|
|
160
|
+
resp = cf_client.describe_stacks(stack_name: name)
|
|
161
|
+
rescue Aws::CloudFormation::Errors::Throttling => e
|
|
162
|
+
output 'Throttling, retrying in 15 seconds'.red
|
|
163
|
+
sleep 15
|
|
164
|
+
get_stack_parameters(name)
|
|
165
|
+
else
|
|
166
|
+
resp.stacks[0].parameters
|
|
167
|
+
end
|
|
116
168
|
end
|
|
117
169
|
|
|
118
170
|
def get_stack_outputs(name)
|
|
119
|
-
|
|
120
|
-
|
|
171
|
+
begin
|
|
172
|
+
resp = cf_client.describe_stacks(stack_name: name)
|
|
173
|
+
rescue Aws::CloudFormation::Errors::Throttling => e
|
|
174
|
+
output 'Throttling, retrying in 15 seconds'.red
|
|
175
|
+
sleep 15
|
|
176
|
+
get_stack_outputs(name)
|
|
177
|
+
else
|
|
178
|
+
resp.stacks[0].outputs
|
|
179
|
+
end
|
|
121
180
|
end
|
|
122
181
|
|
|
123
182
|
def get_stack_template(name)
|
|
124
|
-
|
|
125
|
-
|
|
183
|
+
begin
|
|
184
|
+
resp = cf_client.get_template(stack_name: name)
|
|
185
|
+
rescue Aws::CloudFormation::Errors::Throttling => e
|
|
186
|
+
output 'Throttling, retrying in 15 seconds'.red
|
|
187
|
+
sleep 15
|
|
188
|
+
get_stack_template(name)
|
|
189
|
+
else
|
|
190
|
+
resp.template_body
|
|
191
|
+
end
|
|
192
|
+
|
|
126
193
|
end
|
|
127
194
|
|
|
128
195
|
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'])
|
|
@@ -165,7 +232,13 @@ module PrimaAwsClient
|
|
|
165
232
|
loop do
|
|
166
233
|
print '.'.yellow; STDOUT.flush
|
|
167
234
|
options = next_token != '' ? { export_name: export_name, next_token: next_token } : {export_name: export_name}
|
|
168
|
-
|
|
235
|
+
begin
|
|
236
|
+
resp = cf_client.list_imports(options)
|
|
237
|
+
rescue Aws::CloudFormation::Errors::Throttling => e
|
|
238
|
+
output 'Throttling, retrying in 15 seconds'.red
|
|
239
|
+
sleep 15
|
|
240
|
+
resp = cf_client.list_imports(options)
|
|
241
|
+
end
|
|
169
242
|
stacks += resp.imports
|
|
170
243
|
break unless resp.next_token
|
|
171
244
|
next_token = resp.next_token
|
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.34.
|
|
4
|
+
version: 0.34.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matteo Giachino
|
|
@@ -13,7 +13,7 @@ authors:
|
|
|
13
13
|
autorequire:
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
|
-
date: 2018-04-
|
|
16
|
+
date: 2018-04-13 00:00:00.000000000 Z
|
|
17
17
|
dependencies:
|
|
18
18
|
- !ruby/object:Gem::Dependency
|
|
19
19
|
name: aws-sdk
|