bora 0.6.0 → 0.7.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 +4 -4
- data/README.md +21 -14
- data/lib/bora/stack.rb +21 -6
- data/lib/bora/tasks.rb +11 -4
- data/lib/bora/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 430ba291be8abc9a0c129e8bca4639fa29020dd0
|
4
|
+
data.tar.gz: c7c059203422cc63a92b775d58dddd8cf026439e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c5759c5c000c0d890c05f08bd81bf00a7b38ec398228ea2e5dc0b003113d7aa61ab5b3c87508a5d5b814e0f4b3d97b1300cf81e34f55dae534de6ca93755487
|
7
|
+
data.tar.gz: ba94c9c28df960b73753a45549bf8670defcb83f48b6adcfb62a1b6c507ffb3c238c4a17a1eadcc0b0e2ba9b4ace1d270f90111bbcad663b5f5d7f7e5c6b991d
|
data/README.md
CHANGED
@@ -29,11 +29,7 @@ Add this to your `Rakefile`
|
|
29
29
|
```ruby
|
30
30
|
require 'bora'
|
31
31
|
|
32
|
-
Bora::Tasks.new("example")
|
33
|
-
t.stack_options = {
|
34
|
-
template_body: File.read("example.json")
|
35
|
-
}
|
36
|
-
end
|
32
|
+
Bora::Tasks.new("example", "example.json")
|
37
33
|
```
|
38
34
|
|
39
35
|
This will give you the following rake tasks
|
@@ -59,32 +55,43 @@ When you define the Bora tasks, you can pass in a number of options that control
|
|
59
55
|
The available options are shown below with their default values.
|
60
56
|
|
61
57
|
```ruby
|
62
|
-
Bora::Tasks.new("example") do |t|
|
63
|
-
t.colorize = true
|
58
|
+
Bora::Tasks.new("example", "example.json") do |t|
|
64
59
|
t.stack_options = {}
|
60
|
+
t.colorize = true
|
65
61
|
end
|
66
62
|
```
|
67
|
-
|
63
|
+
* `example.json` - this is a URL to your template. It can be anything openable by Ruby's [`open-uri`](http://ruby-doc.org/stdlib-2.3.0/libdoc/open-uri/rdoc/OpenURI.html) library (eg: a local file or http/https URL), or an `s3://` URL. This parameter is optional - if you don't supply it, you *must* specify either `template_body` or `template_url` in the `stack_options` (see below).
|
64
|
+
* `stack_options` - A hash of options that are passed directly to the CloudFormation [`create_stack`](http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudFormation/Client.html#create_stack-instance_method) and [`update_stack`](http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudFormation/Client.html#update_stack-instance_method) APIs. If you specified a template URL in the constructor you don't need to supply `template_body` or `template_url here (you will get an error if you do).
|
68
65
|
* `colorize` - A boolean that controls whether console output is colored or not
|
69
|
-
* `stack_options` - A hash of options that are passed directly to the CloudFormation [create_stack](http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudFormation/Client.html#create_stack-instance_method) and [update_stack](http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudFormation/Client.html#update_stack-instance_method) APIs.
|
70
|
-
You must at a minimum specify either the `template_body` or `template_url` option.
|
71
66
|
|
72
67
|
|
73
68
|
### Dynamically Generated Templates
|
74
69
|
If you are generating your templates dynamically using a DSL such as [cfndsl](https://github.com/stevenjack/cfndsl) you can easily hook this into the Bora tasks by defining a `generate` task within the Bora::Tasks constructor.
|
75
70
|
|
76
71
|
```ruby
|
77
|
-
Bora::Tasks.new("example") do |t|
|
72
|
+
Bora::Tasks.new("example", "example.json") do |t|
|
78
73
|
desc "Generates the template"
|
79
74
|
task :generate do
|
80
75
|
# Generate your template and write it into "example.json" here
|
81
76
|
end
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
If you need to pass parameters from the rake command line through to your generate method,
|
81
|
+
you can do so by using Rake's [`args.extras`](http://ruby-doc.org/stdlib-2.2.2/libdoc/rake/rdoc/Rake/TaskArguments.html#method-i-extras) functionality:
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
```ruby
|
84
|
+
Bora::Tasks.new("example", "example.json") do |t|
|
85
|
+
task :generate do |t, args|
|
86
|
+
arg1, arg2 = args.extras
|
87
|
+
# Generate your template and write it into "example.json" here
|
88
|
+
end
|
86
89
|
end
|
87
90
|
```
|
91
|
+
```shell
|
92
|
+
$ rake stack:example:apply[arg1_value, arg2_value]
|
93
|
+
```
|
94
|
+
|
88
95
|
|
89
96
|
### API
|
90
97
|
|
data/lib/bora/stack.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'set'
|
2
|
+
require 'open-uri'
|
2
3
|
require 'aws-sdk'
|
3
4
|
require 'diffy'
|
4
5
|
require 'bora/stack_status'
|
@@ -55,12 +56,13 @@ module Bora
|
|
55
56
|
end
|
56
57
|
|
57
58
|
def new_template(options, pretty = true)
|
58
|
-
|
59
|
-
|
59
|
+
options = resolve_options(options, true)
|
60
|
+
template = options[:template_body]
|
61
|
+
if template
|
60
62
|
template = JSON.pretty_generate(JSON.parse(template)) if pretty
|
61
63
|
template
|
62
64
|
else
|
63
|
-
raise
|
65
|
+
raise "new_template not yet implemented for URL #{options[:template_url]}"
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
@@ -69,7 +71,7 @@ module Bora
|
|
69
71
|
end
|
70
72
|
|
71
73
|
def validate(options)
|
72
|
-
@cfn.validate_template(options.select { |k| [:template_body, :template_url].include?(k) })
|
74
|
+
@cfn.validate_template(resolve_options(options).select { |k| [:template_body, :template_url].include?(k) })
|
73
75
|
end
|
74
76
|
|
75
77
|
def status
|
@@ -92,9 +94,9 @@ module Bora
|
|
92
94
|
underlying_stack(refresh: true)
|
93
95
|
return true if action == :delete && !exists?
|
94
96
|
@previous_event_time = last_event_time
|
95
|
-
options[:stack_name] = @stack_name
|
96
97
|
begin
|
97
|
-
@
|
98
|
+
action_options = {stack_name: @stack_name}.merge(resolve_options(options))
|
99
|
+
@cfn.method("#{action.to_s.downcase}_stack").call(action_options)
|
98
100
|
wait_for_completion(&block)
|
99
101
|
rescue Aws::CloudFormation::Errors::ValidationError => e
|
100
102
|
raise e unless e.message.include?(NO_UPDATE_MESSAGE)
|
@@ -103,6 +105,19 @@ module Bora
|
|
103
105
|
(action == :delete && !underlying_stack) || status.success?
|
104
106
|
end
|
105
107
|
|
108
|
+
def resolve_options(options, load_all = false)
|
109
|
+
return options if options[:template_body] || !options[:template_url]
|
110
|
+
uri = URI(options[:template_url])
|
111
|
+
if uri.scheme != "s3" || load_all
|
112
|
+
resolved_options = options.clone
|
113
|
+
resolved_options[:template_body] = open(options[:template_url]).read
|
114
|
+
resolved_options.delete(:template_url)
|
115
|
+
resolved_options
|
116
|
+
else
|
117
|
+
options
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
106
121
|
def wait_for_completion
|
107
122
|
begin
|
108
123
|
events = unprocessed_events
|
data/lib/bora/tasks.rb
CHANGED
@@ -4,15 +4,21 @@ require 'bora/stack'
|
|
4
4
|
|
5
5
|
module Bora
|
6
6
|
class Tasks < Rake::TaskLib
|
7
|
-
def initialize(stack_name)
|
7
|
+
def initialize(stack_name, template_uri = nil)
|
8
8
|
@stack_name = stack_name
|
9
9
|
@stack = Stack.new(stack_name)
|
10
10
|
@colorize = true
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
@stack_options = {}
|
12
|
+
within_namespace { yield self } if block_given?
|
13
|
+
|
14
|
+
if template_uri
|
15
|
+
if @stack_options[:template_body] || @stack_options[:template_url]
|
16
|
+
raise "You cannot specify a template in the constructor as well as in the stack_options"
|
17
|
+
else
|
18
|
+
@stack_options[:template_url] = template_uri
|
14
19
|
end
|
15
20
|
end
|
21
|
+
|
16
22
|
define_tasks
|
17
23
|
end
|
18
24
|
|
@@ -23,6 +29,7 @@ module Bora
|
|
23
29
|
String.disable_colorization = !@colorize
|
24
30
|
end
|
25
31
|
|
32
|
+
|
26
33
|
private
|
27
34
|
|
28
35
|
def define_tasks
|
data/lib/bora/version.rb
CHANGED