jets 2.3.3 → 2.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +3 -0
  3. data/CHANGELOG.md +4 -0
  4. data/lib/jets.rb +5 -0
  5. data/lib/jets/cfn/status.rb +4 -206
  6. data/lib/jets/resource/child_stack/api_gateway.rb +0 -6
  7. data/lib/jets/resource/child_stack/api_resource.rb +0 -6
  8. data/lib/jets/resource/child_stack/app_class.rb +12 -0
  9. data/lib/jets/resource/child_stack/authorizer.rb +0 -6
  10. data/lib/jets/version.rb +1 -1
  11. data/vendor/cfn-status/CHANGELOG.md +14 -0
  12. data/vendor/cfn-status/Gemfile +4 -0
  13. data/vendor/cfn-status/LICENSE.txt +21 -0
  14. data/vendor/cfn-status/README.md +56 -0
  15. data/vendor/cfn-status/Rakefile +6 -0
  16. data/vendor/cfn-status/bin/console +14 -0
  17. data/vendor/cfn-status/bin/setup +8 -0
  18. data/vendor/cfn-status/cfn-status.gemspec +30 -0
  19. data/vendor/cfn-status/lib/cfn-status.rb +1 -0
  20. data/vendor/cfn-status/lib/cfn_status.rb +245 -0
  21. data/vendor/cfn-status/lib/cfn_status/aws_service.rb +51 -0
  22. data/vendor/cfn-status/lib/cfn_status/version.rb +3 -0
  23. data/vendor/cfn-status/spec/fixtures/cfn/pages/fresh/describe_stack_events-1.json +1103 -0
  24. data/vendor/cfn-status/spec/fixtures/cfn/pages/fresh/describe_stack_events-2.json +1104 -0
  25. data/vendor/cfn-status/spec/fixtures/cfn/pages/fresh/describe_stack_events-3.json +1103 -0
  26. data/vendor/cfn-status/spec/fixtures/cfn/pages/updating/describe_stack_events-1.json +1103 -0
  27. data/vendor/cfn-status/spec/fixtures/cfn/pages/updating/describe_stack_events-2.json +1104 -0
  28. data/vendor/cfn-status/spec/fixtures/cfn/pages/updating/describe_stack_events-3.json +1103 -0
  29. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-complete.json +1080 -0
  30. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-in-progress.json +1080 -0
  31. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-update-rollback-complete.json +1086 -0
  32. data/vendor/cfn-status/spec/lib/cfn_status_spec.rb +153 -0
  33. data/vendor/cfn-status/spec/spec_helper.rb +14 -0
  34. metadata +25 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 011aa7990e458d1e5fa86a9819b2972f7076468f88c84026b04b56aff0d710d0
4
- data.tar.gz: ccf4510c62e2d667bc3b17fc32b82db90ea68828529e7cb9238f4b3458d62753
3
+ metadata.gz: 31fd9a4da8f7d6f64364970bf06d6e82aeb8318b44a534460e52f7c6e5d971de
4
+ data.tar.gz: f4545b2deedc9e4bd6a2d2c4159517d07073beee1280d16e9e2b7763e1aaefee
5
5
  SHA512:
6
- metadata.gz: ced86785418e3337fc85c0c5e0c300ccdd3200ee5eeb1c405eeba598aa0e1bc9beca95495cb3a8838a04ac1770a101fd4db6c7b424c9f7d7394c7cb75ad48069
7
- data.tar.gz: 793c70ef4dc623f8b6fa218a1263ad8522752999f54f8fecc279975fccf3e8ca1ef00ac2366f5e1eef01930e09c71c361fab8239f3909eb304d4b0560ea03f4b
6
+ metadata.gz: a74e9ba9b81b69396852b7e26cb3cc247009ae8193d4bca5a211675b1147f8288ad324ff0d88f5a0abafcd908a8835284eb2e03fa56b425f18d0406408144930
7
+ data.tar.gz: 646965fe7717524614b1741e8e190f749e61ec53359d67f817bcaaa86942eb1cc6436e1dc74bac09a49847054fdb2c4ccfd123b5dde4928b955a3ec635c51dc9
data/.gitmodules CHANGED
@@ -0,0 +1,3 @@
1
+ [submodule "vendor/cfn-status"]
2
+ path = vendor/cfn-status
3
+ url = https://github.com/tongueroo/cfn-status.git
data/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [2.3.4]
7
+ - #395 Stay under Outputs Limits for large Jets apps. remove unused outputs
8
+ - use vendor/cfn-status: poll CloudFormation stack events for large stacks
9
+
6
10
  ## [2.3.3]
