cf_deployer 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +3 -0
- data/lib/cf_deployer/driver/cloud_formation_driver.rb +4 -0
- data/lib/cf_deployer/driver/dry_run.rb +24 -0
- data/lib/cf_deployer/stack.rb +4 -4
- data/lib/cf_deployer/version.rb +1 -1
- data/spec/unit/driver/cloud_formation_spec.rb +48 -0
- data/spec/unit/driver/dry_run_spec.rb +66 -0
- data/spec/unit/stack_spec.rb +44 -0
- 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: 6f550eef2ccbd8df2bff3ad4441d228800bab756
|
4
|
+
data.tar.gz: f3981f2ef12ab4338ddb5bec47fc31c6326e2582
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d09d5100924380dd8643c041bdd188b6d53fd3a2b408a4a7609ce785fc935149dc37a39d2b192c9003651cc695f1757c8014134bcbe930f679c4648691e3a78
|
7
|
+
data.tar.gz: 93e9e12ece59c4a0a01508047be7da243977770b82ed8d1d844f1eea81c8b98b3875e942db5e88231ed4716db1004f8c87baca255fd9a61d3a02f24b9b79a0d6
|
data/ChangeLog.md
CHANGED
@@ -54,3 +54,6 @@ version 1.4.0
|
|
54
54
|
- Merge settings from parent component when given (https://github.com/manheim/cf_deployer/pull/37)
|
55
55
|
- Added support for stack policies (https://github.com/manheim/cf_deployer/pull/40)
|
56
56
|
- Fix broken Travis builds with newer version of bundler (https://github.com/manheim/cf_deployer/pull/42)
|
57
|
+
|
58
|
+
version 1.5.0
|
59
|
+
- Treat deployments that end in a rollback as a failure
|
@@ -21,13 +21,17 @@ module CfDeployer
|
|
21
21
|
CfDeployer::Driver::DryRun.guard "Skipping update_stack" do
|
22
22
|
aws_stack.update opts.merge(:template => template)
|
23
23
|
end
|
24
|
+
|
24
25
|
rescue AWS::CloudFormation::Errors::ValidationError => e
|
25
26
|
if e.message =~ /No updates are to be performed/
|
26
27
|
Log.info e.message
|
28
|
+
return false
|
27
29
|
else
|
28
30
|
raise
|
29
31
|
end
|
30
32
|
end
|
33
|
+
|
34
|
+
return !CfDeployer::Driver::DryRun.enabled?
|
31
35
|
end
|
32
36
|
|
33
37
|
def stack_status
|
@@ -4,6 +4,30 @@ module CfDeployer
|
|
4
4
|
|
5
5
|
@@enabled = false
|
6
6
|
|
7
|
+
def self.enabled?
|
8
|
+
@@enabled
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.run_with_value value, &block
|
12
|
+
previous_value = @@enabled
|
13
|
+
@@enabled = value
|
14
|
+
begin
|
15
|
+
block.call
|
16
|
+
rescue => e
|
17
|
+
raise e
|
18
|
+
ensure
|
19
|
+
@@enabled = previous_value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.enable_for &block
|
24
|
+
run_with_value(true, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.disable_for &block
|
28
|
+
run_with_value(false, &block)
|
29
|
+
end
|
30
|
+
|
7
31
|
def self.enable
|
8
32
|
CfDeployer::Log.info "Enabling Dry-Run Mode"
|
9
33
|
@@enabled = true
|
data/lib/cf_deployer/stack.rb
CHANGED
@@ -3,9 +3,9 @@ module CfDeployer
|
|
3
3
|
end
|
4
4
|
|
5
5
|
class Stack
|
6
|
-
SUCCESS_STATS = [:create_complete, :update_complete, :
|
6
|
+
SUCCESS_STATS = [:create_complete, :update_complete, :delete_complete]
|
7
7
|
READY_STATS = SUCCESS_STATS - [:delete_complete]
|
8
|
-
FAILED_STATS = [:create_failed, :update_failed, :delete_failed]
|
8
|
+
FAILED_STATS = [:create_failed, :update_failed, :delete_failed, :update_rollback_complete]
|
9
9
|
|
10
10
|
|
11
11
|
def initialize(stack_name, component, context)
|
@@ -127,8 +127,8 @@ module CfDeployer
|
|
127
127
|
unless override_policy_json.nil?
|
128
128
|
args[:stack_policy_during_update_body] = override_policy_json
|
129
129
|
end
|
130
|
-
@cf_driver.update_stack(template, args)
|
131
|
-
wait_for_stack_op_terminate
|
130
|
+
stack_updated = @cf_driver.update_stack(template, args)
|
131
|
+
wait_for_stack_op_terminate if stack_updated
|
132
132
|
end
|
133
133
|
|
134
134
|
def create_stack(template, params, capabilities, tags, notify, create_policy_json)
|
data/lib/cf_deployer/version.rb
CHANGED
@@ -42,6 +42,54 @@ describe 'CloudFormation' do
|
|
42
42
|
CfDeployer::Driver::CloudFormation.new('testStack').parameters.should eq(parameters)
|
43
43
|
end
|
44
44
|
|
45
|
+
context 'update_stack' do
|
46
|
+
it 'skips the stack update if dry run is enabled' do
|
47
|
+
cloud_formation = CfDeployer::Driver::CloudFormation.new 'my_stack'
|
48
|
+
expect(cloud_formation).to receive(:aws_stack).never
|
49
|
+
|
50
|
+
CfDeployer::Driver::DryRun.enable_for do
|
51
|
+
cloud_formation.update_stack :template, {}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns false if no updates were performed (because of dry run)' do
|
56
|
+
cloud_formation = CfDeployer::Driver::CloudFormation.new 'my_stack'
|
57
|
+
result = nil
|
58
|
+
|
59
|
+
CfDeployer::Driver::DryRun.enable_for do
|
60
|
+
result = cloud_formation.update_stack :template, {}
|
61
|
+
end
|
62
|
+
|
63
|
+
expect(result).to be_false
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns false if no updates were performed (because no difference in template)' do
|
67
|
+
cloud_formation = CfDeployer::Driver::CloudFormation.new 'my_stack'
|
68
|
+
expect(cloud_formation).to receive(:aws_stack).and_raise(AWS::CloudFormation::Errors::ValidationError.new('No updates are to be performed'))
|
69
|
+
result = nil
|
70
|
+
|
71
|
+
CfDeployer::Driver::DryRun.disable_for do
|
72
|
+
result = cloud_formation.update_stack :template, {}
|
73
|
+
end
|
74
|
+
|
75
|
+
expect(result).to be_false
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns true when updates are performed' do
|
79
|
+
cloud_formation = CfDeployer::Driver::CloudFormation.new 'my_stack'
|
80
|
+
aws_stack = double(:update => :did_something)
|
81
|
+
expect(cloud_formation).to receive(:aws_stack).and_return aws_stack
|
82
|
+
result = nil
|
83
|
+
|
84
|
+
CfDeployer::Driver::DryRun.disable_for do
|
85
|
+
result = cloud_formation.update_stack :template, {}
|
86
|
+
end
|
87
|
+
|
88
|
+
expect(result).to be_true
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
45
93
|
context 'resource_statuses' do
|
46
94
|
it 'should get resource statuses' do
|
47
95
|
expected = {
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'DryRun' do
|
4
|
+
|
5
|
+
context 'enable_for' do
|
6
|
+
it 'enables dry run only during the block given' do
|
7
|
+
CfDeployer::Driver::DryRun.disable_for do
|
8
|
+
enabled_in_block = false
|
9
|
+
|
10
|
+
CfDeployer::Driver::DryRun.enable_for do
|
11
|
+
enabled_in_block = CfDeployer::Driver::DryRun.enabled?
|
12
|
+
end
|
13
|
+
|
14
|
+
expect(enabled_in_block).to be_true
|
15
|
+
expect(CfDeployer::Driver::DryRun.enabled?).to be_false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'resets dry run, even if the given block throws an exception' do
|
20
|
+
CfDeployer::Driver::DryRun.disable_for do
|
21
|
+
enabled_in_block = false
|
22
|
+
|
23
|
+
expect do
|
24
|
+
CfDeployer::Driver::DryRun.enable_for do
|
25
|
+
enabled_in_block = CfDeployer::Driver::DryRun.enabled?
|
26
|
+
raise 'boom'
|
27
|
+
end
|
28
|
+
end.to raise_error('boom')
|
29
|
+
|
30
|
+
expect(enabled_in_block).to be_true
|
31
|
+
expect(CfDeployer::Driver::DryRun.enabled?).to be_false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'disable_for' do
|
37
|
+
it 'disables dry run only during the block given' do
|
38
|
+
CfDeployer::Driver::DryRun.enable_for do
|
39
|
+
enabled_in_block = nil
|
40
|
+
|
41
|
+
CfDeployer::Driver::DryRun.disable_for do
|
42
|
+
enabled_in_block = CfDeployer::Driver::DryRun.enabled?
|
43
|
+
end
|
44
|
+
|
45
|
+
expect(enabled_in_block).to be_false
|
46
|
+
expect(CfDeployer::Driver::DryRun.enabled?).to be_true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'resets dry run, even if the given block throws an exception' do
|
51
|
+
CfDeployer::Driver::DryRun.enable_for do
|
52
|
+
enabled_in_block = nil
|
53
|
+
|
54
|
+
expect do
|
55
|
+
CfDeployer::Driver::DryRun.disable_for do
|
56
|
+
enabled_in_block = CfDeployer::Driver::DryRun.enabled?
|
57
|
+
raise 'boom'
|
58
|
+
end
|
59
|
+
end.to raise_error('boom')
|
60
|
+
|
61
|
+
expect(enabled_in_block).to be_false
|
62
|
+
expect(CfDeployer::Driver::DryRun.enabled?).to be_true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/unit/stack_spec.rb
CHANGED
@@ -72,6 +72,50 @@ describe CfDeployer::Stack do
|
|
72
72
|
stack.deploy
|
73
73
|
end
|
74
74
|
|
75
|
+
it 'waits for result when stack is updated' do
|
76
|
+
template = { :resources => {}}
|
77
|
+
allow(CfDeployer::ConfigLoader).to receive(:erb_to_json).with('web', @config).and_return(template)
|
78
|
+
allow(@cf_driver).to receive(:stack_exists?) { true }
|
79
|
+
allow(@cf_driver).to receive(:stack_status) { :create_complete }
|
80
|
+
expected_opt = {
|
81
|
+
:capabilities => [],
|
82
|
+
:parameters => {:foo => 'bar'}
|
83
|
+
}
|
84
|
+
expect(@cf_driver).to receive(:update_stack).with(template, expected_opt).and_return(true)
|
85
|
+
stack = CfDeployer::Stack.new('test','web', @config)
|
86
|
+
expect(stack).to receive(:wait_for_stack_op_terminate)
|
87
|
+
stack.deploy
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'does not wait for result when stack is not updated' do
|
91
|
+
template = { :resources => {}}
|
92
|
+
allow(CfDeployer::ConfigLoader).to receive(:erb_to_json).with('web', @config).and_return(template)
|
93
|
+
allow(@cf_driver).to receive(:stack_exists?) { true }
|
94
|
+
allow(@cf_driver).to receive(:stack_status) { :create_complete }
|
95
|
+
expected_opt = {
|
96
|
+
:capabilities => [],
|
97
|
+
:parameters => {:foo => 'bar'}
|
98
|
+
}
|
99
|
+
expect(@cf_driver).to receive(:update_stack).with(template, expected_opt).and_return(false)
|
100
|
+
stack = CfDeployer::Stack.new('test','web', @config)
|
101
|
+
expect(stack).to_not receive(:wait_for_stack_op_terminate)
|
102
|
+
stack.deploy
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'does not fail if deployment caused no updates, and stack was already in a rollback state' do
|
106
|
+
template = { :resources => {}}
|
107
|
+
allow(CfDeployer::ConfigLoader).to receive(:erb_to_json).with('web', @config).and_return(template)
|
108
|
+
allow(@cf_driver).to receive(:stack_exists?) { true }
|
109
|
+
allow(@cf_driver).to receive(:stack_status) { :update_rollback_complete }
|
110
|
+
expected_opt = {
|
111
|
+
:capabilities => [],
|
112
|
+
:parameters => {:foo => 'bar'}
|
113
|
+
}
|
114
|
+
expect(@cf_driver).to receive(:update_stack).with(template, expected_opt).and_return(false)
|
115
|
+
stack = CfDeployer::Stack.new('test','web', @config)
|
116
|
+
stack.deploy
|
117
|
+
end
|
118
|
+
|
75
119
|
it 'updates a stack using the override policy, when defined' do
|
76
120
|
template = { :resources => {}}
|
77
121
|
override_policy = { :Statement => [] }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cf_deployer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jame Brechtel
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-
|
14
|
+
date: 2016-07-11 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: aws-sdk
|
@@ -206,6 +206,7 @@ files:
|
|
206
206
|
- spec/unit/deployment_strategy/deployment_strategy_spec.rb
|
207
207
|
- spec/unit/driver/auto_scaling_group_spec.rb
|
208
208
|
- spec/unit/driver/cloud_formation_spec.rb
|
209
|
+
- spec/unit/driver/dry_run_spec.rb
|
209
210
|
- spec/unit/driver/elb_spec.rb
|
210
211
|
- spec/unit/driver/instance_spec.rb
|
211
212
|
- spec/unit/driver/route53_spec.rb
|
@@ -257,6 +258,7 @@ test_files:
|
|
257
258
|
- spec/unit/deployment_strategy/deployment_strategy_spec.rb
|
258
259
|
- spec/unit/driver/auto_scaling_group_spec.rb
|
259
260
|
- spec/unit/driver/cloud_formation_spec.rb
|
261
|
+
- spec/unit/driver/dry_run_spec.rb
|
260
262
|
- spec/unit/driver/elb_spec.rb
|
261
263
|
- spec/unit/driver/instance_spec.rb
|
262
264
|
- spec/unit/driver/route53_spec.rb
|