prima-twig 0.45.31 → 0.46.0
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 +5 -5
- data/bin/twig-update-ami +22 -104
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b922b242a735dfdb1ee9b16c3ddc4c908d8f322b
|
4
|
+
data.tar.gz: e0e0198426a3dee834e77d3e98e7df84341d93dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d43d94a447b6b10b2f97837bbc21c0df335d2b173c5c49111cb87f9a661df2d5ee5bbd46615f88842a5d19821f502a742879331ad5d6de1ce4c13484e49cfab
|
7
|
+
data.tar.gz: 2055c6e4d5d1495aaa84331ab8c0130d01176eaceb87ea96a478425dc48b99ef2b7a265f0f9d0307451a607942235c8a7b72f005f13cfbcb852905d6c1a953c3
|
data/bin/twig-update-ami
CHANGED
@@ -30,6 +30,7 @@ class TwigUpdateAmi
|
|
30
30
|
update_instance_name(ami_id, ami_name, ami_description, ami_template)
|
31
31
|
output 'running packer update (this could take some time)'.light_green
|
32
32
|
new_ami_id = update_packer(ami_template)
|
33
|
+
# new_ami_id = 'ami-000e38f3a919824ae'
|
33
34
|
Dir.chdir '..'
|
34
35
|
stop_if(new_ami_id.to_s.empty?, 'Failed to generate AMI!'.red)
|
35
36
|
output "new ami id: #{new_ami_id}"
|
@@ -39,7 +40,7 @@ class TwigUpdateAmi
|
|
39
40
|
old_amis = update_ami_mappings(ami_mappings, ami_template, env, new_ami_id)
|
40
41
|
stop_if(old_amis.empty?, "No ami to update! No #{ami_template} in env #{env}, exiting".yellow)
|
41
42
|
|
42
|
-
output
|
43
|
+
output "retrieving stacks that uses old ami ids: #{old_amis}"
|
43
44
|
exports = list_exports()
|
44
45
|
stacks = get_stacks_from_exports(exports, old_amis)
|
45
46
|
stop_if(stacks.empty?, "No stack to update found! This means that ami-mapping file is not in sync, please check manually")
|
@@ -48,26 +49,34 @@ class TwigUpdateAmi
|
|
48
49
|
output "processing stack #{stack}"
|
49
50
|
if stack.include?('qa')
|
50
51
|
output "skipping stack #{stack} because is a qa"
|
51
|
-
next
|
52
|
+
next
|
52
53
|
elsif stack.include?('batch')
|
53
|
-
stack_parameters = update_stack_parameters(stack,
|
54
|
+
stack_parameters = update_stack_parameters(get_stack_parameters(stack),
|
54
55
|
[
|
55
56
|
{ parameter_key: 'AMIID', parameter_value: new_ami_id }
|
56
57
|
]
|
57
58
|
)
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
update_stack(stack, get_stack_template(stack), stack_parameters)
|
60
|
+
elsif stack.include?('fleet')
|
61
|
+
stack_tags = tags_to_hashes(get_stack_tags(stack))
|
62
|
+
stack_tags['TemplateVersion'] = stack_tags['TemplateVersion'].to_i + 1
|
63
|
+
|
64
|
+
stack_parameters = update_stack_parameters(get_stack_parameters(stack),
|
65
|
+
[
|
66
|
+
{ parameter_key: 'AMIID', parameter_value: new_ami_id },
|
67
|
+
{ parameter_key: 'DesiredCapacity', parameter_value: get_desired_capacity(stack).to_s },
|
68
|
+
{ parameter_key: 'TemplateVersion', parameter_value: stack_tags['TemplateVersion'].to_s }
|
69
|
+
]
|
70
|
+
)
|
71
|
+
update_stack(stack, get_stack_template(stack), stack_parameters, hashes_to_tags(stack_tags))
|
72
|
+
else # autoscaling group normali come ania-tools
|
73
|
+
stack_parameters = update_stack_parameters(get_stack_parameters(stack),
|
61
74
|
[
|
62
75
|
{ parameter_key: 'AMIID', parameter_value: new_ami_id },
|
63
76
|
{ parameter_key: 'DesiredCapacity', parameter_value: get_desired_capacity(stack).to_s }
|
64
77
|
]
|
65
78
|
)
|
66
|
-
|
67
|
-
update_spotfleet(stack, get_stack_template(stack), stack_parameters, tags_to_hashes(get_stack_tags(stack)))
|
68
|
-
else
|
69
|
-
update_stack(stack, get_stack_template(stack), stack_parameters)
|
70
|
-
end
|
79
|
+
update_stack(stack, get_stack_template(stack), stack_parameters)
|
71
80
|
end
|
72
81
|
end
|
73
82
|
|
@@ -111,8 +120,7 @@ class TwigUpdateAmi
|
|
111
120
|
old_values.uniq
|
112
121
|
end
|
113
122
|
|
114
|
-
def update_stack_parameters(
|
115
|
-
stack_parameters = get_stack_parameters(stack_name)
|
123
|
+
def update_stack_parameters(stack_parameters, new_parameters)
|
116
124
|
new_parameters.each do |new_param|
|
117
125
|
stack_parameters.reject{ |k| k["parameter_key"] == new_param["parameter_key"] }
|
118
126
|
stack_parameters.push(new_param)
|
@@ -135,13 +143,10 @@ class TwigUpdateAmi
|
|
135
143
|
def get_desired_capacity(stack_name)
|
136
144
|
stack_outputs = get_stack_outputs(stack_name)
|
137
145
|
stack_outputs.each do |out|
|
138
|
-
if out.export_name.include?('
|
146
|
+
if out.export_name.include?('EC2Fleet') or out.export_name.include?('AutoScalingGroup')
|
139
147
|
return get_autoscaling_capacity(out.output_value)
|
140
|
-
elsif out.export_name.include?('SpotFleet')
|
141
|
-
return get_spotfleet_capacity(out.output_value)
|
142
148
|
end
|
143
149
|
end
|
144
|
-
return nil
|
145
150
|
end
|
146
151
|
|
147
152
|
def update_packer(json_filename)
|
@@ -149,93 +154,6 @@ class TwigUpdateAmi
|
|
149
154
|
`grep 'artifact,0,id' build.log | cut -d, -f6 | cut -d: -f2`.sub(/\n/, '')
|
150
155
|
end
|
151
156
|
|
152
|
-
def update_body_and_tags(stack_body, stack_tags, old_amis = [])
|
153
|
-
if stack_tags['ArtemideTemplatePath'].include?('spotfleet')
|
154
|
-
if stack_tags['ArtemideTemplatePath'].include?('ci')
|
155
|
-
return
|
156
|
-
end
|
157
|
-
|
158
|
-
stack_tags['SpotFleetHandleVersion'] = stack_tags['SpotFleetHandleVersion'].to_i + 1
|
159
|
-
stack_body.gsub!(/InstanceReadyWaitHandleUpdate[0-9]*/, 'InstanceReadyWaitHandleUpdate' + stack_tags['SpotFleetHandleVersion'].to_s)
|
160
|
-
stack_body.gsub!(/InstanceReadyWaitConditionUpdate[0-9]*/, 'InstanceReadyWaitConditionUpdate' + stack_tags['SpotFleetHandleVersion'].to_s)
|
161
|
-
|
162
|
-
File.open stack_tags['ArtemideTemplatePath'], 'w' do |f|
|
163
|
-
f.write(stack_body)
|
164
|
-
@s3.put_object(body: stack_body, bucket: @s3_bucket, key: stack_tags['ArtemideTemplatePath'])
|
165
|
-
end
|
166
|
-
|
167
|
-
elsif stack_tags['ArtemideTemplatePath'].include?('batch')
|
168
|
-
stack_body.gsub!(/(\w+:\s+)!(\w+)/i, '\1QuaCeraUnPuntoEsclamativo\2')
|
169
|
-
stack_body_original = stack_body.clone
|
170
|
-
ce_name = stack_tags['ComputeEnvironment'].sub(/[0-9]+/, '')
|
171
|
-
new_ce_version = stack_tags['ComputeEnvironment'].sub(/[a-zA-Z]*/, '').to_i + 1
|
172
|
-
new_ce_name = ce_name + new_ce_version.to_s
|
173
|
-
stack_body.gsub!(/#{ce_name}[0-9]*/, new_ce_name)
|
174
|
-
stack_body_original.gsub!("QuaCeraUnPuntoEsclamativoRef AMIID", old_amis[0])
|
175
|
-
stack_tags['OldComputeEnvironment'] = stack_tags['ComputeEnvironment']
|
176
|
-
stack_tags['ComputeEnvironment'] = new_ce_name
|
177
|
-
|
178
|
-
File.open stack_tags['ArtemideTemplatePath'] + 'new', 'w' do |f|
|
179
|
-
f.write(stack_body)
|
180
|
-
end
|
181
|
-
|
182
|
-
yaml_stack_body = YAML.load(stack_body_original)
|
183
|
-
yaml_stack_body_new = YAML.load(stack_body)
|
184
|
-
yaml_stack_body_merged = (yaml_stack_body.deep_merge(yaml_stack_body_new)).to_yaml.gsub('QuaCeraUnPuntoEsclamativo', '!')
|
185
|
-
|
186
|
-
File.open(stack_tags['ArtemideTemplatePath'], 'w') do |file|
|
187
|
-
file.write yaml_stack_body_merged
|
188
|
-
@s3.put_object(body: yaml_stack_body_merged, bucket: @s3_bucket, key: stack_tags['ArtemideTemplatePath'])
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
def update_spotfleet(stack_name, stack_template, stack_parameters, stack_tags)
|
194
|
-
update_body_and_tags(stack_template, stack_tags)
|
195
|
-
update_stack_url(stack_name, "#{@templates_base_url}/#{@s3_bucket}/#{stack_tags['ArtemideTemplatePath']}", stack_parameters, hashes_to_tags(stack_tags))
|
196
|
-
end
|
197
|
-
|
198
|
-
def update_batch_compute_environment(stack_name, stack_body, stack_parameters, stack_tags, env, old_amis)
|
199
|
-
output "updating #{stack_name} to add a new compute environment"
|
200
|
-
update_body_and_tags(stack_body, stack_tags, old_amis)
|
201
|
-
output 'updating stack on cloudformation (step 1)'
|
202
|
-
update_stack_url(stack_name, "#{@templates_base_url}/#{@s3_bucket}/#{stack_tags['ArtemideTemplatePath']}", stack_parameters, hashes_to_tags(stack_tags))
|
203
|
-
wait_for_stack_ready(stack_name, ['CREATE_FAILED', 'ROLLBACK_IN_PROGRESS', 'ROLLBACK_FAILED', 'DELETE_IN_PROGRESS', 'DELETE_FAILED', 'DELETE_COMPLETE', 'UPDATE_ROLLBACK_FAILED', 'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS', 'UPDATE_ROLLBACK_COMPLETE', 'ROLLBACK_COMPLETE'])
|
204
|
-
|
205
|
-
output "retrieving the list of stacks that are currently using the stack #{stack_name}"
|
206
|
-
job_stacks = list_import_stacks(stack_tags['OldComputeEnvironment'] + "-" + env)
|
207
|
-
job_stacks.each do |job_stack_name|
|
208
|
-
output "updating the stack #{job_stack_name} to use to the new compute environment"
|
209
|
-
job_stack_parameters = update_stack_parameters(job_stack_name,
|
210
|
-
[
|
211
|
-
{
|
212
|
-
parameter_key: "ComputeEnvironmentExportName",
|
213
|
-
parameter_value: stack_tags['ComputeEnvironment']
|
214
|
-
}
|
215
|
-
]
|
216
|
-
)
|
217
|
-
update_stack(job_stack_name, get_stack_template(job_stack_name), job_stack_parameters)
|
218
|
-
end
|
219
|
-
job_stacks.each do |job_stack_name|
|
220
|
-
wait_for_stack_ready(job_stack_name, ['CREATE_FAILED', 'ROLLBACK_IN_PROGRESS', 'ROLLBACK_FAILED', 'DELETE_IN_PROGRESS', 'DELETE_FAILED', 'DELETE_COMPLETE', 'UPDATE_ROLLBACK_FAILED', 'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS', 'UPDATE_ROLLBACK_COMPLETE', 'ROLLBACK_COMPLETE'])
|
221
|
-
end
|
222
|
-
|
223
|
-
stack_body = File.read(stack_tags['ArtemideTemplatePath'] + 'new').gsub('QuaCeraUnPuntoEsclamativo', '!')
|
224
|
-
File.open stack_tags['ArtemideTemplatePath'], 'w' do |f|
|
225
|
-
f.write stack_body
|
226
|
-
@s3.put_object(body: stack_body, bucket: @s3_bucket, key: stack_tags['ArtemideTemplatePath'])
|
227
|
-
end
|
228
|
-
stack_tags.delete('OldComputeEnvironment')
|
229
|
-
|
230
|
-
output "updating stack #{stack_name} on cloudformation to remove the old compute environment"
|
231
|
-
update_stack_url(stack_name, "#{@templates_base_url}/#{@s3_bucket}/#{stack_tags['ArtemideTemplatePath']}", stack_parameters, hashes_to_tags(stack_tags))
|
232
|
-
wait_for_stack_ready(stack_name, ['CREATE_FAILED', 'ROLLBACK_IN_PROGRESS', 'ROLLBACK_FAILED', 'DELETE_IN_PROGRESS', 'DELETE_FAILED', 'DELETE_COMPLETE', 'UPDATE_ROLLBACK_FAILED', 'UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS', 'UPDATE_ROLLBACK_COMPLETE', 'ROLLBACK_COMPLETE'])
|
233
|
-
|
234
|
-
File.delete(stack_tags['ArtemideTemplatePath'] + 'new')
|
235
|
-
|
236
|
-
output "cloudformation stack update for #{stack_name} done!"
|
237
|
-
end
|
238
|
-
|
239
157
|
def help_content
|
240
158
|
<<-HELP
|
241
159
|
|
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.46.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matteo Giachino
|
@@ -214,7 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
214
|
- !ruby/object:Gem::Version
|
215
215
|
version: '0'
|
216
216
|
requirements: []
|
217
|
-
|
217
|
+
rubyforge_project:
|
218
|
+
rubygems_version: 2.5.2.3
|
218
219
|
signing_key:
|
219
220
|
specification_version: 4
|
220
221
|
summary: The Prima twig toolbelt
|