bora 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -5
- data/lib/bora.rb +1 -0
- data/lib/bora/event.rb +5 -9
- data/lib/bora/stack.rb +22 -2
- data/lib/bora/stack_status.rb +29 -0
- data/lib/bora/status.rb +41 -0
- data/lib/bora/tasks.rb +30 -0
- data/lib/bora/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1bb37a94a96c16d392746dd4b9fde60bf77f598
|
4
|
+
data.tar.gz: 33b5fa1b0aefa84de3bffaaba26ca7868381e7ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd85e49e097d8aa0519601152b6e342d391012c6d6b70d02eae06dd3073382c760d0adb5cdc5ae5e2973b1b5278f697b3fe1f5e4512157cd2d37d989f6b8d33d
|
7
|
+
data.tar.gz: 3f91f89e9fdd73faba4a40b8da1df84d2f70254efb3de207c31b9004d62cd0ee7f9f376a3ed642f4cf444d4b23745da9e1428d35f4c84fecc80ebcd664c65e92
|
data/README.md
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
# Bora
|
2
2
|
|
3
|
-
> 1. A cold and often gusty katabatic wind in the Adriatic
|
4
|
-
> 2. A tool for pushing around your cloud formations
|
5
|
-
|
6
3
|
This gem contains Ruby [rake](https://github.com/ruby/rake) tasks that help you work with [CloudFormation](https://aws.amazon.com/cloudformation/) stacks.
|
7
|
-
You don't need to use it with rake though - you can use the
|
8
|
-
in any Ruby app.
|
4
|
+
You don't need to use it with rake though - you can use the underlying classes in any Ruby app.
|
9
5
|
|
10
6
|
|
11
7
|
## Installation
|
@@ -49,6 +45,9 @@ rake stack:example:delete # Deletes the example stack
|
|
49
45
|
rake stack:example:diff # Diffs the new template with the example stack's current template
|
50
46
|
rake stack:example:events # Outputs the latest events from the example stack
|
51
47
|
rake stack:example:new_template # Shows the new template for example stack
|
48
|
+
rake stack:example:recreate # Recreates (deletes then creates) the example stack
|
49
|
+
rake stack:example:status # Displays the current status of the example stack
|
50
|
+
rake stack:example:validate # Checks the example stack's template for validity
|
52
51
|
```
|
53
52
|
|
54
53
|
You can add as many templates as you like into your Rakefile, simply define an instance of `Bora::Tasks` for each one.
|
data/lib/bora.rb
CHANGED
data/lib/bora/event.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'colorize'
|
2
|
+
require 'bora/status'
|
2
3
|
|
3
4
|
module Bora
|
4
5
|
class Event
|
5
6
|
def initialize(event)
|
6
7
|
@event = event
|
8
|
+
@status = Status.new(@event.resource_status)
|
7
9
|
end
|
8
10
|
|
9
11
|
def method_missing(sym, *args, &block)
|
@@ -11,11 +13,11 @@ module Bora
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def status_success?
|
14
|
-
@
|
16
|
+
@status.success?
|
15
17
|
end
|
16
18
|
|
17
19
|
def status_failure?
|
18
|
-
@
|
20
|
+
@status.failure?
|
19
21
|
end
|
20
22
|
|
21
23
|
def status_complete?
|
@@ -23,14 +25,8 @@ module Bora
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def to_s(colorize = true)
|
26
|
-
color = case
|
27
|
-
when status_success?; :green
|
28
|
-
when status_failure?; :red
|
29
|
-
else; :yellow;
|
30
|
-
end
|
31
|
-
status = colorize ? @event.resource_status.colorize(color) : @event.resource_status
|
32
28
|
status_reason = @event.resource_status_reason ? " - #{@event.resource_status_reason}" : ""
|
33
|
-
"#{@event.timestamp} - #{@event.resource_type} - #{@event.logical_resource_id} - #{status}#{status_reason}"
|
29
|
+
"#{@event.timestamp.getlocal} - #{@event.resource_type} - #{@event.logical_resource_id} - #{@status.to_s(colorize)}#{status_reason}"
|
34
30
|
end
|
35
31
|
end
|
36
32
|
end
|
data/lib/bora/stack.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'set'
|
2
2
|
require 'aws-sdk'
|
3
3
|
require 'diffy'
|
4
|
+
require 'bora/stack_status'
|
5
|
+
require 'bora/event'
|
4
6
|
|
5
7
|
module Bora
|
6
8
|
class Stack
|
@@ -22,6 +24,11 @@ module Bora
|
|
22
24
|
exists? ? update(options, &block) : create(options, &block)
|
23
25
|
end
|
24
26
|
|
27
|
+
def recreate(options, &block)
|
28
|
+
delete(&block) if exists?
|
29
|
+
create(options, &block) if !exists?
|
30
|
+
end
|
31
|
+
|
25
32
|
def delete(&block)
|
26
33
|
call_cfn_action(:delete, &block)
|
27
34
|
end
|
@@ -53,13 +60,26 @@ module Bora
|
|
53
60
|
Diffy::Diff.new(template, new_template(options))
|
54
61
|
end
|
55
62
|
|
63
|
+
def validate(options)
|
64
|
+
@cfn.validate_template(options.select { |k| [:template_body, :template_url].include?(k) })
|
65
|
+
end
|
66
|
+
|
67
|
+
def status
|
68
|
+
StackStatus.new(underlying_stack)
|
69
|
+
end
|
70
|
+
|
56
71
|
def exists?
|
57
|
-
|
72
|
+
status.exists?
|
58
73
|
end
|
59
74
|
|
60
75
|
|
76
|
+
# =============================================================================================
|
61
77
|
private
|
62
78
|
|
79
|
+
def method_missing(sym, *args, &block)
|
80
|
+
underlying_stack ? underlying_stack.send(sym, *args, &block) : nil
|
81
|
+
end
|
82
|
+
|
63
83
|
def call_cfn_action(action, options = {}, &block)
|
64
84
|
underlying_stack(refresh: true)
|
65
85
|
return true if action == :delete && !exists?
|
@@ -71,7 +91,7 @@ module Bora
|
|
71
91
|
rescue Aws::CloudFormation::Errors::ValidationError => e
|
72
92
|
raise e unless e.message.include?("No updates are to be performed")
|
73
93
|
end
|
74
|
-
(action == :delete && !underlying_stack) ||
|
94
|
+
(action == :delete && !underlying_stack) || status.success?
|
75
95
|
end
|
76
96
|
|
77
97
|
def wait_for_completion
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'bora/status'
|
2
|
+
|
3
|
+
module Bora
|
4
|
+
class StackStatus
|
5
|
+
def initialize(underlying_stack)
|
6
|
+
@stack = underlying_stack
|
7
|
+
if @stack
|
8
|
+
@status = Status.new(@stack.stack_status)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def exists?
|
13
|
+
@status && !@status.deleted?
|
14
|
+
end
|
15
|
+
|
16
|
+
def success?
|
17
|
+
@status && @status.success?
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s(colorize = true)
|
21
|
+
if @stack
|
22
|
+
status_reason = @stack.stack_status_reason ? " - #{@stack.stack_status_reason}" : ""
|
23
|
+
"#{@stack.stack_name} - #{@status.to_s(colorize)}#{status_reason}"
|
24
|
+
else
|
25
|
+
"Stack does not exist"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/bora/status.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
3
|
+
module Bora
|
4
|
+
class Status
|
5
|
+
def initialize(status)
|
6
|
+
@status = status
|
7
|
+
end
|
8
|
+
|
9
|
+
def success?
|
10
|
+
@status.end_with?("_COMPLETE") && !@status.include?("ROLLBACK")
|
11
|
+
end
|
12
|
+
|
13
|
+
def failure?
|
14
|
+
@status.end_with?("_FAILED") || @status.include?("ROLLBACK")
|
15
|
+
end
|
16
|
+
|
17
|
+
def deleted?
|
18
|
+
@status == "DELETE_COMPLETE"
|
19
|
+
end
|
20
|
+
|
21
|
+
def complete?
|
22
|
+
success? || failure?
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s(colorize = true)
|
26
|
+
colorize ? @status.colorize(color) : @status
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def color
|
33
|
+
case
|
34
|
+
when success?; :green
|
35
|
+
when failure?; :red
|
36
|
+
else; :yellow;
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
data/lib/bora/tasks.rb
CHANGED
@@ -22,6 +22,9 @@ module Bora
|
|
22
22
|
define_diff_task
|
23
23
|
define_events_task
|
24
24
|
define_new_template_task
|
25
|
+
define_recreate_task
|
26
|
+
define_status_task
|
27
|
+
define_validate_task
|
25
28
|
end
|
26
29
|
|
27
30
|
def define_apply_task
|
@@ -84,6 +87,33 @@ module Bora
|
|
84
87
|
end
|
85
88
|
end
|
86
89
|
|
90
|
+
def define_recreate_task
|
91
|
+
within_namespace do
|
92
|
+
desc "Recreates (deletes then creates) the #{@stack_name} stack"
|
93
|
+
task :recreate do
|
94
|
+
invoke_action("recreate", stack_options)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def define_status_task
|
100
|
+
within_namespace do
|
101
|
+
desc "Displays the current status of the #{@stack_name} stack"
|
102
|
+
task :status do
|
103
|
+
puts @stack.status
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def define_validate_task
|
109
|
+
within_namespace do
|
110
|
+
desc "Checks the #{@stack_name} stack's template for validity"
|
111
|
+
task :validate do
|
112
|
+
puts "Template for stack '#{@stack_name}' is valid" if @stack.validate(stack_options)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
87
117
|
def invoke_action(action, *args)
|
88
118
|
puts "#{action.capitalize} stack #{@stack_name}"
|
89
119
|
success = @stack.send(action, *args) { |event| puts event.to_s(colorize) }
|
data/lib/bora/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Blaxland
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -113,6 +113,8 @@ files:
|
|
113
113
|
- lib/bora.rb
|
114
114
|
- lib/bora/event.rb
|
115
115
|
- lib/bora/stack.rb
|
116
|
+
- lib/bora/stack_status.rb
|
117
|
+
- lib/bora/status.rb
|
116
118
|
- lib/bora/tasks.rb
|
117
119
|
- lib/bora/version.rb
|
118
120
|
homepage: https://github.com/ampedandwired/bora
|