7
11
  - fix sqs_queue
8
12
 
data/lib/jets.rb CHANGED
@@ -13,6 +13,11 @@ require "jets/gems"
13
13
  require "memoist"
14
14
  require "rainbow/ext/string"
15
15
 
16
+ gem_root = File.dirname(__dir__)
17
+ $:.unshift("#{gem_root}/lib")
18
+ $:.unshift("#{gem_root}/vendor/cfn-status/lib")
19
+ require "cfn_status"
20
+
16
21
  require "jets/autoloaders"
17
22
  Jets::Autoloaders.log! if ENV["JETS_AUTOLOAD_LOG"]
18
23
  Jets::Autoloaders.once.setup
@@ -1,212 +1,10 @@
1
- module Jets::Cfn
2
- class Status
3
- include Jets::AwsServices
1
+ require 'cfn_status'
4
2
 
5
- attr_reader :events
3
+ module Jets::Cfn
4
+ class Status < CfnStatus
6
5
  def initialize(options={})
7
- @options = options
8
6
  @stack_name = Jets::Naming.parent_stack_name
9
- reset
10
- end
11
-
12
- # used for the jets status command
13
- def run
14
- unless stack_exists?(@stack_name)
15
- puts "The stack #{@stack_name.color(:green)} does not exist."
16
- return
17
- end
18
-
19
- resp = cfn.describe_stacks(stack_name: @stack_name)
20
- stack = resp.stacks.first
21
-
22
- puts "The current status for the stack #{@stack_name.color(:green)} is #{stack.stack_status.color(:green)}"
23
- if stack.stack_status =~ /_IN_PROGRESS$/
24
- puts "Stack events (tailing):"
25
- # tail all events until done
26
- @hide_time_took = true
27
- wait
28
- else
29
- puts "Stack events:"
30
- # show the last events that was user initiated
31
- refresh_events
32
- show_events(true)
33
- end
34
- end
35
-
36
- def reset
37
- @events = [] # constantly replaced with recent events
38
- @last_shown_event_id = nil
39
- @stack_deletion_completed = nil
40
- end
41
-
42
- # check for /(_COMPLETE|_FAILED)$/ status
43
- def wait
44
- start_time = Time.now
45
-
46
- refresh_events
47
- until completed || @stack_deletion_completed
48
- show_events
49
- end
50
- show_events(true) # show the final event
51
-
52
- if @stack_deletion_completed
53
- puts "Stack #{@stack_name} deleted."
54
- return
55
- end
56
-
57
- success = false
58
- if last_event_status =~ /_FAILED/
59
- puts "Stack failed: #{last_event_status}".color(:red)
60
- puts "Stack reason #{@events[0]["resource_status_reason"]}".color(:red)
61
- elsif last_event_status =~ /_ROLLBACK_/
62
- puts "Stack rolled back: #{last_event_status}".color(:red)
63
- else # success
64
- puts "Stack success status: #{last_event_status}".color(:green)
65
- success = true
66
- end
67
-
68
- # Never gets here when deleting a stack because the describe stack returns nothing
69
- # once the stack is deleted. Gets here for stack create and update though.
70
- return if @hide_time_took # set in run
71
- took = Time.now - start_time
72
- puts "Time took for stack deployment: #{pretty_time(took).color(:green)}."
73
-
74
- success
75
- end
76
-
77
- def completed
78
- last_event_status =~ /(_COMPLETE|_FAILED)$/ &&
79
- @events[0]["logical_resource_id"] == @stack_name &&
80
- @events[0]["resource_type"] == "AWS::CloudFormation::Stack"
81
- end
82
-
83
- def last_event_status
84
- @events[0]["resource_status"]
85
- end
86
-
87
- # Only shows new events
88
- def show_events(final=false)
89
- if @last_shown_event_id.nil?
90
- i = find_index(:start)
91
- print_events(i)
92
- else
93
- i = find_index(:last_shown)
94
- # puts "last_shown index #{i}"
95
- print_events(i-1) unless i == 0
96
- end
97
-
98
- return if final
99
- sleep 5 unless Jets.env.test?
100
- refresh_events
101
- end
102
-
103
- def print_events(i)
104
- @events[0..i].reverse.each do |e|
105
- print_event(e)
106
- end
107
- @last_shown_event_id = @events[0]["event_id"]
108
- # puts "@last_shown_event_id #{@last_shown_event_id.inspect}"
109
- end
110
-
111
- def print_event(e)
112
- message = [
113
- event_time(e["timestamp"]),
114
- e["resource_status"],
115
- e["resource_type"],
116
- e["logical_resource_id"],
117
- e["resource_status_reason"]
118
- ].join(" ")
119
- message = message.color(:red) if e["resource_status"] =~ /_FAILED/
120
- puts message
121
- end
122
-
123
- # https://stackoverflow.com/questions/18000432/rails-12-hour-am-pm-range-for-a-day
124
- def event_time(timestamp)
125
- Time.parse(timestamp.to_s).localtime.strftime("%I:%M:%S%p")
126
- end
127
-
128
- # refreshes the loaded events in memory
129
- def refresh_events
130
- resp = cfn.describe_stack_events(stack_name: @stack_name)
131
- @events = resp["stack_events"]
132
- rescue Aws::CloudFormation::Errors::ValidationError => e
133
- if e.message =~ /Stack .* does not exis/
134
- @stack_deletion_completed = true
135
- else
136
- raise
137
- end
138
- end
139
-
140
- def find_index(name)
141
- send("#{name}_index")
142
- end
143
-
144
- def start_index
145
- @events.find_index do |event|
146
- event["resource_type"] == "AWS::CloudFormation::Stack" &&
147
- event["resource_status_reason"] == "User Initiated"
148
- end
149
- end
150
-
151
- def last_shown_index
152
- @events.find_index do |event|
153
- event["event_id"] == @last_shown_event_id
154
- end
155
- end
156
-
157
- def success?
158
- resource_status = @events[0]["resource_status"]
159
- %w[CREATE_COMPLETE UPDATE_COMPLETE].include?(resource_status)
160
- end
161
-
162
- def update_rollback?
163
- @events[0]["resource_status"] == "UPDATE_ROLLBACK_COMPLETE"
164
- end
165
-
166
- def find_update_failed_event
167
- i = @events.find_index do |event|
168
- event["resource_type"] == "AWS::CloudFormation::Stack" &&
169
- event["resource_status_reason"] == "User Initiated"
170
- end
171
-
172
- @events[0..i].reverse.find do |e|
173
- e["resource_status"] == "UPDATE_FAILED"
174
- end
175
- end
176
-
177
- def rollback_error_message
178
- return unless update_rollback?
179
-
180
- event = find_update_failed_event
181
- return unless event
182
-
183
- reason = event["resource_status_reason"]
184
- messages_map.each do |pattern, message|
185
- if reason =~ pattern
186
- return message
187
- end
188
- end
189
-
190
- reason # default message is original reason if not found in messages map
191
- end
192
-
193
- def messages_map
194
- {
195
- /CloudFormation cannot update a stack when a custom-named resource requires replacing/ => "A workaround is to run ufo again with STATIC_NAME=0 and to switch to dynamic names for resources. Then run ufo again with STATIC_NAME=1 to get back to statically name resources. Note, there are caveats with the workaround.",
196
- /cannot be associated with more than one load balancer/ => "There's was an issue updating the stack. Target groups can only be associated with one load balancer at a time. The workaround for this is to use UFO_FORCE_TARGET_GROUP=1 and run the command again. This will force the recreation of the target group resource.",
197
- /SetSubnets is not supported for load balancers of type/ => "Changing subnets for Network Load Balancers is currently not supported. You can try workarouding this with UFO_FORCE_ELB=1 and run the command again. This will force the recreation of the elb resource."
198
- }
199
- end
200
-
201
- # http://stackoverflow.com/questions/4175733/convert-duration-to-hoursminutesseconds-or-similar-in-rails-3-or-ruby
202
- def pretty_time(total_seconds)
203
- minutes = (total_seconds / 60) % 60
204
- seconds = total_seconds % 60
205
- if total_seconds < 60
206
- "#{seconds.to_i}s"
207
- else
208
- "#{minutes.to_i}m #{seconds.to_i}s"
209
- end
7
+ super(@stack_name, options)
210
8
  end
