kumo_keisei 4.0.3 → 4.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c116cab1d7427e80c7e517cc1a62c5dc380704b
4
- data.tar.gz: 6f540668685e80674a94f897c20a5b8e752c4fe6
3
+ metadata.gz: 7db2c2392cfe443b1f4b92254438a92ec6628034
4
+ data.tar.gz: eb0d0948727fdc934617f441500a4f254527738c
5
5
  SHA512:
6
- metadata.gz: b21ed2b0f957a06986da3854ac3a348a7781b98c23052a812218159fa781fe4fa1581a73ab299764539ca8cff8fb70ec6fb624d9bc04ba2ada46161e460bff21
7
- data.tar.gz: 17446fcdaf29d7c7c21b820c66724ae7a18ab06a0bf1b46c074f2f758993f38802ec357827b9d70d68e3b4df69deda640fe894a2b9c6e589fea768117fb446ec
6
+ metadata.gz: 01756da3af8883007f9b8766b8503450539ee0732caf7eecdc354ee260a270566066e8d52a45097c0650db29a50dbd3105ba662a7a3dbc270c6a5bfacd37f1b1
7
+ data.tar.gz: 2f7ec5597b8380d9624daa22efda61cc82b3b98216ce0c9fd148fe4ff9ff7c532cb086fe23867ad6206ab465daa9080775423a712f15da29bd64b084fc70e166
@@ -3,6 +3,15 @@ steps:
3
3
  command: script/unit_test.sh
4
4
  agents:
5
5
  location: aws
6
+ - name: ':rspec: integration-test'
7
+ command: script/integration_test.sh
8
+ agents:
9
+ location: aws
10
+ env:
11
+ AWS_REGION: us-east-1
12
+
13
+ - wait
14
+
6
15
  - name: ':gem: build'
7
16
  command: script/build.sh
8
17
  agents:
data/README.md CHANGED
@@ -205,6 +205,16 @@ This gem is tested with Ruby (MRI) versions 1.9.3 and 2.2.3.
205
205
 
206
206
  ## Testing changes
207
207
 
208
+ ### Automated AWS Integration Tests
209
+
210
+ You can test the Cloudformation responsibilities of this gem by extending the integration tests at `spec/integration`.
211
+
212
+ To run these tests you need a properly configured AWS environment (with AWS_DEFAULT_REGION, AWS_ACCESS_KEY and AWS_SECRET_ACCESS_KEY set) and then run `./script/integration_test.sh`.
213
+
214
+ If you run this within a Buildkite job then you will have a stack named "kumokeisei-test-$buildnumber" created and torn down for each integration test context. If you run this outside of a Buildkite job then the stack will be named "kumokeisei-test-$username".
215
+
216
+ ### Manual testing with Kumo Tools container
217
+
208
218
  Changes to the gem can be manually tested end to end in a project that uses the gem (i.e. http-wala).
209
219
 
210
220
  1. First start the dev-tools container: `kumo tools debug non-production`
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.3
1
+ 4.0.4
data/kumo_keisei.gemspec CHANGED
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.6"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.4"
25
+ spec.add_development_dependency "pry", "~> 0.10"
25
26
  end
@@ -25,9 +25,6 @@ module KumoKeisei
25
25
  elsif options[:config_dir_path]
26
26
  @log.warn "[DEPRECATION] `:config_dir_path` is deprecated, please pass in `:config_path` instead"
27
27
  @config_file_loader = KumoKeisei::FileLoader.new(config_dir_path: options[:config_dir_path])
28
- else
29
- @log.fatal "Please provide a :config_path"
30
- raise ConfigurationError.new("Please provide a :config_path")
31
28
  end
32
29
 
33
30
  end
@@ -52,10 +49,10 @@ module KumoKeisei
52
49
  def cf_params
53
50
  # returns a list of Cfn friendly paramater_value, paramater_key pairs for
54
51
  # consumption by cloudformation.
