stackup 0.0.1 → 0.0.2
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/Gemfile +1 -0
- data/Gemfile.lock +15 -0
- data/README.md +0 -0
- data/Rakefile +5 -1
- data/bin/stackup +7 -0
- data/lib/stackup.rb +3 -3
- data/lib/stackup/cli.rb +25 -0
- data/lib/stackup/monitor.rb +2 -0
- data/lib/stackup/stack.rb +15 -9
- data/pkg/stackup-0.0.2.gem +0 -0
- data/sample.json +13 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/stackup/monitor_spec.rb +11 -9
- data/spec/stackup/stack_spec.rb +26 -17
- data/stackup.gemspec +1 -2
- metadata +8 -4
- data/pkg/stackup-0.0.1.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dc62580195d06b89d9eb18003751b1271e061fb
|
4
|
+
data.tar.gz: 51755d4592858e5a8926e52b9ac16abc424db145
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9654b97ed0a4b01d84cc334d65c575e95714a12affe82d98a0316fab5d206362b16ec0ebf625ff97bcf4aa71b85d475f4ee0625f44ecda2f61213a66a86e9528
|
7
|
+
data.tar.gz: 26072daf588afb7d27b9d31e3842c40e94a090a5d429c375d56e2667c5c92116add3b6af4e7e7b1d92a3f1fcbc5d390a2fc989600faf3818c428a11cc5b6bbcb
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -8,6 +8,9 @@ PATH
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
ast (2.1.0)
|
12
|
+
astrolabe (1.3.1)
|
13
|
+
parser (~> 2.2)
|
11
14
|
aws-sdk (2.1.20)
|
12
15
|
aws-sdk-resources (= 2.1.20)
|
13
16
|
aws-sdk-core (2.1.20)
|
@@ -20,6 +23,10 @@ GEM
|
|
20
23
|
jmespath (1.0.2)
|
21
24
|
multi_json (~> 1.0)
|
22
25
|
multi_json (1.11.2)
|
26
|
+
parser (2.2.2.6)
|
27
|
+
ast (>= 1.1, < 3.0)
|
28
|
+
powerpack (0.1.1)
|
29
|
+
rainbow (2.0.0)
|
23
30
|
rake (10.4.2)
|
24
31
|
rspec (3.3.0)
|
25
32
|
rspec-core (~> 3.3.0)
|
@@ -34,6 +41,13 @@ GEM
|
|
34
41
|
diff-lcs (>= 1.2.0, < 2.0)
|
35
42
|
rspec-support (~> 3.3.0)
|
36
43
|
rspec-support (3.3.0)
|
44
|
+
rubocop (0.34.1)
|
45
|
+
astrolabe (~> 1.3)
|
46
|
+
parser (>= 2.2.2.5, < 3.0)
|
47
|
+
powerpack (~> 0.1)
|
48
|
+
rainbow (>= 1.99.1, < 3.0)
|
49
|
+
ruby-progressbar (~> 1.4)
|
50
|
+
ruby-progressbar (1.7.5)
|
37
51
|
|
38
52
|
PLATFORMS
|
39
53
|
ruby
|
@@ -42,6 +56,7 @@ DEPENDENCIES
|
|
42
56
|
byebug
|
43
57
|
rake (~> 10.0)
|
44
58
|
rspec (~> 3.3)
|
59
|
+
rubocop (~> 0.32)
|
45
60
|
stackup!
|
46
61
|
|
47
62
|
BUNDLED WITH
|
data/README.md
CHANGED
File without changes
|
data/Rakefile
CHANGED
@@ -3,8 +3,12 @@ require "bundler/gem_tasks"
|
|
3
3
|
require "rspec/core/rake_task"
|
4
4
|
|
5
5
|
RSpec::Core::RakeTask.new do |t|
|
6
|
-
t.pattern =
|
6
|
+
t.pattern = "spec/**/*_spec.rb"
|
7
7
|
t.rspec_opts = ["--colour", "--format", "documentation"]
|
8
8
|
end
|
9
9
|
|
10
10
|
task "default" => "spec"
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
data/bin/stackup
ADDED
data/lib/stackup.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
3
|
-
require_relative
|
1
|
+
require "aws-sdk"
|
2
|
+
require_relative "stackup/monitor"
|
3
|
+
require_relative "stackup/stack"
|
data/lib/stackup/cli.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Stackup
|
2
|
+
class CLI < Clamp::Command
|
3
|
+
|
4
|
+
subcommand ["stack"], "Manage a stack." do
|
5
|
+
parameter "STACK-NAME", "Name of stack", :attribute_name => :stack_name
|
6
|
+
|
7
|
+
subcommand "apply", "Create/update the stack" do
|
8
|
+
parameter "TEMPLATE", "CloudFormation template (.json)", :attribute_name => :template
|
9
|
+
|
10
|
+
def execute
|
11
|
+
stack = Stackup::Stack.new(stack_name, template)
|
12
|
+
stack.create
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
subcommand "delete", "Remove the stack." do
|
17
|
+
def execute
|
18
|
+
stack = Stackup::Stack.new(stack_name, nil)
|
19
|
+
stack.delete
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
data/lib/stackup/monitor.rb
CHANGED
data/lib/stackup/stack.rb
CHANGED
@@ -1,28 +1,34 @@
|
|
1
|
-
require
|
1
|
+
require "set"
|
2
2
|
|
3
3
|
module Stackup
|
4
4
|
class Stack
|
5
|
+
|
5
6
|
attr_reader :stack, :name, :cf, :template, :monitor
|
6
7
|
SUCESS_STATES = ["CREATE_COMPLETE", "UPDATE_COMPLETE"]
|
7
|
-
FAILURE_STATES = ["CREATE_FAILED", "DELETE_FAILED", "UPDATE_ROLLBACK_FAILED", "ROLLBACK_FAILED", "ROLLBACK_COMPLETE","ROLLBACK_FAILED","UPDATE_ROLLBACK_COMPLETE","UPDATE_ROLLBACK_FAILED"]
|
8
|
+
FAILURE_STATES = ["CREATE_FAILED", "DELETE_COMPLETE", "DELETE_FAILED", "UPDATE_ROLLBACK_FAILED", "ROLLBACK_FAILED", "ROLLBACK_COMPLETE", "ROLLBACK_FAILED", "UPDATE_ROLLBACK_COMPLETE", "UPDATE_ROLLBACK_FAILED"]
|
8
9
|
END_STATES = SUCESS_STATES + FAILURE_STATES
|
9
10
|
|
10
11
|
def initialize(name, template)
|
11
12
|
@cf = Aws::CloudFormation::Client.new
|
12
|
-
@stack = Aws::CloudFormation::Stack.new(name
|
13
|
+
@stack = Aws::CloudFormation::Stack.new(:name => name, :client => cf)
|
13
14
|
@monitor = Stackup::Monitor.new(@stack)
|
14
15
|
@template = template
|
15
16
|
@name = name
|
16
17
|
end
|
17
18
|
|
18
19
|
def create
|
19
|
-
response = cf.create_stack(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
})
|
20
|
+
response = cf.create_stack(:stack_name => name,
|
21
|
+
:template_body => template,
|
22
|
+
:disable_rollback => true)
|
23
|
+
stack.wait_until(:max_attempts => 1000, :delay => 10) { |resource| display_events; END_STATES.include?(resource.stack_status) }
|
24
24
|
!response[:stack_id].nil?
|
25
|
-
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete
|
28
|
+
response = cf.delete_stack(:stack_name => name)
|
29
|
+
stack.wait_until(:max_attempts => 1000, :delay => 10) { |resource| display_events; END_STATES.include?(resource.stack_status) }
|
30
|
+
rescue Aws::CloudFormation::Errors::ValidationError
|
31
|
+
puts "Stack does not exist."
|
26
32
|
end
|
27
33
|
|
28
34
|
def display_events
|
Binary file
|
data/sample.json
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Stackup::Monitor do
|
4
|
-
let(:stack) { Stackup::Stack.new(
|
4
|
+
let(:stack) { Stackup::Stack.new("name", "template") }
|
5
5
|
let(:monitor) { Stackup::Monitor.new(stack) }
|
6
|
-
let(:event) { double(Aws::CloudFormation::Event.new(id
|
7
|
-
let(:events) { [
|
6
|
+
let(:event) { double(Aws::CloudFormation::Event.new(:id => "1")) }
|
7
|
+
let(:events) { [event] }
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
before do
|
10
|
+
Aws.config[:region] = "ap-southeast-2"
|
11
|
+
allow(event).to receive(:event_id).and_return("1")
|
11
12
|
allow(stack).to receive(:events).and_return(events)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should add the event if it is non-existent" do
|
12
16
|
expect(monitor.new_events.size).to eq(1)
|
13
17
|
end
|
14
18
|
|
15
|
-
it
|
16
|
-
allow(event).to receive(:event_id).and_return('1')
|
17
|
-
allow(stack).to receive(:events).and_return(events)
|
19
|
+
it "should skip the event if it has been shown" do
|
18
20
|
expect(monitor.new_events.size).to eq(1)
|
19
21
|
expect(monitor.new_events.size).to eq(0)
|
20
22
|
end
|
data/spec/stackup/stack_spec.rb
CHANGED
@@ -1,25 +1,34 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Stackup::Stack do
|
4
|
-
let(:stack) { Stackup::Stack.new(
|
4
|
+
let(:stack) { Stackup::Stack.new("stack_name", double(String)) }
|
5
5
|
let(:cf_stack) { double(Aws::CloudFormation::Stack) }
|
6
|
-
let(:cf) {double(Aws::CloudFormation::Client)}
|
6
|
+
let(:cf) { double(Aws::CloudFormation::Client) }
|
7
7
|
|
8
8
|
before do
|
9
9
|
allow(Aws::CloudFormation::Client).to receive(:new).and_return(cf)
|
10
10
|
allow(Aws::CloudFormation::Stack).to receive(:new).and_return(cf_stack)
|
11
11
|
end
|
12
12
|
|
13
|
-
context
|
14
|
-
|
15
|
-
|
16
|
-
allow(
|
13
|
+
context "delete" do
|
14
|
+
it "should delete the stack if it exists?" do
|
15
|
+
response = double(Struct)
|
16
|
+
allow(cf).to receive(:delete_stack).and_return(response)
|
17
|
+
allow(cf_stack).to receive(:wait_until).and_return(response)
|
18
|
+
expect(stack.delete).to be response
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "create" do
|
23
|
+
let(:response) { Seahorse::Client::Http::Response.new }
|
24
|
+
it "should create stack if all is well" do
|
25
|
+
allow(response).to receive(:[]).with(:stack_id).and_return("1")
|
17
26
|
allow(cf).to receive(:create_stack).and_return(response)
|
18
27
|
allow(cf_stack).to receive(:wait_until).and_return(true)
|
19
28
|
expect(stack.create).to be true
|
20
29
|
end
|
21
30
|
|
22
|
-
it
|
31
|
+
it "should return nil if stack was not created" do
|
23
32
|
allow(response).to receive(:[]).with(:stack_id).and_return(nil)
|
24
33
|
allow(cf).to receive(:create_stack).and_return(response)
|
25
34
|
allow(cf_stack).to receive(:wait_until).and_return(false)
|
@@ -27,27 +36,27 @@ describe Stackup::Stack do
|
|
27
36
|
end
|
28
37
|
end
|
29
38
|
|
30
|
-
context
|
31
|
-
it
|
39
|
+
context "validate" do
|
40
|
+
it "should be valid if cf validate say so" do
|
32
41
|
allow(cf).to receive(:validate_template).and_return({})
|
33
42
|
expect(stack.valid?).to be true
|
34
43
|
end
|
35
44
|
|
36
|
-
it
|
37
|
-
allow(cf).to receive(:validate_template).and_return(
|
45
|
+
it "should be invalid if cf validate say so" do
|
46
|
+
allow(cf).to receive(:validate_template).and_return(:code => "404")
|
38
47
|
expect(stack.valid?).to be false
|
39
48
|
end
|
40
49
|
|
41
50
|
end
|
42
51
|
|
43
|
-
context
|
44
|
-
it
|
45
|
-
allow(cf_stack).to receive(:stack_status).and_return(
|
52
|
+
context "deployed" do
|
53
|
+
it "should be true if it is already deployed" do
|
54
|
+
allow(cf_stack).to receive(:stack_status).and_return("CREATE_COMPLETE")
|
46
55
|
expect(stack.deployed?).to be true
|
47
56
|
end
|
48
57
|
|
49
|
-
it
|
50
|
-
allow(cf_stack).to receive(:stack_status).and_raise(Aws::CloudFormation::Errors::ValidationError.new(
|
58
|
+
it "should be false if it is not deployed" do
|
59
|
+
allow(cf_stack).to receive(:stack_status).and_raise(Aws::CloudFormation::Errors::ValidationError.new("1", "2"))
|
51
60
|
expect(stack.deployed?).to be false
|
52
61
|
end
|
53
62
|
end
|
data/stackup.gemspec
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
|
5
4
|
Gem::Specification.new do |spec|
|
6
5
|
|
7
6
|
spec.name = "stackup"
|
8
|
-
spec.version =
|
7
|
+
spec.version = "0.0.2"
|
9
8
|
spec.authors = ["Arvind Kunday", "Mike Williams"]
|
10
9
|
spec.email = ["arvind.kunday@rea-group.com", "mike.williams@rea-group.com"]
|
11
10
|
spec.summary = "Tools for deployment to AWS"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stackup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arvind Kunday
|
@@ -43,7 +43,8 @@ description:
|
|
43
43
|
email:
|
44
44
|
- arvind.kunday@rea-group.com
|
45
45
|
- mike.williams@rea-group.com
|
46
|
-
executables:
|
46
|
+
executables:
|
47
|
+
- stackup
|
47
48
|
extensions: []
|
48
49
|
extra_rdoc_files: []
|
49
50
|
files:
|
@@ -51,10 +52,13 @@ files:
|
|
51
52
|
- Gemfile.lock
|
52
53
|
- README.md
|
53
54
|
- Rakefile
|
55
|
+
- bin/stackup
|
54
56
|
- lib/stackup.rb
|
57
|
+
- lib/stackup/cli.rb
|
55
58
|
- lib/stackup/monitor.rb
|
56
59
|
- lib/stackup/stack.rb
|
57
|
-
- pkg/stackup-0.0.
|
60
|
+
- pkg/stackup-0.0.2.gem
|
61
|
+
- sample.json
|
58
62
|
- spec/spec_helper.rb
|
59
63
|
- spec/stackup/monitor_spec.rb
|
60
64
|
- spec/stackup/stack_spec.rb
|
@@ -79,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
83
|
version: '0'
|
80
84
|
requirements: []
|
81
85
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.4.
|
86
|
+
rubygems_version: 2.4.8
|
83
87
|
signing_key:
|
84
88
|
specification_version: 4
|
85
89
|
summary: Tools for deployment to AWS
|
data/pkg/stackup-0.0.1.gem
DELETED
Binary file
|