211
9
  end
212
10
  end
@@ -16,12 +16,6 @@ module Jets::Resource::ChildStack
16
16
  }
17
17
  end
18
18
 
19
- def outputs
20
- {
21
- logical_id => "!Ref #{logical_id}",
22
- }
23
- end
24
-
25
19
  def template_filename
26
20
  "#{Jets.config.project_namespace}-api-gateway.yml"
27
21
  end
@@ -47,12 +47,6 @@ module Jets::Resource::ChildStack
47
47
  Page.logical_id(parameter)
48
48
  end
49
49
 
50
- def outputs
51
- {
52
- logical_id => "!Ref #{logical_id}",
53
- }
54
- end
55
-
56
50
  def template_filename
57
51
  "#{Jets.config.project_namespace}-api-resources-#{@page}.yml"
58
52
  end
@@ -102,10 +102,22 @@ module Jets::Resource::ChildStack
102
102
  "#{authorizer_stack}.Outputs.#{authorizer_logical_id}"
103
103
  end
104
104
 
105
+ def outputs
106
+ if controller? or job?
107
+ {}
108
+ else
109
+ super # { logical_id => "!Ref #{logical_id}" } in base.rb
110
+ end
111
+ end
112
+
105
113
  def controller?
106
114
  @path.include?('_controller.yml')
