prima-twig 0.31.1 → 0.31.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/twig-update-ami +131 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6f7a49c077da9462b2283d2e4cd246c3d0af86e
|
4
|
+
data.tar.gz: 7ad946b20bc7c0b742ae6e99efa021686b49f047
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e53e291ecc59c2916c5935a46c9260f17f7fc10fdac268dac0376b1fd4cd320d7864533cb2ef94ae315784696ce9d26b883bed7eec5a02d5f4c6de73ea7246f1
|
7
|
+
data.tar.gz: b960e4d770f769191b3a4d8b9f5baf47db8c051929c2f387f4745e7993cff1385125fcc30ed01f80dc90a463f6546eb93c32806d91d15fca3949ec4451036d55
|
data/bin/twig-update-ami
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require_relative '../lib/prima_twig.rb'
|
5
|
+
require_relative '../lib/prima_aws_client.rb'
|
6
|
+
require 'launchy'
|
7
|
+
require 'json'
|
8
|
+
require 'aws-sdk'
|
9
|
+
|
10
|
+
#
|
11
|
+
class TwigUpdateAmi
|
12
|
+
include Command
|
13
|
+
include PrimaAwsClient
|
14
|
+
def initialize
|
15
|
+
@s3 = Aws::S3::Client.new
|
16
|
+
@s3_bucket = 'prima-deploy'
|
17
|
+
@instances = JSON.parse File.read('../twig-binaries/cloudformation.json')
|
18
|
+
end
|
19
|
+
|
20
|
+
def execute!(args)
|
21
|
+
update_amis args[0], args[1], args[2]
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def update_amis(ami_id, ami_name, ami_description)
|
27
|
+
@instances['instances'].each do |instance|
|
28
|
+
output 'updating instance definition'.light_green
|
29
|
+
Dir.chdir 'ami'
|
30
|
+
update_instance_name(ami_id, ami_name, ami_description, instance['json'])
|
31
|
+
output 'running packer update (this could take some time)'.light_green
|
32
|
+
new_ami_id = update_packer instance['json']
|
33
|
+
Dir.chdir '..'
|
34
|
+
output 'new ami id: ' + new_ami_id
|
35
|
+
instance['stacks'].each do |stack|
|
36
|
+
output 'updating ' + stack['yaml_filename'] + ' and copying onto s3'
|
37
|
+
update_yml_files(new_ami_id, stack['yaml_filename'])
|
38
|
+
copy_yml_files_to_s3(stack['yaml_filename'], stack['s3_key'])
|
39
|
+
output 'updating stack on cloudformation'
|
40
|
+
update_stack_url(stack['stack_name'], stack['template_url'], stack['parameters']) if stack['stack_name']
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def update_instance_name(ami_id, ami_name, ami_description, ecs_json_path)
|
46
|
+
ecs_json = JSON.parse File.read(ecs_json_path)
|
47
|
+
|
48
|
+
ecs_json['builders'][0]['source_ami'] = ami_id
|
49
|
+
ecs_json['builders'][0]['ami_name'] = ami_name
|
50
|
+
ecs_json['builders'][0]['ami_description'] = ami_description
|
51
|
+
|
52
|
+
File.open ecs_json_path, 'w' do |f|
|
53
|
+
f.write(JSON.pretty_generate(ecs_json))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def update_packer(json_filename)
|
58
|
+
`packer build -machine-readable ./#{json_filename} | tee build.log`
|
59
|
+
`grep 'artifact,0,id' build.log | cut -d, -f6 | cut -d: -f2`.sub(/\n/, '')
|
60
|
+
end
|
61
|
+
|
62
|
+
def update_yml_files(ami_id, yaml_filename)
|
63
|
+
yaml_file = File.read yaml_filename
|
64
|
+
|
65
|
+
yaml_file.sub!(/ami-[0-9a-z]{8}/, ami_id)
|
66
|
+
|
67
|
+
File.open yaml_filename, 'w' do |f|
|
68
|
+
f.write yaml_file
|
69
|
+
end
|
70
|
+
|
71
|
+
if yaml_filename.include? 'spotfleet' do
|
72
|
+
old_handle = (File.read yaml_filename)[/InstanceReadyWaitHandleUpdate[0-9]+/]
|
73
|
+
handle_version = old_handle.sub('InstanceReadyWaitHandleUpdate', '').to_i + 1
|
74
|
+
|
75
|
+
old_condition = (File.read yaml_filename)[/InstanceReadyWaitConditionUpdate[0-9]+/]
|
76
|
+
condition_version = old_condition.sub('InstanceReadyWaitConditionUpdate', '').to_i + 1
|
77
|
+
|
78
|
+
file_content = File.read yaml_filename
|
79
|
+
file_content.gsub!(old_handle, 'InstanceReadyWaitHandleUpdate' + handle_version.to_s)
|
80
|
+
file_content.gsub!(old_condition, 'InstanceReadyWaitConditionUpdate' + condition_version.to_s)
|
81
|
+
|
82
|
+
File.open yaml_filename, 'w' do |f|
|
83
|
+
f.write file_content
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def copy_yml_files_to_s3(source, s3_key)
|
90
|
+
body = File.read source
|
91
|
+
@s3.put_object(
|
92
|
+
body: body,
|
93
|
+
bucket: @s3_bucket,
|
94
|
+
key: s3_key
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
def help_content
|
99
|
+
<<-HELP
|
100
|
+
|
101
|
+
twig-update-ami
|
102
|
+
===========
|
103
|
+
|
104
|
+
Updates ami version and applies it to stacks on cloudformation
|
105
|
+
|
106
|
+
Synopsis
|
107
|
+
--------
|
108
|
+
|
109
|
+
twig-update-ami
|
110
|
+
|
111
|
+
Description
|
112
|
+
-----------
|
113
|
+
|
114
|
+
from artemide main folder run
|
115
|
+
`../twig-binaries/bin/twig-update-ami ${AMI_ID} ${AMI_NAME} ${AMI_DESCRIPTION}`
|
116
|
+
|
117
|
+
Subcommand for Twig: <http://rondevera.github.io/twig/>
|
118
|
+
Author: Eugenio Laghi <https://github.com/eugeniolaghi>
|
119
|
+
|
120
|
+
HELP
|
121
|
+
end
|
122
|
+
|
123
|
+
args = ARGV.dup
|
124
|
+
|
125
|
+
if args.include?('--help')
|
126
|
+
puts help_content
|
127
|
+
exit
|
128
|
+
end
|
129
|
+
|
130
|
+
TwigUpdateAmi.new.execute!(args)
|
131
|
+
end
|
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.31.
|
4
|
+
version: 0.31.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matteo Giachino
|
@@ -179,6 +179,7 @@ executables:
|
|
179
179
|
- twig-open-pr
|
180
180
|
- twig-pick-issue
|
181
181
|
- twig-review
|
182
|
+
- twig-update-ami
|
182
183
|
extensions: []
|
183
184
|
extra_rdoc_files: []
|
184
185
|
files:
|
@@ -189,6 +190,7 @@ files:
|
|
189
190
|
- bin/twig-open-pr
|
190
191
|
- bin/twig-pick-issue
|
191
192
|
- bin/twig-review
|
193
|
+
- bin/twig-update-ami
|
192
194
|
- lib/command.rb
|
193
195
|
- lib/prima_aws_client.rb
|
194
196
|
- lib/prima_twig.rb
|