kumo_keisei 3.2.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66099568edba510ba762b74a4ad4399eec9946a0
4
- data.tar.gz: 2c7eb0d24a55a913b4aeca57a1a911eab0e6aa51
3
+ metadata.gz: ee8cf3ca725828906b7a8c98b2ddd15957964443
4
+ data.tar.gz: b5a1bcbb5b5f0093f86aec78378a2a08c4c86a31
5
5
  SHA512:
6
- metadata.gz: 287b8d01d89b2fdc805f8a2d169056ee0265e9ece9ad58ea08c9c27c914dca57c73690d37adbcd28a2c1350c2f1b46dd6c360898f59e702c76ca2d1a9101a13a
7
- data.tar.gz: 0599d8839161ff6d12fd3cd0a79421e4e93b2be1e2bae554977b6fe02eec5b58e090bc13e9d494f050ad9ba5968352985e49f50fee5b514e3054ff4284bb9fe8
6
+ metadata.gz: e81b694610cf7626e3ab8ad2bbd39a6e6f273b007200c89057b7ff4405b8812c8e9c44afe81af74bec88a84b9603b036df37ec816d82edebcff8e9047e54b6b9
7
+ data.tar.gz: 2a6e0142a23dc0520a193379163db5f8c72963e2dcda1d687105705d30e0353bec25f4f4c5a34cbd3a2a254a9b308faa352fd0afd85b0b829fbc800597e52328
data/README.md CHANGED
@@ -24,12 +24,12 @@ Or install it yourself as:
24
24
 
25
25
  ### Basic Usage
26
26
 
27
- The basic usage will give you a CloudFormation stack named `{application}-{type}-{environment}`. The default type is `nodes`
27
+ The basic usage will give you a CloudFormation stack named `{application}-{environment}`. The default type is `nodes`
28
28
 
29
29
  ```ruby
30
30
  application_name = "myapp"
31
31
  environment_name = "production"
32
- my_stack = KumoKeisei::Stack.new(stack_name, environment_name)
32
+ my_stack = KumoKeisei::Stack.new(application_name, environment_name)
33
33
 
34
34
  stack_config = {
35
35
  config_path: File.join('/app', 'env', 'config'),
@@ -39,15 +39,13 @@ stack_config = {
39
39
  my_stack.apply! stack_config
40
40
  ```
41
41
 