107
115
  end
108
116
 
117
+ def job?
118
+ @path.include?('_job.yml')
119
+ end
120
+
109
121
  def scoped_routes
110
122
  @routes ||= Jets::Router.routes.select do |route|
111
123
  route.controller_name == current_app_class.to_s
@@ -26,12 +26,6 @@ module Jets::Resource::ChildStack
26
26
  params
27
27
  end
28
28
 
29
- def outputs
30
- {
31
- logical_id => "!Ref #{logical_id}",
32
- }
33
- end
34
-
35
29
  # map the path to a camelized logical_id. IE: ProtectAuthorizer
36
30
  def authorizer_logical_id
37
31
  regexp = Regexp.new(".*#{Jets.config.project_namespace}-authorizers-")
data/lib/jets/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "2.3.3"
2
+ VERSION = "2.3.4"
3
3
  end
@@ -0,0 +1,14 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
+
6
+ ## [UNRELEASED]
7
+ - #1 Breaking change: rename Rename to CfnStatus, cfn/status to cfn_status
8
+ - Handle large templates and long stack_events via paginating the cfn.describe_stack_events until
9
+
10
+ ## [0.2.0]
11
+ - allow require "cfn-status" to work also
12
+
13
+ ## [0.1.0]
14
+ - Initial release
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cfn-status.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Tung Nguyen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ # Cfn Status
2
+
3
+ Helper library provides status of CloudFormation stack.
4
+
5
+ ## Usage
6
+
7
+ Add this line to your gem's gemspec:
8
+
9
+ ```ruby
10
+ gem.add_development_dependency "cfn-status"
11
+ ```
12
+
13
+ Require it to your library:
14
+
15
+ ```ruby
16
+ require "cfn_status"
17
+ ```
18
+
19
+ Use like so:
20
+
21
+ ```ruby
22
+ status = CfnStatus.new(stack_name)
23
+ status.run # prints out stack events
24
+ ```
25
+
26
+ The `status.run` will:
27
+
28
+ * print out the most recent stack events and return right away if the stack is in a completed state.
29
+ * print out the most recent stack events and poll for more events until the stack in a completed state.
30
+
31
+ To find out whether the most recent completed state of the stack was a success or a fail, you can use `status.success?`.
32
+
33
+ ```ruby
34
+ status.success?
35
+ ```
36
+
37
+ If you need to just wait for the stack to complete, you can also use `status.wait`.
38
+
39
+ ```ruby
40
+ status.wait
41
+ status.success?
42
+ ```
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cfn-status.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cfn_status"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)