kumogata2 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/kumogata2/cli/option_parser.rb +5 -5
- data/lib/kumogata2/client.rb +83 -13
- data/lib/kumogata2/version.rb +1 -1
- 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: 6db4a45c394094f8864f856bfd395f6f241ced59
|
4
|
+
data.tar.gz: 770e9b3fed15e232d59bd13bac0bf7aebc619c28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7791866506cd56ca7ed5be88e0ab6b619140ae5cb245abbd66fa970056289771219edd834bcef14bd2e9f08df9b4db357fae803c9bc61f6a058b3407662e9f3
|
7
|
+
data.tar.gz: 02d7c9156d0acd8d96c67a18e83071fdfc24dd7e984a3cbf22590062f8877effd5a0fcc5ad50f9c58107c7444529a6caea91faf3b359356a94db6d6b06ba859c
|
data/README.md
CHANGED
@@ -32,6 +32,7 @@ Commands:
|
|
32
32
|
create PATH_OR_URL [STACK_NAME] Create resources as specified in the template
|
33
33
|
update PATH_OR_URL STACK_NAME Update a stack as specified in the template
|
34
34
|
delete STACK_NAME Delete a specified stack
|
35
|
+
deploy PATH_OR_URL STACK_NAME Create a change set and executes it
|
35
36
|
validate PATH_OR_URL Validate a specified template
|
36
37
|
list [STACK_NAME] List summary information for stacks
|
37
38
|
export STACK_NAME Export a template from a specified stack
|
@@ -25,6 +25,11 @@ module Kumogata2::CLI
|
|
25
25
|
arguments: [:stack_name],
|
26
26
|
output: false,
|
27
27
|
},
|
28
|
+
deploy: {
|
29
|
+
description: 'Create a change set and executes it',
|
30
|
+
arguments: [:path_or_url, :stack_name],
|
31
|
+
output: false,
|
32
|
+
},
|
28
33
|
validate: {
|
29
34
|
description: 'Validate a specified template',
|
30
35
|
arguments: [:path_or_url],
|
@@ -145,11 +150,6 @@ module Kumogata2::CLI
|
|
145
150
|
|
146
151
|
opt.parse!
|
147
152
|
|
148
|
-
# https://github.com/aws/aws-sdk-ruby/blob/v2.3.11/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb#L29
|
149
|
-
unless options[:aws][:region]
|
150
|
-
raise "missing region; use '--region' option or export region name to ENV['AWS_REGION']"
|
151
|
-
end
|
152
|
-
|
153
153
|
unless (command = argv.shift)
|
154
154
|
puts opt.help
|
155
155
|
exit_parse!(1)
|
data/lib/kumogata2/client.rb
CHANGED
@@ -51,6 +51,16 @@ class Kumogata2::Client
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
def deploy(path_or_url, stack_name = nil)
|
55
|
+
stack_name = normalize_stack_name(stack_name)
|
56
|
+
validate_stack_name(stack_name) if stack_name
|
57
|
+
template = open_template(path_or_url)
|
58
|
+
update_deletion_policy(template, delete_stack: !stack_name)
|
59
|
+
|
60
|
+
change_set = create_change_set(template, stack_name)
|
61
|
+
execute_change_set(change_set)
|
62
|
+
end
|
63
|
+
|
54
64
|
def validate(path_or_url)
|
55
65
|
template = open_template(path_or_url)
|
56
66
|
validate_template(template)
|
@@ -150,6 +160,12 @@ class Kumogata2::Client
|
|
150
160
|
|
151
161
|
def get_client
|
152
162
|
return @client unless @client.nil?
|
163
|
+
|
164
|
+
# https://github.com/aws/aws-sdk-ruby/blob/v2.3.11/aws-sdk-core/lib/aws-sdk-core/plugins/regional_endpoint.rb#L29
|
165
|
+
unless @options[:aws][:region]
|
166
|
+
raise "missing region; use '--region' option or export region name to ENV['AWS_REGION']"
|
167
|
+
end
|
168
|
+
|
153
169
|
@client = Aws::CloudFormation::Client.new(@options.aws)
|
154
170
|
end
|
155
171
|
|
@@ -283,7 +299,7 @@ class Kumogata2::Client
|
|
283
299
|
raise_stack_error!(stack, 'Delete failed')
|
284
300
|
end
|
285
301
|
|
286
|
-
log(:info, '
|
302
|
+
log(:info, 'Delete stack successfully')
|
287
303
|
end
|
288
304
|
|
289
305
|
def validate_template(template)
|
@@ -312,17 +328,35 @@ class Kumogata2::Client
|
|
312
328
|
JSON.parse(template)
|
313
329
|
end
|
314
330
|
|
315
|
-
def
|
316
|
-
output = nil
|
331
|
+
def create_change_set(template, stack_name)
|
317
332
|
change_set_name = [stack_name, SecureRandom.uuid].join('-')
|
318
333
|
|
319
|
-
|
334
|
+
begin
|
335
|
+
stack = describe_stack(stack_name)
|
336
|
+
case stack[:stack_status]
|
337
|
+
when /_FAILED\z/
|
338
|
+
log(:error, "Stack #{stack_name} status is now failed - #{stack[:stack_status]}", color: :red)
|
339
|
+
return
|
340
|
+
when /^DELETE_/
|
341
|
+
log(:error, "Stack #{stack_name} statis is now delete - #{stack[:stack_status]}", color: :red)
|
342
|
+
return
|
343
|
+
when 'REVIEW_IN_PROGRESS'
|
344
|
+
change_set_type = 'CREATE'
|
345
|
+
else
|
346
|
+
change_set_type = 'UPDATE'
|
347
|
+
end
|
348
|
+
rescue
|
349
|
+
change_set_type = 'CREATE'
|
350
|
+
end
|
351
|
+
|
352
|
+
log(:info, "Creating ChangeSet: #{change_set_name} for #{stack_name}", color: :cyan)
|
320
353
|
|
321
354
|
params = {
|
322
355
|
stack_name: stack_name,
|
323
356
|
change_set_name: change_set_name,
|
324
357
|
template_body: convert_output_value(template),
|
325
358
|
parameters: parameters_array,
|
359
|
+
change_set_type: change_set_type,
|
326
360
|
}
|
327
361
|
|
328
362
|
params.merge!(set_api_params(params,
|
@@ -337,26 +371,62 @@ class Kumogata2::Client
|
|
337
371
|
|
338
372
|
completed, change_set = wait_change_set(change_set_arn, 'CREATE_COMPLETE')
|
339
373
|
|
340
|
-
|
341
|
-
output = changes_for(change_set)
|
342
|
-
else
|
374
|
+
unless completed
|
343
375
|
log(:error, "Create ChangeSet failed: #{change_set.status_reason}", color: :red)
|
344
376
|
end
|
345
377
|
|
346
|
-
|
378
|
+
change_set
|
379
|
+
end
|
380
|
+
|
381
|
+
def execute_change_set(change_set)
|
382
|
+
if change_set.status != 'CREATE_COMPLETE'
|
383
|
+
log(:info, "ChangeSet status is #{change_set.status}", color: :red)
|
384
|
+
delete_change_set(change_set)
|
385
|
+
return
|
386
|
+
end
|
387
|
+
|
388
|
+
log(:info, "Executing ChangeSet: #{change_set.change_set_name} for #{change_set.stack_name}", color: :cyan)
|
389
|
+
|
390
|
+
get_client.execute_change_set(change_set_name: change_set.change_set_name,
|
391
|
+
stack_name: change_set.stack_name)
|
392
|
+
|
393
|
+
stack = get_resource.stack(change_set.stack_name)
|
394
|
+
|
395
|
+
event_log = create_event_log(stack)
|
396
|
+
|
397
|
+
completed = wait(stack, stack.stack_status, event_log)
|
398
|
+
|
399
|
+
unless completed
|
400
|
+
raise_stack_error!(stack, 'executing change set failed')
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
def delete_change_set(change_set)
|
405
|
+
log(:info, "Deleting ChangeSet: #{change_set.change_set_name}", color: :red)
|
347
406
|
|
348
|
-
get_client.delete_change_set(
|
407
|
+
get_client.delete_change_set(stack_name: change_set.stack_name,
|
408
|
+
change_set_name: change_set.change_set_id)
|
349
409
|
|
350
410
|
begin
|
351
|
-
completed, _ = wait_change_set(
|
411
|
+
completed, _ = wait_change_set(change_set.change_set_id, 'DELETE_COMPLETE')
|
352
412
|
rescue Aws::CloudFormation::Errors::ChangeSetNotFound
|
353
413
|
# Handle `ChangeSet does not exist`
|
354
414
|
completed = true
|
355
415
|
end
|
356
416
|
|
357
|
-
|
358
|
-
|
359
|
-
|
417
|
+
completed
|
418
|
+
end
|
419
|
+
|
420
|
+
def show_change_set(template, stack_name)
|
421
|
+
output = nil
|
422
|
+
|
423
|
+
change_set = create_change_set(template, stack_name)
|
424
|
+
output = changes_for(change_set) unless change_set.nil?
|
425
|
+
|
426
|
+
delete_change_set(change_set)
|
427
|
+
|
428
|
+
stack = get_resource.stack(stack_name)
|
429
|
+
delete_stack(stack_name) if stack.stack_status == 'REVIEW_IN_PROGRESS'
|
360
430
|
|
361
431
|
output
|
362
432
|
end
|
data/lib/kumogata2/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kumogata2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|