42
- ### Changing the stack type
42
+ ### Stack Naming
43
+
44
+ We are using APPNAME-ENVNAME (e.g `redbubble-staging`) as our naming convention. There are some legacy stacks in AWS which have the old naming convention which is APPNAME-TYPE-ENVNAME (e.g `redbubble-nodes-staging`). If you want to ensure that you keep your existing stack (so you don't accidently build an extra stack):
45
+
46
+ 0. Login into the AWS console and find out what your stack is named.
47
+ 0. Update your app name (see Basic Usage above) in the apply-env script to match your existing stack name's app name part (which is everything before the environment name, e.g `redbubble-nodes` in `redbubble-nodes-staging`)
43
48
 
44
- Specify the `type` in an options object passed to the `KumoKeisei::Stack` constructor. For example the following will give you a `myapp-vpc-production` stack e.g:
45
- ```ruby
46
- vpc_stack_options = {
47
- type: 'vpc'
48
- }
49
- vpc_stack = KumoKeisei::Stack.new('myapp', 'production', vpc_stack_options)
50
- ```
51
49
 
52
50
  ### Timeouts
53
51
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.1
1
+ 4.0.0
@@ -0,0 +1,13 @@
1
+ module KumoKeisei
2
+ class GetStackOutput
3
+ def initialize(aws_stack)
4
+ @aws_stack = aws_stack
5
+ end
6
+
7
+ def output(name)
8
+ return nil if @aws_stack.nil?
9
+ outputs_hash = @aws_stack.outputs.reduce({}) { |acc, o| acc.merge(o.output_key.to_s => o.output_value) }
10
+ outputs_hash[name]
11
+ end
12
+ end
13
+ end
@@ -28,14 +28,21 @@ module KumoKeisei
28
28
  self.new(app_name, environment_name).exists?
29
29
  end
30
30
 
31
- def initialize(app_name, environment_name, options = { confirmation_timeout: 30, waiter_delay: 20, waiter_attempts: 90 })
32
- type = options.fetch(:type, 'nodes')
31
+ def initialize(app_name, environment_name, options = { confirmation_timeout: 30, waiter_delay: 20, waiter_attempts: 90, prompt_user: true })
33
32
  @env_name = environment_name
34
33
  @app_name = app_name
35
- @stack_name = "#{app_name}-#{type}-#{ environment_name }"
34
+ @stack_name = "#{app_name}-#{ environment_name }"
36
35
  @confirmation_timeout = options[:confirmation_timeout]
37
36
  @waiter_delay = options[:waiter_delay]
38
37
  @waiter_attempts = options[:waiter_attempts]
38
+ prompt_user if options[:prompt_user]
39
+ end
40
+
41
+ def prompt_user
42
+ puts "WARNING: You are about to lookup/create/update/delete #{@stack_name}."
43
+ puts "We have recently changed the way we name stacks in aws, if #{@stack_name} looks correct, hit 'Y', otherwise hit anything else and read more at 'https://github.com/redbubble/kumo_keisei_gem'"
44
+ continue = $stdin.gets.chomp.downcase
45
+ exit 1 if continue != 'y'
39
46
  end
40
47
 
41
48
  def apply!(stack_config)
@@ -62,12 +69,8 @@ module KumoKeisei
62
69
  ensure_deleted!
63
70
  end
64
71
 
65
- def outputs(output)
66
- stack = get_stack
67
- return nil if stack.nil?
68
- outputs_hash = stack.outputs.reduce({}) { |acc, o| acc.merge(o.output_key.to_s => o.output_value) }
69
-
70
- outputs_hash[output]
72
+ def outputs(name)
73
+ return GetStackOutput.new(get_stack).output(name)
71
74
  end
72
75
 
73
76
  def logical_resource(resource_name)
data/lib/kumo_keisei.rb CHANGED
@@ -2,3 +2,4 @@ require_relative "kumo_keisei/cloud_formation_stack"
2
2
  require_relative "kumo_keisei/stack"
3
3
  require_relative "kumo_keisei/environment_config"
4
4
  require_relative "kumo_keisei/errors"
5
+ require_relative "kumo_keisei/get_stack_output"
@@ -0,0 +1,33 @@
1
+ describe KumoKeisei::GetStackOutput do
2
+ describe "#output" do
3
+ let(:aws_stack) { double(:stack, outputs: [output])}
4
+ let(:name) { "Key" }
5
+ subject { described_class.new(aws_stack).output(name) }
6
+
7
+ context 'when the stack exists' do
8
+ let(:value) { "Value" }
9
+ let(:output_key) { name }
10
+ let(:output) { double(:output, output_key: output_key, output_value: value) }
11
+
12
+ it "returns the outputs given by CloudFormation" do
13
+ expect(subject).to eq(value)
14
+ end
15
+
16
+ context "Output key doesn't exist" do
17
+ let(:output_key) { "something else" }
18
+
19
+ it "returns the outputs given by CloudFormation" do
20
+ expect(subject).to be_nil
21
+ end
22
+ end
23
+ end
24
+
25
+ context 'when the stack does not exist' do
26
+ let(:aws_stack) { nil }
27
+
28
+ it 'returns nil' do
29
+ expect(subject).to be_nil
30
+ end
31
+ end
32
+ end
33
+ end
@@ -9,13 +9,14 @@ describe KumoKeisei::Stack do
9
9
 
10
10
  let(:app_name) { "my-stack" }
11
11
  let(:environment_name) { 'non-production' }
12
- let(:stack_name) { "#{app_name}-nodes-#{environment_name}" }
12
+ let(:stack_name) { "#{app_name}-#{environment_name}" }
13
13
  let(:stack_template_name) { "#{app_name}-#{environment_name}" }
14
14
  let(:stack_cfntemplate_filename) { "#{stack_template_name}.json" }
15
15
  let(:stack_cfnparams_filename) { "#{stack_template_name}.yml.erb" }
16
16
  let(:cloudformation) { instance_double(Aws::CloudFormation::Client) }
17
17
  let(:happy_stack_status) { "CREATE_COMPLETE" }
18
- let(:cf_stack) { stack_result_list_with_status(happy_stack_status, stack_name) }
18
+ let(:named_cf_stack) { double(stack_status: happy_stack_status, stack_name: stack_name, stack_id: nil) }
19
+ let(:cf_stack) { double(stacks: [named_cf_stack]) }
19
20
  let(:parameter_builder) { instance_double(KumoKeisei::ParameterBuilder, params: {}) }
20
21
  let(:stack_template_body) { double(:stack_template_body) }
21
22
  let(:cf_stack_update_params) do
@@ -30,7 +31,7 @@ describe KumoKeisei::Stack do
30
31
  cf_stack_update_params.merge(on_failure: "DELETE")
31
32
  end
32
33
  let(:confirmation_timeout) { 30 }
33
- subject(:instance) { KumoKeisei::Stack.new(app_name, environment_name) }
34
+ subject(:instance) { KumoKeisei::Stack.new(app_name, environment_name, confirmation_timeout: 30, waiter_delay: 20, waiter_attempts: 90, prompt_user: false ) }
34
35
  let(:stack_config) {
35
36
  {
36
37
  config_path: 'config-path',
@@ -40,8 +41,6 @@ describe KumoKeisei::Stack do
40
41
  }
41
42
  }
42
43
 
43
- context "unit tests" do
44
-
45
44
  before do
46
45
  allow(KumoKeisei::ConsoleJockey).to receive(:flash_message)
47
46
  allow(KumoKeisei::ConsoleJockey).to receive(:write_line).and_return(nil)
@@ -51,7 +50,6 @@ describe KumoKeisei::Stack do
51
50
  allow(KumoKeisei::ParameterBuilder).to receive(:new).and_return(parameter_builder)
52
51
  allow(File).to receive(:read).with(stack_cfntemplate_filename).and_return(stack_template_body)
53
52
  allow(KumoKeisei::EnvironmentConfig).to receive(:new).with(stack_config.merge(params_template_file_path: "/#{stack_cfnparams_filename}")).and_return(double(:environment_config, cf_params: {}))
54
- # allow(File).to receive(:absolute_path).and_return("#{app_name}.yml.erb")
55
53
  Dir.chdir('/')
56
54
  end
57
55
 
@@ -234,22 +232,15 @@ describe KumoKeisei::Stack do
234
232
  end
235
233
 
236
234
  describe "#outputs" do
237
- context 'when the stack exists' do
238
- let(:output) { double(:output, output_key: "Key", output_value: "Value") }
239
- let(:stack) { double(:stack, stack_name: stack_name, outputs: [output])}
240
- let(:stack_result) { double(:stack_result, stacks: [stack]) }
241
-
242
- it "returns the outputs given by CloudFormation" do
243
- allow(cloudformation).to receive(:describe_stacks).and_return(stack_result)
244
- expect(subject.outputs("Key")).to eq("Value")
245
- end
246
- end
235
+ let(:name) { "Key" }
236
+ subject { instance.outputs(name) }
247
237
 
248
- context 'when the stack does not exist' do
249
- it 'returns nil' do
250
- allow(subject).to receive(:get_stack).and_return(nil)
251
- expect(subject.outputs('Key')).to be_nil
252
- end
238
+ let(:get_stack_output) { double(:get_stack_output) }
239
+
240
+ it "delegates output retrieval to GetStackOutput" do
241
+ expect(KumoKeisei::GetStackOutput).to receive(:new).with(named_cf_stack).and_return(get_stack_output)
242
+ expect(get_stack_output).to receive(:output).with(name).and_return('Value')
243
+ expect(subject).to eq("Value")
253
244
  end
254
245
  end
255
246
 
@@ -271,17 +262,6 @@ describe KumoKeisei::Stack do
271
262
  end
272
263
  end
273
264
 
274
- describe "#type" do
275
- it "presumes stacks are of type node if the type is not set" do
276
- expect(subject.stack_name).to eq("#{app_name}-nodes-#{environment_name}")
277
- end
278
-
279
- it "embeds the type into the name of the stack if set" do
280
- subject = KumoKeisei::Stack.new(app_name, environment_name, { type: "vpc" } )
281
- expect(subject.stack_name).to eq("#{app_name}-vpc-#{environment_name}")
282
- end
283
- end
284
-
285
265
  describe "#config" do
286
266
  context "when passed a config_path and params_template_file_path" do
287
267
  it "will return the results of the nested KumoKeisei::EnvironmentConfig.config" do
@@ -310,12 +290,11 @@ describe KumoKeisei::Stack do
310
290
  }
