prima-twig 0.20.0 → 0.54.20

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.
@@ -0,0 +1,197 @@
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
+ class TwigUpdateAmi
11
+ include Command
12
+ include PrimaAwsClient
13
+ def initialize
14
+ output 'Controllo se ci sono aggiornamenti da fare...'
15
+ exec "gem update prima-twig && twig update-ami #{ARGV.join ' '}" unless `gem outdated`.lines.grep(/^prima-twig \(.*\)/).empty?
16
+ @s3 = Aws::S3::Client.new
17
+ @s3_bucket = 'prima-deploy'
18
+ @templates_base_url = "https://s3-eu-west-1.amazonaws.com"
19
+ end
20
+
21
+ def execute!(args)
22
+ update_amis(args[0], args[1], args[2], args[3], args[4])
23
+ end
24
+
25
+ private
26
+
27
+ def update_amis(ami_template, ami_id, ami_name, ami_description, env)
28
+ output "updating instance definition #{ami_template}".light_green
29
+ Dir.chdir 'ami'
30
+ update_instance_name(ami_id, ami_name, ami_description, ami_template)
31
+ output 'running packer update (this could take some time)'.light_green
32
+ new_ami_id = update_packer(ami_template)
33
+ # new_ami_id = 'ami-000e38f3a919824ae'
34
+ Dir.chdir '..'
35
+ stop_if(new_ami_id.to_s.empty?, 'Failed to generate AMI!'.red)
36
+ output "new ami id: #{new_ami_id}"
37
+
38
+ output 'searching for ami to update...'
39
+ ami_mappings = JSON.parse(@s3.get_object(bucket: @s3_bucket, key: "ami/ami-mappings.json")["body"].read())
40
+ old_amis = update_ami_mappings(ami_mappings, ami_template, env, new_ami_id)
41
+ stop_if(old_amis.empty?, "No ami to update! No #{ami_template} in env #{env}, exiting".yellow)
42
+
43
+ output "retrieving stacks that uses old ami ids: #{old_amis}"
44
+ exports = list_exports()
45
+ stacks = get_stacks_from_exports(exports, old_amis)
46
+ stop_if(stacks.empty?, "No stack to update found! This means that ami-mapping file is not in sync, please check manually")
47
+
48
+ stacks.each do |stack|
49
+ output "processing stack #{stack}"
50
+ if stack.include?('qa')
51
+ output "skipping stack #{stack} because is a qa"
52
+ next
53
+ elsif stack.include?('batch')
54
+ stack_parameters = update_stack_parameters(get_stack_parameters(stack),
55
+ [
56
+ { parameter_key: 'AMIID', parameter_value: new_ami_id }
57
+ ]
58
+ )
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),
74
+ [
75
+ { parameter_key: 'AMIID', parameter_value: new_ami_id },
76
+ { parameter_key: 'DesiredCapacity', parameter_value: get_desired_capacity(stack).to_s }
77
+ ]
78
+ )
79
+ update_stack(stack, get_stack_template(stack), stack_parameters)
80
+ end
81
+ end
82
+
83
+ stacks.each do |stack|
84
+ if stack.include?('qa')
85
+ next
86
+ end
87
+ wait_for_stack_ready(stack, ['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'])
88
+ end
89
+
90
+ output 'writing new ami mapping'
91
+ File.open("ami/ami-mappings.json", 'w+') do |f|
92
+ mapping_file = JSON.pretty_generate(ami_mappings)
93
+ f.write(mapping_file)
94
+ @s3.put_object(bucket: @s3_bucket, key: "ami/ami-mappings.json", body: mapping_file)
95
+ end
96
+
97
+ output 'Update finished! ( ͡° ͜ʖ ͡°)'
98
+ end
99
+
100
+ def get_stacks_from_exports(exports, old_amis)
101
+ stacks = []
102
+ old_amis.each do |old_ami|
103
+ exports.each do |export|
104
+ if export.value.eql?(old_ami)
105
+ stacks.insert(0,export.exporting_stack_id)
106
+ end
107
+ end
108
+ end
109
+ stacks
110
+ end
111
+
112
+ def update_ami_mappings(mappings, ami_template, env, new_ami_id)
113
+ old_values = []
114
+ mappings.each do |item|
115
+ if item['ami_template'].eql?(ami_template) and item['env'].eql?(env)
116
+ old_values.insert(0,item['ami_id'])
117
+ item['ami_id'] = new_ami_id
118
+ end
119
+ end
120
+ old_values.uniq
121
+ end
122
+
123
+ def update_stack_parameters(stack_parameters, new_parameters)
124
+ new_parameters.each do |new_param|
125
+ stack_parameters.reject{ |k| k["parameter_key"] == new_param["parameter_key"] }
126
+ stack_parameters.push(new_param)
127
+ end
128
+ stack_parameters
129
+ end
130
+
131
+ def update_instance_name(ami_id, ami_name, ami_description, ecs_json_path)
132
+ ecs_json = JSON.parse File.read(ecs_json_path)
133
+
134
+ ecs_json['builders'][0]['source_ami'] = ami_id
135
+ ecs_json['builders'][0]['ami_name'] = ami_name
136
+ ecs_json['builders'][0]['ami_description'] = ami_description
137
+
138
+ File.open ecs_json_path, 'w' do |f|
139
+ f.write(JSON.pretty_generate(ecs_json))
140
+ end
141
+ end
142
+
143
+ def get_desired_capacity(stack_name)
144
+ stack_outputs = get_stack_outputs(stack_name)
145
+ stack_outputs.each do |out|
146
+ if out.export_name.include?('EC2Fleet') or out.export_name.include?('AutoScalingGroup')
147
+ return get_autoscaling_capacity(out.output_value)
148
+ end
149
+ end
150
+ end
151
+
152
+ def update_packer(json_filename)
153
+ execute_command "packer build -var datadog_apikey=`biscuit get -f ../configs/secrets/common.yml common_production_apikey_datadog` -var github_token=`biscuit get -f ../configs/secrets/common.yml common_private_repo_github_token` -machine-readable ./#{json_filename} | tee build.log"
154
+ `grep 'artifact,0,id' build.log | cut -d, -f6 | cut -d: -f2`.sub(/\n/, '')
155
+ end
156
+
157
+ def help_content
158
+ <<-HELP
159
+
160
+ twig-update-ami
161
+ ===========
162
+
163
+ Updates ami version and applies it to stacks on cloudformation
164
+
165
+ Synopsis
166
+ --------
167
+
168
+ twig-update-ami
169
+
170
+ Description
171
+ -----------
172
+
173
+ from artemide main folder run
174
+ `twig-update-ami ${AMI_TEMPLATE} ${AMI_ID} ${AMI_NAME} ${AMI_DESCRIPTION} ${ENV}`
175
+
176
+ Subcommand for Twig: <http://rondevera.github.io/twig/>
177
+ Author: Eugenio Laghi <https://github.com/eugeniolaghi>
178
+
179
+ HELP
180
+ end
181
+
182
+ class ::Hash
183
+ def deep_merge(second)
184
+ merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : Array === v1 && Array === v2 ? v1 | v2 : [:undefined, nil, :nil].include?(v2) ? v1 : v2 }
185
+ self.merge(second.to_h, &merger)
186
+ end
187
+ end
188
+
189
+ args = ARGV.dup
190
+
191
+ if args.include?('--help')
192
+ puts help_content
193
+ exit
194
+ end
195
+
196
+ TwigUpdateAmi.new.execute!(args)
197
+ end
data/lib/command.rb CHANGED
@@ -1,60 +1,73 @@
1
1
  require 'colorize'