55
- return [] unless params
52
+ return [] unless params_template_erb
56
53
  config
57
54
 
58
- stack_params = YAML.load(params.result(binding))
55
+ stack_params = YAML.load(params_template_erb.result(binding))
59
56
  KumoKeisei::ParameterBuilder.new(stack_params).params
60
57
  end
61
58
 
@@ -69,8 +66,8 @@ module KumoKeisei
69
66
  @kms ||= KumoKi::KMS.new
70
67
  end
71
68
 
72
- def params
73
- return nil unless @params_template_file_path
69
+ def params_template_erb
70
+ return nil unless @params_template_file_path && File.exist?(@params_template_file_path)
74
71
  template_file_loader = KumoKeisei::FileLoader.new(config_dir_path: File.dirname(@params_template_file_path))
75
72
  template_file_loader.load_erb(File.basename(@params_template_file_path))
76
73
  end
@@ -0,0 +1,13 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ echo "--- :clock1: :clock2: running specs :clock3: :clock4:"
6
+ bundle install && bundle exec rspec --pattern "spec/integration/*_spec.rb"
7
+
8
+ function inline_image {
9
+ printf '\033]1338;url='"$1"';alt='"$2"'\a\n'
10
+ }
11
+
12
+ echo "+++ Done! :thumbsup: :shipit:"
13
+ inline_image "https://giftoppr.desktopprassets.com/uploads/f828c372186b5fa80a1c553adbcd4bc4d331396b/tumblr_m2cg550aq21ql201ao1_500.gif" "Yuss"
data/script/unit_test.sh CHANGED
@@ -3,7 +3,7 @@
3
3
  set -e
4
4
 
5
5
  echo "--- :clock1: :clock2: running specs :clock3: :clock4:"
6
- bundle install && bundle exec rspec
6
+ bundle install && bundle exec rspec --exclude-pattern "spec/integration/*_spec.rb"
7
7
 