311
291
  }
312
292
  it "will raise an error" do
313
- expect { described_class.new(app_name, environment_name).config(stack_config)}.to raise_error(KumoKeisei::Stack::UsageError)
293
+ expect { described_class.new(app_name, environment_name, prompt_user: false).config(stack_config)}.to raise_error(KumoKeisei::Stack::UsageError)
314
294
  end
315
295
  end
316
296
 
317
297
  end
318
- end
319
298
 
320
299
  describe "#params_template_path" do
321
300
  context "when looking for the parameter template file" do
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: 3.2.1
4
+ version: 4.0.0
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-02 00:00:00.000000000 Z
11
+ date: 2016-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -104,6 +104,7 @@ files:
104
104
  - lib/kumo_keisei/environment_config.rb
105
105
  - lib/kumo_keisei/errors.rb
106
106
  - lib/kumo_keisei/file_loader.rb
107
+ - lib/kumo_keisei/get_stack_output.rb
107
108
  - lib/kumo_keisei/parameter_builder.rb
108
109
  - lib/kumo_keisei/stack.rb
109
110
  - script/build.sh
@@ -113,6 +114,7 @@ files:
113
114
  - spec/lib/kumo_keisei/console_jockey_spec.rb
114
115
  - spec/lib/kumo_keisei/environment_config_spec.rb
115
116
  - spec/lib/kumo_keisei/file_loader_spec.rb
117
+ - spec/lib/kumo_keisei/get_stack_output_spec.rb
116
118
  - spec/lib/kumo_keisei/parameter_builder_spec.rb
117
119
  - spec/lib/kumo_keisei/stack_spec.rb
118
120
  - spec/spec_helper.rb
@@ -145,6 +147,7 @@ test_files:
145
147
  - spec/lib/kumo_keisei/console_jockey_spec.rb
146
148
  - spec/lib/kumo_keisei/environment_config_spec.rb
147
149
  - spec/lib/kumo_keisei/file_loader_spec.rb
150
+ - spec/lib/kumo_keisei/get_stack_output_spec.rb
148
151
  - spec/lib/kumo_keisei/parameter_builder_spec.rb
149
152
  - spec/lib/kumo_keisei/stack_spec.rb
150
153
  - spec/spec_helper.rb