2
+ require 'English'
2
3
  require 'optparse'
3
4
 
4
- module Command
5
- def exec_step command, output = nil
5
+ module Command
6
+ # executes command and exits if status != 0
7
+ def exec_step(command, output = nil)
6
8
  if output
7
9
  puts output
8
10
  else
9
- puts "exec > ".green + "#{command}".yellow
11
+ puts 'exec > '.green + command.to_s.yellow
10
12
  end
11
13
  `#{command}`
12
- exit($?.exitstatus) unless 0 === $?.exitstatus
14
+ exit($CHILD_STATUS.exitstatus) unless $CHILD_STATUS.exitstatus.zero?
13
15
  end
14
16
 
15
- def output msg
16
- puts "twig binaries > ".black + msg
17
+ def output(msg)
18
+ puts 'twig binaries > '.black + msg
17
19
  end
18
20
 
19
- def stop_if check, msg
21
+ def stop_if(check, msg, command = '')
20
22
  if check
21
- output_msg = case msg
22
- when Symbol
23
- symbol_message msg
24
- when Array
25
- array_message msg
26
- else
27
- msg
28
- end
29
- puts "there was a problem > ".red + output_msg
23
+ output_msg =
24
+ case msg
25
+ when Symbol
26
+ symbol_message msg
27
+ when Array
28
+ array_message msg
29
+ else
30
+ msg
31
+ end
32
+ command.empty? || exec(command)
33
+ puts 'there was a problem > '.red + output_msg
30
34
  exit(1)