8
8
  function inline_image {
9
9
  printf '\033]1338;url='"$1"';alt='"$2"'\a\n'
@@ -0,0 +1 @@
1
+ SGDescription: "FOO"
@@ -0,0 +1,12 @@
1
+ {
2
+ "AWSTemplateFormatVersion": "2010-09-09",
3
+ "Description": "A simple CFN stack to test KumoKeisei",
4
+ "Resources": {
5
+ "KumoTestSecurityGroup": {
6
+ "Type": "AWS::EC2::SecurityGroup",
7
+ "Properties": {
8
+ "GroupDescription": "A security group to test KumoKeisei"
9
+ }
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "AWSTemplateFormatVersion": "2010-09-09",
3
+ "Description": "A simple CFN stack to test KumoKeisei",
4
+ "Parameters": {
5
+ "SGDescription": {
6
+ "Type": "String",
7
+ "Description": "Description of the security group"
8
+ }
9
+ },
10
+ "Resources": {
11
+ "KumoTestSecurityGroup": {
12
+ "Type": "AWS::EC2::SecurityGroup",
13
+ "Properties": {
14
+ "GroupDescription": { "Ref": "SGDescription" }
15
+ }
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "AWSTemplateFormatVersion": "2010-09-09",
3
+ "Description": "A simple CFN stack to test KumoKeisei",
4
+ "Parameters": {
5
+ "SGDescription": {
6
+ "Type": "String",
7
+ "Description": "Description of the security group"
8
+ }
9
+ },
10
+ "Resources": {
11
+ "KumoTestSecurityGroup": {
12
+ "Type": "AWS::EC2::SecurityGroup",
13
+ "Properties": {
14
+ "GroupDescription": { "Ref": "SGDescription" }
15
+ }
16
+ }
17
+ }
18
+ }
@@ -0,0 +1 @@
1
+ SGDescription: "<%= config['SGDescription'] %>"
@@ -0,0 +1,79 @@
1
+ require 'aws-sdk'
2
+
3
+ def stack_exists?(stack_name)
4
+ cloudformation = Aws::CloudFormation::Client.new
5
+ cloudformation.describe_stacks({ stack_name: stack_name })
6
+ true
7
+ rescue Aws::CloudFormation::Errors::ValidationError
8
+ false
9
+ end
10
+
11
+ describe KumoKeisei::Stack do
12
+ let(:environment_name) { ENV.fetch('BUILDKITE_BUILD_NUMBER', `whoami`.strip) }
13
+ let(:stack_name) { "kumokeisei-test" }
14
+ let(:stack_full_name) { "#{stack_name}-#{environment_name}" }
15
+
16
+ let(:stack_timeout_options) do
17
+ {
18
+ confirmation_timeout: 30,
19
+ waiter_delay: 1,
20
+ waiter_attempts: 90
21
+ }
22
+ end
23
+
24
+ after do
25
+ if stack_exists?(stack_full_name)
26
+ cloudformation = Aws::CloudFormation::Client.new
27
+ cloudformation.delete_stack(stack_name: stack_full_name)
28
+ cloudformation.wait_until(:stack_delete_complete, stack_name: stack_full_name) { |waiter| waiter.delay = 1; waiter.max_attempts = 90 }
29
+ end
30
+ end
31
+
32
+ describe "#apply!" do
33
+ let(:stack) { KumoKeisei::Stack.new(stack_name, environment_name, stack_timeout_options) }
34
+ subject { stack.apply!(stack_config) }
35
+
36
+ context "when given a CloudFormation template" do
37
+ context "and a parameter template file exists" do
38
+ let(:stack_config) do
39
+ {
40
+ config_path: File.join(File.dirname(__FILE__), 'fixtures'),
41
+ template_path: File.join(File.dirname(__FILE__), 'fixtures', 'one-parameter.json')
42
+ }
43
+ end
44
+
45
+ it "creates a stack" do
46
+ subject
47
+ expect(stack_exists?(stack_full_name)).to be true
48
+ end
49
+ end
50
+
51
+ context "and a parameter template file is not required and does not exist" do
52
+ let(:stack_config) do
53
+ {
54
+ template_path: File.join(File.dirname(__FILE__), 'fixtures', 'no-parameter-section.json')
55
+ }
56
+ end
57
+
58
+ it "creates a stack" do
59
+ subject
60
+ expect(stack_exists?(stack_full_name)).to be true
61
+ end
62
+ end
63
+
64
+ context "and a parameter template file is required but does not exist" do
65
+ let(:stack_config) do
66
+ {
67
+ template_path: File.join(File.dirname(__FILE__), 'fixtures', 'one-parameter-no-matching-parameter-template.json')
68
+ }
69
+ end
70
+
71
+ it "does not create a stack" do
72
+ expect { subject }.to raise_error(Aws::CloudFormation::Errors::ValidationError)
73
+ expect(stack_exists?(stack_full_name)).to be false
74
+ end
75
+ end
76
+ end
77
+
78
+ end
79
+ end
@@ -10,7 +10,7 @@ describe KumoKeisei::EnvironmentConfig do
10
10
  end
11
11
  let(:file_loader) { instance_double(KumoKeisei::FileLoader) }
12
12
  let(:file_loader_cloudformation) { instance_double(KumoKeisei::FileLoader) }
13
- let(:parameters) { ERB.new("") }
13
+ let(:parameters_erb) { ERB.new("") }
14
14
  let(:params_template_file_path) { 'junk.txt' }
15
15
  let(:environment_config_file_name) { "#{env_name}.yml" }
16
16
  let(:kms) { instance_double(KumoKi::KMS) }
@@ -20,58 +20,43 @@ describe KumoKeisei::EnvironmentConfig do
20
20
  before do
21
21
  allow(KumoKeisei::FileLoader).to receive(:new).and_return(file_loader)
22
22
  allow(KumoKi::KMS).to receive(:new).and_return(kms)
23
- allow(file_loader).to receive(:load_erb).with(params_template_file_path).and_return(parameters)
23
+ allow(file_loader).to receive(:load_erb).with(params_template_file_path).and_return(parameters_erb)
24
24
  allow(File).to receive(:dirname).and_return('/tmp')
25
25
  end
26
26
 
27
27
  context 'backward compatibility' do
28
- context 'config_path' do
29
- let(:options) do
30
- {
31
- env_name: env_name,
32
- config_path: config_dir_path
33
- }
34
- end
35
- it 'will be used without complaint' do
36
- expect(KumoKeisei::FileLoader).to receive(:new).with(config_dir_path: config_dir_path).and_return(nil)
37
- expect(logger).to receive(:warn).at_most(0).times
38
- expect(logger).to receive(:fatal).at_most(0).times
39
- described_class.new(options, logger)
40
- end
28
+ context 'config_path' do
29
+ let(:options) do
30
+ {
31
+ env_name: env_name,
32
+ config_path: config_dir_path
33
+ }
41
34
  end
42
-
43
- context 'config_dir_path' do
44
- let(:options) do
45
- {
46
- env_name: env_name,
47
- config_dir_path: config_dir_path
48
- }
49
- end
50
-
51
- it 'will be used if given and raise a deprecation warning' do
52
- expect(KumoKeisei::FileLoader).to receive(:new).with(config_dir_path: config_dir_path).and_return(nil)
53
- expect(logger).to receive(:warn).with("[DEPRECATION] `:config_dir_path` is deprecated, please pass in `:config_path` instead")
54
- described_class.new(options, logger)
55
- end
35
+ it 'will be used without complaint' do
36
+ expect(KumoKeisei::FileLoader).to receive(:new).with(config_dir_path: config_dir_path).and_return(nil)
37
+ expect(logger).to receive(:warn).at_most(0).times
38
+ expect(logger).to receive(:fatal).at_most(0).times
39
+ described_class.new(options, logger)
56
40
  end
41
+ end
57
42
 
58
- context 'neither config_path nor config_dir_path' do
59
- let(:options) do
60
- {
61
- env_name: env_name
62
- }
63
- end
43
+ context 'config_dir_path' do
44
+ let(:options) do
45
+ {
46
+ env_name: env_name,
47
+ config_dir_path: config_dir_path
48
+ }
49
+ end
64
50
 
65
- it 'will raise an error' do
66
- expect(logger).to receive(:fatal).with("Please provide a :config_path")
67
- expect { described_class.new(options, logger)}.to raise_error(KumoKeisei::EnvironmentConfig::ConfigurationError)
68
- end
51
+ it 'will be used if given and raise a deprecation warning' do
52
+ expect(KumoKeisei::FileLoader).to receive(:new).with(config_dir_path: config_dir_path).and_return(nil)
53
+ expect(logger).to receive(:warn).with("[DEPRECATION] `:config_dir_path` is deprecated, please pass in `:config_path` instead")
54
+ described_class.new(options, logger)
69
55
  end
56
+ end
70
57
  end
71
58
 
72
59
  context 'unit tests' do
73
- let(:fake_environment_binding) { binding }
74
-
75
60
  describe '#get_binding' do
76
61
  subject { environment_config.get_binding }
77
62
 
@@ -97,25 +82,31 @@ describe KumoKeisei::EnvironmentConfig do
97
82
  end
98
83
 
99
84
  context 'params is empty' do
100
- let(:parameters) { nil }
85
+ let(:parameters_erb) { nil }
101
86
 
102
87
  it 'creates an empty array' do
103
88
  expect(subject).to eq([])
104
89
  end
105
90
  end
106
91
 
92
+ context 'no config_path' do
93
+ let(:options) { { params_template_file_path: "not-a-real-file.yml.erb" } }
94
+
95
+ it { is_expected.to eq([]) }
96
+ end
97
+
107
98
  context 'a hard-coded param' do
108
- let(:parameters) { ERB.new("stack_name: \"foo-stack\"") }
109
- let(:parameters) { ERB.new("parameter_key: \"parameter_value\"") }
99
+ let(:parameters_erb) { ERB.new("foo: \"bar\"") }
110
100
 
111
101
  before do
102
+ allow(File).to receive(:exist?).with(params_template_file_path).and_return(true)
112
103
  allow(file_loader).to receive(:load_hash).with('common.yml').and_return({})
113
104
  allow(file_loader).to receive(:load_hash).with('the_jungle.yml').and_return({})
114
105
  allow(file_loader).to receive(:load_hash).with('development.yml').and_return({})
115
106
  end
116
107
 
117
108
  it 'creates a array containing an aws formatted parameter hash' do
118
- expect(subject).to eq([{parameter_key: "parameter_key", parameter_value: "parameter_value"}])
109
+ expect(subject).to eq([{parameter_key: "foo", parameter_value: "bar"}])
119
110
  end
120
111
  end
121
112
 
@@ -256,7 +247,9 @@ describe KumoKeisei::EnvironmentConfig do
256
247
  subject { environment_config.cf_params }
257
248
 
258
249
  context 'templated params' do
259
- let(:parameters) { ERB.new("stack_name: \"<%= config['stack_name'] %>\"" ) }
250
+ before { allow(File).to receive(:exist?).with(params_template_file_path).and_return(true) }
251
+
252
+ let(:parameters_erb) { ERB.new("stack_name: \"<%= config['stack_name'] %>\"" ) }
260
253
  let(:common_config) { { "stack_name" => "common"} }
261
254
  let(:staging_config) { { "stack_name" => "staging" } }
262
255
  let(:development_config) { { "stack_name" => "development" } }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kumo_keisei
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 4.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Redbubble
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-11 00:00:00.000000000 Z
11
+ date: 2016-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
83
97
  description:
84
98
  email:
85
99
  - delivery-engineering@redbubble.com
@@ -108,8 +122,15 @@ files:
108
122
  - lib/kumo_keisei/parameter_builder.rb
109
123
  - lib/kumo_keisei/stack.rb
110
124
  - script/build.sh
125
+ - script/integration_test.sh
111
126
  - script/release-gem
112
127
  - script/unit_test.sh
128
+ - spec/integration/fixtures/development.yml
129
+ - spec/integration/fixtures/no-parameter-section.json
130
+ - spec/integration/fixtures/one-parameter-no-matching-parameter-template.json
131
+ - spec/integration/fixtures/one-parameter.json
132
+ - spec/integration/fixtures/one-parameter.yml.erb
133
+ - spec/integration/stack_spec.rb
113
134
  - spec/lib/kumo_keisei/cloud_formation_stack_spec.rb
114
135
  - spec/lib/kumo_keisei/console_jockey_spec.rb
115
136
  - spec/lib/kumo_keisei/environment_config_spec.rb
@@ -138,11 +159,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
159
  version: '0'
139
160
  requirements: []
140
161
  rubyforge_project:
141
- rubygems_version: 2.2.2
162
+ rubygems_version: 2.4.5.1
142
163
  signing_key:
143
164
  specification_version: 4
144
165
  summary: A collection of utilities for dealing with AWS Cloud Formation.
145
166
  test_files:
167
+ - spec/integration/fixtures/development.yml
168
+ - spec/integration/fixtures/no-parameter-section.json
169
+ - spec/integration/fixtures/one-parameter-no-matching-parameter-template.json
170
+ - spec/integration/fixtures/one-parameter.json
171
+ - spec/integration/fixtures/one-parameter.yml.erb
172
+ - spec/integration/stack_spec.rb
146
173
  - spec/lib/kumo_keisei/cloud_formation_stack_spec.rb
147
174
  - spec/lib/kumo_keisei/console_jockey_spec.rb
148
175
  - spec/lib/kumo_keisei/environment_config_spec.rb