31
35
  end
32
36
  end
33
37
 
34
- def symbol_message s
38
+ def symbol_message(s)
35
39
  case s
36
40
  when :clean
37
- "hai dei file non committati...non posso continuare'"
41
+ 'hai dei file non committati...non posso continuare'
38
42
  when :detached_head
39
43
  "repo in stato 'head detached'"
40
44
  when :wrong_args
41
- "argomento non corretto"
45
+ 'argomento non corretto'
42
46
  end
43
47
  end
44
48
 
45
- def array_message arr
49
+ def array_message(arr)
46
50
  case arr[0]
47
51
  when :wrong_args
48
52
  msg = symbol_message arr[0]
49
53
  msg += "\n"
50
- msg += " valore possibile: "
51
- values = "[ " + arr[1].join(" | ").yellow + " ]"
54
+ msg += ' valore possibile: '
55
+ values = '[ ' + arr[1].join(' | ').yellow + ' ]'
52
56
  msg += values
53
57
  msg
54
58
  end
55
59
  end
56
60
 
57
- def stop_unless check, msg
58
- stop_if (not check), msg
61
+ def stop_unless(check, msg, command = '')
62
+ stop_if !check, msg, command
63
+ end
64
+
65
+ # executes command and returns properly colored output
66
+ def execute_command(cmd)
67
+ output "Eseguo #{cmd}".yellow
68
+ res = `#{cmd}`
69
+ color = $CHILD_STATUS.exitstatus.zero? ? 'green' : 'red'
70
+ output res.send color
71
+ stop_if (color == 'red'), "Errore durante la build dell'artifact".red
59
72
  end
60
73
  end
@@ -0,0 +1,336 @@
1
+ require 'aws-sdk'
2
+ require 'colorize'
3
+ #
4
+ module PrimaAwsClient
5
+ def s3_client
6
+ @s3 ||= Aws::S3::Client.new
7
+ end
8
+
9
+ def cf_client
10
+ @cf ||= Aws::CloudFormation::Client.new
11
+ end
12
+
13
+ def asg_client
14
+ @asg ||= Aws::AutoScaling::Client.new
15
+ end
16
+
17
+ def ec2_client
18
+ @ec2 ||= Aws::EC2::Client.new
19
+ end
20
+
21
+ def stack_list
22
+ stacks = []
23
+ next_token = ''
24
+ loop do
25
+ print '.'.yellow; STDOUT.flush
26
+ options = next_token != '' ? { next_token: next_token } : {}
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
34
+ stacks += resp.stacks
35
+ break unless resp.next_token
36
+ next_token = resp.next_token
37
+ end
38
+ puts '.'.yellow; STDOUT.flush
39
+ stacks.keep_if { |stack| stack.stack_name.include? '-qa-' }
40
+ stacks
41
+ end
42
+
43
+ def cluster_list
44
+ stacks = []
45
+ next_token = ''
46
+ loop do
47
+ print '.'.yellow; STDOUT.flush
48
+ options = next_token != '' ? { next_token: next_token } : {}
49
+ begin
50
+ resp = cf_client.describe_stacks(options)
51
+ rescue Aws::CloudFormation::Errors::Throttling => e
52
+ output 'Throttling, retrying in 15 seconds'.red
53
+ sleep 15
54
+ resp = cf_client.describe_stacks(options)
55
+ end
56
+ stacks += resp.stacks
57
+ break unless resp.next_token
58
+ next_token = resp.next_token
59
+ end
60
+ puts '.'.yellow; STDOUT.flush
61
+ stacks.keep_if { |stack| stack.stack_name.include? 'ecs-cluster-qa-' }
62
+ stacks
63
+ end
64
+
65
+ def list_exports
66
+ exports = []
67
+ next_token = ''
68
+ loop do
69
+ print '.'.yellow; STDOUT.flush
70
+ options = next_token != '' ? { next_token: next_token } : {}
71
+ begin
72
+ resp = cf_client.list_exports(options)
73
+ rescue Aws::CloudFormation::Errors::Throttling => e
74
+ output 'Throttling, retrying in 15 seconds'.red
75
+ sleep 15
76
+ resp = cf_client.list_exports(options)
77
+ end
78
+ exports += resp.exports
79
+ break unless resp.next_token
80
+ next_token = resp.next_token
81
+ end
82
+ puts '.'.yellow; STDOUT.flush
83
+ exports
84
+ end
85
+
86
+ def create_stack(stack_name, stack_body, parameters = [], tags = [], role = nil)
87
+ cf_args = {
88
+ stack_name: stack_name,
89
+ template_body: stack_body,
90
+ parameters: parameters,
91
+ tags: tags,
92
+ capabilities: ['CAPABILITY_IAM'],
93
+ on_failure: 'ROLLBACK'
94
+ }
95
+
96
+ if role != nil then
97
+ cf_args.merge!(role_arn: role)
98
+ end
99
+
100
+ begin
101
+ cf_client.create_stack(cf_args)
102
+ rescue Aws::CloudFormation::Errors::Throttling, Aws::CloudFormation::Errors::LimitExcedeedException => e
103
+ output 'Throttling, retrying in 15 seconds'.red
104
+ sleep 15
105
+ create_stack(stack_name, stack_body, parameters = [], tags = [])
106
+ else
107
+ output "La creazione dello stack #{stack_name} è stata avviata".green
108
+ end
109
+ end
110
+
111
+ def update_stack(stack_name, template_body, parameters = [], tags = [], role = nil)
112
+ cf_args = {
113
+ stack_name: stack_name,
114
+ template_body: template_body,
115
+ parameters: parameters,
116
+ tags: tags,
117
+ capabilities: ['CAPABILITY_IAM']
118
+ }
119
+
120
+ if role != nil then
121
+ cf_args.merge!(role_arn: role)
122
+ end
123
+
124
+ begin
125
+ cf_client.update_stack(cf_args)
126
+ rescue Aws::CloudFormation::Errors::Throttling => e
127
+ output 'Throttling, retrying in 15 seconds'.red
128
+ sleep 15
129
+ update_stack(stack_name, template_body, parameters = [], tags = [])
130
+ rescue Aws::CloudFormation::Errors::ValidationError => e
131
+ raise e
132
+ else
133
+ output "L'update dello stack #{stack_name} è stato avviato".green
134
+ end
135
+ end
136
+
137
+ def update_stack_url(stack_name, template_url, parameters = [], tags = [], role = nil)
138
+ cf_args = {
139
+ stack_name: stack_name,
140
+ template_url: template_url,
141
+ parameters: parameters,
142
+ tags: tags,
143
+ capabilities: ['CAPABILITY_IAM']
144
+ }
145
+
146
+ if role != nil then
147
+ cf_args.merge!(role_arn: role)
148
+ end
149
+
150
+ begin
151
+ cf_client.update_stack(cf_args)
152
+ rescue Aws::CloudFormation::Errors::Throttling => e
153
+ output 'Throttling, retrying in 15 seconds'.red
154
+ sleep 15
155
+ update_stack_url(stack_name, template_url, parameters = [], tags = [])
156
+ rescue Aws::CloudFormation::Errors::ValidationError => e
157
+ raise e
158
+ else
159
+ output "L'update dello stack #{stack_name} è stato avviato".green
160
+ end
161
+ end
162
+
163
+ def stack_exists?(stack_name)
164
+ begin
165
+ cf_client.describe_stacks(stack_name: stack_name)
166
+ rescue Aws::CloudFormation::Errors::Throttling => e
167
+ output 'Throttling, retrying in 15 seconds'.red
168
+ sleep 15
169
+ stack_exists?(stack_name)
170
+ rescue Aws::CloudFormation::Errors::ValidationError => e
171
+ return false if e.message.include? 'does not exist'
172
+ raise e
173
+ else
174
+ true
175
+ end
176
+ end
177
+
178
+ def delete_stack(stack_name)
179
+ begin
180
+ cf_client.delete_stack(stack_name: stack_name)
181
+ rescue Aws::CloudFormation::Errors::Throttling => e
182
+ output 'Throttling, retrying in 15 seconds'.red
183
+ sleep 15
184
+ delete_stack(stack_name)
185
+ else
186
+ output "Stack #{stack_name} spenta con successo\n".green
187
+ end
188
+ end
189
+
190
+ 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'])
191
+ ready = false
192
+ sleep_seconds = 13
193
+ output "Attendo che lo stack #{stack_name} finisca di essere inizializzato...\n".yellow
194
+ while !ready
195
+ ready = true if stack_ready?(stack_name, failed_statuses)
196
+ seconds_elapsed = 0
197
+ loop do
198
+ break if seconds_elapsed >= sleep_seconds
199
+ print '.'.yellow; STDOUT.flush
200
+ sleep 1
201
+ seconds_elapsed += 1
202
+ end
203
+ end
204
+ output "\nStack #{stack_name} pronto!\n".green
205
+ end
206
+
207
+ def get_stack_tags(name)
208
+ begin
209
+ resp = cf_client.describe_stacks(stack_name: name)
210
+ rescue Aws::CloudFormation::Errors::Throttling => e
211
+ output 'Throttling, retrying in 15 seconds'.red
212
+ sleep 15
213
+ get_stack_tags(name)
214
+ else
215
+ resp.stacks[0].tags
216
+ end
217
+ end
218
+
219
+ def get_stack_parameters(name)
220
+ begin
221
+ resp = cf_client.describe_stacks(stack_name: name)
222
+ rescue Aws::CloudFormation::Errors::Throttling => e
223
+ output 'Throttling, retrying in 15 seconds'.red
224
+ sleep 15
225
+ get_stack_parameters(name)
226
+ else
227
+ resp.stacks[0].parameters
228
+ end
229
+ end
230
+
231
+ def get_stack_outputs(name)
232
+ begin
233
+ resp = cf_client.describe_stacks(stack_name: name)
234
+ rescue Aws::CloudFormation::Errors::Throttling => e
235
+ output 'Throttling, retrying in 15 seconds'.red
236
+ sleep 15
237
+ get_stack_outputs(name)
238
+ else
239
+ resp.stacks[0].outputs
240
+ end
241
+ end
242
+
243
+ def get_stack_template(name)
244
+ begin
245
+ resp = cf_client.get_template(stack_name: name)
246
+ rescue Aws::CloudFormation::Errors::Throttling => e
247
+ output 'Throttling, retrying in 15 seconds'.red
248
+ sleep 15
249
+ get_stack_template(name)
250
+ else
251
+ resp.template_body
252
+ end
253
+
254
+ end
255
+
256
+ 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'])
257
+ begin
258
+ resp = cf_client.describe_stacks(
259
+ stack_name: stack_name
260
+ )
261
+ stack_status = resp.stacks[0].stack_status
262
+ rescue Aws::CloudFormation::Errors::Throttling => e
263
+ print 'Throttling'.red; STDOUT.flush
264
+ return false
265
+ end
266
+ raise "The stack #{stack_name} errored out" if failed_statuses.include? stack_status
267
+ ['CREATE_COMPLETE', 'UPDATE_COMPLETE', 'UPDATE_ROLLBACK_COMPLETE', 'ROLLBACK_COMPLETE'].include? stack_status
268
+ end
269
+
270
+ def artifact_exists?(bucket, path)
271
+ resp = s3_client.list_objects(
272
+ bucket: bucket,
273
+ max_keys: 1,
274
+ prefix: path
275
+ )
276
+ !resp.contents.empty?
277
+ end
278
+
279
+ def upload_artifact(source_path, destination_path, bucket_name_override=nil)
280
+ output "Upload dell'artifact in corso (#{(File.size(source_path).to_f / 2**20).round(2)} MiB)\n".yellow
281
+ s3 = Aws::S3::Resource.new
282
+ s3_bucket = if !bucket_name_override.nil? then bucket_name_override else @s3_bucket end
283
+ puts s3_bucket
284
+ obj = s3.bucket(s3_bucket).object(destination_path)
285
+ obj.upload_file(source_path)
286
+
287
+ output "#{s3_bucket}/#{destination_path} uploadato con successo!\n".green
288
+ end
289
+
290
+ def list_import_stacks(export_name)
291
+ stacks = []
292
+ next_token = ''
293
+ loop do
294
+ print '.'.yellow; STDOUT.flush
295
+ options = next_token != '' ? { export_name: export_name, next_token: next_token } : {export_name: export_name}
296
+ begin
297
+ resp = cf_client.list_imports(options)
298
+ rescue Aws::CloudFormation::Errors::Throttling => e
299
+ output 'Throttling, retrying in 15 seconds'.red
300
+ sleep 15
301
+ resp = cf_client.list_imports(options)
302
+ end
303
+ stacks += resp.imports
304
+ break unless resp.next_token
305
+ next_token = resp.next_token
306
+ end
307
+ stacks
308
+ end
309
+
310
+ def get_autoscaling_capacity(asg_name)
311
+ resp = asg_client.describe_auto_scaling_groups(auto_scaling_group_names: [asg_name])
312
+ resp.auto_scaling_groups[0].desired_capacity
313
+ end
314
+
315
+ def get_spotfleet_capacity(fleet_arn)
316
+ resp = ec2_client.describe_spot_fleet_requests(spot_fleet_request_ids: [fleet_arn])
317
+ resp.spot_fleet_request_configs[0].spot_fleet_request_config.target_capacity
318
+ end
319
+
320
+ def hashes_to_tags(hashes)
321
+ tags = []
322
+ hkeys = hashes.keys
323
+ hkeys.each do |hkey|
324
+ tags.insert(0, { key: hkey, value: hashes[hkey].to_s })
325
+ end
326
+ tags
327
+ end
328
+
329
+ def tags_to_hashes(tags)
330
+ hash = Hash.new
331
+ tags.each do |tags_obj|
332
+ hash[tags_obj.key] = tags_obj.value
333
+ end
334
+ hash
335
+ end
336
+ end
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', 'aws_username', 'aws_password', 'prima_apikey']
16
17
  attr_reader :gh, :twig, :config, :rugged, :aws
17
18
 
18
19
  def initialize
@@ -211,7 +212,12 @@ class Prima
211
212
  end
212
213
 
213
214
  def assign_issue_to_me(issue)
214
- @gh.update_issue('primait/board', issue, :assignee => user_login)
215
+ detailed_issue = get_issue issue
216
+ assignees = [user_login]
217
+ detailed_issue.assignees.each do |assignee|
218
+ assignees << assignee.login
219
+ end
220
+ @gh.update_issue('primait/board', issue, :assignees => assignees)
215
221
  end
216
222
 
217
223
  def assign_pull_request_to_me(pr_number)