lono 4.2.7 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +4 -4
  2. data/.cody/README.md +6 -0
  3. data/.cody/acceptance.sh +30 -0
  4. data/.cody/buildspec.yml +21 -0
  5. data/.cody/demo.rb +38 -0
  6. data/.cody/project.rb +12 -0
  7. data/.cody/role.rb +1 -0
  8. data/.gitignore +2 -0
  9. data/.gitmodules +6 -3
  10. data/.travis.yml +7 -0
  11. data/CHANGELOG.md +10 -0
  12. data/Gemfile +0 -1
  13. data/LICENSE.txt +1 -22
  14. data/README.md +46 -55
  15. data/lib/lono.rb +20 -27
  16. data/lib/lono/app_file.rb +5 -0
  17. data/lib/lono/app_file/base.rb +19 -0
  18. data/lib/lono/app_file/build.rb +78 -0
  19. data/lib/lono/app_file/registry.rb +14 -0
  20. data/lib/lono/app_file/registry/item.rb +46 -0
  21. data/lib/lono/app_file/upload.rb +39 -0
  22. data/lib/lono/autoloader.rb +22 -0
  23. data/lib/lono/aws_services.rb +46 -0
  24. data/lib/lono/aws_services/util.rb +49 -0
  25. data/lib/lono/blueprint.rb +113 -0
  26. data/lib/lono/blueprint/find.rb +90 -0
  27. data/lib/lono/blueprint/helper.rb +18 -0
  28. data/lib/lono/blueprint/info.rb +10 -0
  29. data/lib/lono/blueprint/list.rb +14 -0
  30. data/lib/lono/blueprint/root.rb +43 -0
  31. data/lib/lono/cfn.rb +31 -19
  32. data/lib/lono/cfn/aws_service.rb +16 -0
  33. data/lib/lono/cfn/base.rb +244 -261
  34. data/lib/lono/cfn/create.rb +36 -32
  35. data/lib/lono/cfn/current.rb +1 -1
  36. data/lib/lono/cfn/delete.rb +2 -2
  37. data/lib/lono/cfn/deploy.rb +11 -0
  38. data/lib/lono/cfn/diff.rb +1 -1
  39. data/lib/lono/cfn/preview.rb +3 -3
  40. data/lib/lono/cfn/rollback.rb +26 -0
  41. data/lib/lono/cfn/status.rb +2 -203
  42. data/lib/lono/cfn/suffix.rb +67 -0
  43. data/lib/lono/cfn/update.rb +61 -53
  44. data/lib/lono/cli.rb +42 -23
  45. data/lib/lono/completer.rb +0 -2
  46. data/lib/lono/configure.rb +37 -0
  47. data/lib/lono/configure/aws_services.rb +18 -0
  48. data/lib/lono/configure/base.rb +94 -0
  49. data/lib/lono/configure/helpers.rb +128 -0
  50. data/lib/lono/conventions.rb +11 -0
  51. data/lib/lono/core.rb +42 -12
  52. data/lib/lono/core/config.rb +5 -4
  53. data/lib/lono/default/settings.yml +0 -11
  54. data/lib/lono/file_uploader.rb +9 -4
  55. data/lib/lono/help.rb +1 -2
  56. data/lib/lono/help/blueprint.md +46 -0
  57. data/lib/lono/help/cfn.md +5 -4
  58. data/lib/lono/help/cfn/create.md +14 -9
  59. data/lib/lono/help/cfn/deploy.md +92 -0
  60. data/lib/lono/help/cfn/diff.md +0 -1
  61. data/lib/lono/help/cfn/update.md +16 -15
  62. data/lib/lono/help/completion.md +3 -3
  63. data/lib/lono/help/generate.md +0 -1
  64. data/lib/lono/help/new.md +40 -34
  65. data/lib/lono/help/param.md +1 -1
  66. data/lib/lono/help/param/generate.md +1 -1
  67. data/lib/lono/help/template.md +2 -2
  68. data/lib/lono/help/xgraph.md +1 -1
  69. data/lib/lono/inspector.rb +1 -1
  70. data/lib/lono/inspector/base.rb +26 -10
  71. data/lib/lono/inspector/graph.rb +7 -3
  72. data/lib/lono/inspector/summary.rb +15 -3
  73. data/lib/lono/md5.rb +46 -0
  74. data/lib/lono/new.rb +40 -28
  75. data/lib/lono/new/helper.rb +2 -3
  76. data/lib/lono/param.rb +12 -11
  77. data/lib/lono/param/generator.rb +96 -42
  78. data/lib/lono/project_checker.rb +27 -8
  79. data/lib/lono/s3.rb +23 -0
  80. data/lib/lono/s3/bucket.rb +123 -0
  81. data/lib/lono/script.rb +4 -8
  82. data/lib/lono/script/base.rb +7 -2
  83. data/lib/lono/script/build.rb +7 -8
  84. data/lib/lono/script/upload.rb +4 -20
  85. data/lib/lono/sequence.rb +19 -16
  86. data/lib/lono/setting.rb +19 -27
  87. data/lib/lono/template.rb +22 -26
  88. data/lib/lono/template/base.rb +13 -0
  89. data/lib/lono/template/context.rb +4 -56
  90. data/lib/lono/template/context/loader.rb +70 -0
  91. data/lib/lono/template/dsl.rb +15 -151
  92. data/lib/lono/template/dsl/builder.rb +60 -0
  93. data/lib/lono/template/dsl/builder/base.rb +14 -0
  94. data/lib/lono/template/dsl/builder/condition.rb +26 -0
  95. data/lib/lono/template/dsl/builder/fn.rb +114 -0
  96. data/lib/lono/template/dsl/builder/helper.rb +64 -0
  97. data/lib/lono/template/dsl/builder/mapping.rb +24 -0
  98. data/lib/lono/template/dsl/builder/output.rb +37 -0
  99. data/lib/lono/template/dsl/builder/parameter.rb +39 -0
  100. data/lib/lono/template/dsl/builder/resource.rb +38 -0
  101. data/lib/lono/template/dsl/builder/section.rb +12 -0
  102. data/lib/lono/template/dsl/builder/syntax.rb +58 -0
  103. data/lib/lono/template/erb.rb +82 -0
  104. data/lib/lono/template/evaluate.rb +39 -0
  105. data/lib/lono/template/generator.rb +29 -0
  106. data/lib/lono/template/helper.rb +7 -29
  107. data/lib/lono/template/post_processor.rb +69 -0
  108. data/lib/lono/template/template.rb +4 -9
  109. data/lib/lono/template/upload.rb +103 -133
  110. data/lib/lono/template/util.rb +48 -0
  111. data/lib/lono/upgrade.rb +5 -3
  112. data/lib/lono/upgrade/upgrade5.rb +55 -0
  113. data/lib/lono/user_data.rb +4 -4
  114. data/lib/lono/version.rb +1 -1
  115. data/lib/templates/blueprint/%blueprint_name%.gemspec.tt +44 -0
  116. data/lib/templates/blueprint/.gitignore +14 -0
  117. data/lib/templates/blueprint/.lono/config.yml.tt +3 -0
  118. data/lib/templates/blueprint/.meta/config.yml.tt +3 -0
  119. data/lib/templates/blueprint/CHANGELOG.md +7 -0
  120. data/lib/templates/blueprint/Gemfile +4 -0
  121. data/lib/templates/blueprint/README.md +37 -0
  122. data/lib/templates/blueprint/Rakefile +6 -0
  123. data/lib/templates/blueprint/setup/configs.rb +54 -0
  124. data/lib/templates/blueprint_configs/configs/%blueprint_name%/params/base.txt +2 -0
  125. data/lib/{starter_projects/skeleton/app/definitions/base.rb → templates/blueprint_configs/configs/%blueprint_name%/params/development.txt} +0 -0
  126. data/lib/templates/blueprint_configs/configs/%blueprint_name%/variables/base.rb +2 -0
  127. data/lib/templates/blueprint_configs/configs/%blueprint_name%/variables/development.rb +0 -0
  128. data/lib/templates/blueprint_types/dsl/app/templates/%blueprint_name%.rb +37 -0
  129. data/lib/templates/blueprint_types/dsl/app/user_data/bootstrap.sh +2 -0
  130. data/lib/templates/blueprint_types/erb/app/definitions/base.rb.tt +1 -0
  131. data/lib/templates/blueprint_types/erb/app/templates/%blueprint_name%.yml +8 -0
  132. data/lib/{starter_projects/autoscaling → templates/skeleton}/.gitignore +1 -0
  133. data/lib/templates/skeleton/Gemfile +3 -0
  134. data/lib/{starter_projects/autoscaling → templates/skeleton}/Guardfile +2 -2
  135. data/lib/templates/skeleton/README.md +58 -0
  136. data/lib/templates/skeleton/configs/settings.yml +17 -0
  137. data/lib/templates/upgrade5/blueprints/main/.lono/config.yml +3 -0
  138. data/lib/templates/upgrade5/blueprints/main/.meta/config.yml +3 -0
  139. data/lono.gemspec +12 -8
  140. data/vendor/cfn-status/CHANGELOG.md +10 -0
  141. data/vendor/cfn-status/Gemfile +4 -0
  142. data/vendor/cfn-status/LICENSE.txt +21 -0
  143. data/vendor/cfn-status/README.md +56 -0
  144. data/vendor/cfn-status/Rakefile +6 -0
  145. data/vendor/cfn-status/bin/console +14 -0
  146. data/vendor/cfn-status/bin/setup +8 -0
  147. data/vendor/cfn-status/cfn-status.gemspec +30 -0
  148. data/vendor/cfn-status/lib/cfn-status.rb +1 -0
  149. data/vendor/cfn-status/lib/cfn/aws_service.rb +51 -0
  150. data/vendor/cfn-status/lib/cfn/status.rb +219 -0
  151. data/vendor/cfn-status/lib/cfn/status/version.rb +5 -0
  152. data/vendor/cfn-status/spec/cfn/status_spec.rb +81 -0
  153. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-complete.json +1080 -0
  154. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-in-progress.json +1080 -0
  155. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-update-rollback-complete.json +1086 -0
  156. data/vendor/cfn-status/spec/spec_helper.rb +14 -0
  157. data/vendor/cfn_camelizer/CHANGELOG.md +20 -0
  158. data/vendor/cfn_camelizer/Gemfile +4 -0
  159. data/vendor/cfn_camelizer/LICENSE.txt +21 -0
  160. data/vendor/cfn_camelizer/README.md +40 -0
  161. data/vendor/cfn_camelizer/Rakefile +6 -0
  162. data/vendor/cfn_camelizer/bin/console +14 -0
  163. data/vendor/cfn_camelizer/bin/setup +8 -0
  164. data/vendor/cfn_camelizer/cfn_camelizer.gemspec +32 -0
  165. data/vendor/cfn_camelizer/lib/camelizer.yml +37 -0
  166. data/vendor/cfn_camelizer/lib/cfn_camelizer.rb +94 -0
  167. data/vendor/cfn_camelizer/lib/cfn_camelizer/version.rb +3 -0
  168. data/vendor/cfn_camelizer/spec/cfn_camelizer_spec.rb +86 -0
  169. data/vendor/cfn_camelizer/spec/spec_helper.rb +14 -0
  170. metadata +189 -62
  171. data/.circleci/bin/commit_docs.sh +0 -26
  172. data/.circleci/config.yml +0 -72
  173. data/bin/release +0 -9
  174. data/lib/lono/help/import.md +0 -54
  175. data/lib/lono/importer.rb +0 -134
  176. data/lib/lono/new/message.rb +0 -35
  177. data/lib/starter_projects/autoscaling/Gemfile +0 -3
  178. data/lib/starter_projects/autoscaling/README.md +0 -118
  179. data/lib/starter_projects/autoscaling/app/definitions/base.rb +0 -2
  180. data/lib/starter_projects/autoscaling/app/templates/autoscaling.yml +0 -682
  181. data/lib/starter_projects/autoscaling/config/params/base/autoscaling.txt +0 -6
  182. data/lib/starter_projects/autoscaling/config/settings.yml +0 -33
  183. data/lib/starter_projects/ec2/.gitignore +0 -2
  184. data/lib/starter_projects/ec2/Gemfile +0 -3
  185. data/lib/starter_projects/ec2/Guardfile +0 -12
  186. data/lib/starter_projects/ec2/README.md +0 -86
  187. data/lib/starter_projects/ec2/app/definitions/base.rb +0 -2
  188. data/lib/starter_projects/ec2/app/definitions/development.rb +0 -1
  189. data/lib/starter_projects/ec2/app/definitions/production.rb +0 -1
  190. data/lib/starter_projects/ec2/app/helpers/my_custom_helper.rb +0 -17
  191. data/lib/starter_projects/ec2/app/partials/user_data/bootstrap.sh +0 -4
  192. data/lib/starter_projects/ec2/app/templates/example.yml +0 -430
  193. data/lib/starter_projects/ec2/config/params/base/example.txt +0 -2
  194. data/lib/starter_projects/ec2/config/params/development/example.txt +0 -3
  195. data/lib/starter_projects/ec2/config/params/production/example.txt +0 -2
  196. data/lib/starter_projects/ec2/config/settings.yml +0 -33
  197. data/lib/starter_projects/ec2/config/variables/base.rb +0 -3
  198. data/lib/starter_projects/ec2/config/variables/development.rb +0 -2
  199. data/lib/starter_projects/ec2/config/variables/production.rb +0 -2
  200. data/lib/starter_projects/ec2/welcome.txt +0 -8
  201. data/lib/starter_projects/skeleton/.gitignore +0 -2
  202. data/lib/starter_projects/skeleton/Gemfile +0 -3
  203. data/lib/starter_projects/skeleton/Guardfile +0 -12
  204. data/lib/starter_projects/skeleton/README.md +0 -53
  205. data/lib/starter_projects/skeleton/config/settings.yml +0 -33
  206. data/lib/starter_projects/skeleton/welcome.txt +0 -7
  207. data/vendor/plissken/Gemfile +0 -14
  208. data/vendor/plissken/LICENSE.txt +0 -20
  209. data/vendor/plissken/README.md +0 -46
  210. data/vendor/plissken/Rakefile +0 -56
  211. data/vendor/plissken/VERSION +0 -1
  212. data/vendor/plissken/lib/plissken.rb +0 -1
  213. data/vendor/plissken/lib/plissken/ext/hash/to_snake_keys.rb +0 -45
  214. data/vendor/plissken/plissken.gemspec +0 -61
  215. data/vendor/plissken/spec/lib/to_snake_keys_spec.rb +0 -177
  216. data/vendor/plissken/spec/spec_helper.rb +0 -90
  217. data/vendor/plissken/test/helper.rb +0 -20
  218. data/vendor/plissken/test/plissken/ext/hash/to_snake_keys_test.rb +0 -184
  219. data/vendor/plissken/test/test_plissken.rb +0 -2
@@ -0,0 +1,17 @@
1
+ # More info: http://lono.cloud/docs/settings/
2
+ # The base config is specially treated. It gets included the other environments automatically.
3
+ # Yaml also directly supports merging with & and <<* syntax but doing it automatically
4
+ # for a cleaner syntax.
5
+ base:
6
+ # http://lono.cloud/docs/app-scripts/
7
+ # extract_scripts:
8
+ # to: "/opt"
9
+ # as: "ec2-user"
10
+
11
+ development:
12
+ # The aws_profile tightly binds LONO_ENV to AWS_PROFILE and vice-versa.
13
+ # aws_profile: dev_profile
14
+
15
+ production:
16
+ # The aws_profile tightly binds LONO_ENV to AWS_PROFILE and vice-versa.
17
+ # aws_profile: prod_profile
@@ -0,0 +1,3 @@
1
+ ---
2
+ blueprint_name: main
3
+ template_type: erb
@@ -0,0 +1,3 @@
1
+ ---
2
+ blueprint_name: main
3
+ template_type: erb
@@ -4,8 +4,8 @@ require_relative "lib/lono/version"
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Tung Nguyen"]
6
6
  gem.email = ["tongueroo@gmail.com"]
7
- gem.summary = "Lono is a CloudFormation Framework Tool"
8
- gem.homepage = "http://github.com/tongueroo/lono"
7
+ gem.summary = "Powerful CloudFormation Framework"
8
+ gem.homepage = "https://lono.cloud"
9
9
 
10
10
  vendor_files = Dir.glob("vendor/**/*")
11
11
  gem_files = `git ls-files -z`.split("\x0").reject do |f|
@@ -18,26 +18,30 @@ Gem::Specification.new do |gem|
18
18
  gem.name = "lono"
19
19
  gem.require_paths = ["lib"]
20
20
  gem.version = Lono::VERSION
21
- gem.license = "MIT"
21
+ gem.license = "https://boltops.com/boltops-community-license"
22
22
 
23
23
  gem.add_dependency "activesupport"
24
+ gem.add_dependency "awesome_print"
24
25
  gem.add_dependency "aws-sdk-cloudformation"
26
+ gem.add_dependency "aws-sdk-ec2" # lono configure
27
+ gem.add_dependency "aws-sdk-iam" # lono configure
25
28
  gem.add_dependency "aws-sdk-s3"
29
+ # gem.add_dependency "cfn_camelizer" # use vendor/cfn_camelizer instead for now
26
30
  gem.add_dependency "filesize"
27
- gem.add_dependency "graph" # lono graph command dependency
31
+ gem.add_dependency "graph" # lono xgraph command dependency
28
32
  gem.add_dependency "guard"
29
33
  gem.add_dependency "guard-cloudformation"
30
- gem.add_dependency "guard-lono"
34
+ # gem.add_dependency "guard-lono" # TODO: create guard gem
31
35
  gem.add_dependency "hashie"
32
36
  gem.add_dependency "json"
33
37
  gem.add_dependency "memoist"
38
+ gem.add_dependency "parslet"
39
+ gem.add_dependency "plissken"
34
40
  gem.add_dependency "rainbow"
35
41
  gem.add_dependency "rb-fsevent"
36
42
  gem.add_dependency "render_me_pretty"
37
43
  gem.add_dependency "thor"
38
- # gem.add_dependency "plissken" # dependency for vendor/lono-params
39
- # using the vendor fork version: https://github.com/tongueroo/plissken
40
- # until https://github.com/futurechimp/plissken/pull/6 gets merged
44
+ gem.add_dependency "zeitwerk"
41
45
 
42
46
  gem.add_development_dependency "byebug"
43
47
  gem.add_development_dependency "cli_markdown"
@@ -0,0 +1,10 @@
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
+ ## [0.2.0]
7
+ - allow require "cfn-status" to work also
8
+
9
+ ## [0.1.0]
10
+ - 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 = Cfn::Status.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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cfn/status/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cfn-status"
8
+ spec.version = Cfn::Status::VERSION
9
+ spec.authors = ["Tung Nguyen"]
10
+ spec.email = ["tongueroo@gmail.com"]
11
+
12
+ spec.summary = "CloudFormation status library"
13
+ spec.homepage = "https://github.com/tongueroo/cfn-status"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "aws-sdk-cloudformation"
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
@@ -0,0 +1 @@
1
+ require "cfn/status"
@@ -0,0 +1,51 @@
1
+ require "aws-sdk-cloudformation"
2
+
3
+ module Cfn
4
+ module AwsService
5
+ def cfn
6
+ @cfn ||= Aws::CloudFormation::Client.new
7
+ end
8
+
9
+ def stack_exists?(stack_name)
10
+ return true if ENV['TEST']
11
+ return false if @options[:noop]
12
+
13
+ exist = nil
14
+ begin
15
+ # When the stack does not exist an exception is raised. Example:
16
+ # Aws::CloudFormation::Errors::ValidationError: Stack with id blah does not exist
17
+ cfn.describe_stacks(stack_name: stack_name)
18
+ exist = true
19
+ rescue Aws::CloudFormation::Errors::ValidationError => e
20
+ if e.message =~ /does not exist/
21
+ exist = false
22
+ elsif e.message.include?("'stackName' failed to satisfy constraint")
23
+ # Example of e.message when describe_stack with invalid stack name
24
+ # "1 validation error detected: Value 'instance_and_route53' at 'stackName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z][-a-zA-Z0-9]*|arn:[-a-zA-Z0-9:/._+]*"
25
+ puts "Invalid stack name: #{stack_name}"
26
+ puts "Full error message: #{e.message}"
27
+ exit 1
28
+ else
29
+ raise # re-raise exception because unsure what other errors can happen
30
+ end
31
+ end
32
+ exist
33
+ end
34
+
35
+ def find_stack(stack_name)
36
+ resp = cfn.describe_stacks(stack_name: stack_name)
37
+ resp.stacks.first
38
+ rescue Aws::CloudFormation::Errors::ValidationError => e
39
+ # example: Stack with id demo-web does not exist
40
+ if e.message =~ /Stack with/ && e.message =~ /does not exist/
41
+ nil
42
+ else
43
+ raise
44
+ end
45
+ end
46
+
47
+ def rollback_complete?(stack)
48
+ stack.stack_status == 'ROLLBACK_COMPLETE'
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,219 @@
1
+ require "cfn/status/version"
2
+
3
+ module Cfn
4
+ autoload :AwsService, "cfn/aws_service"
5
+
6
+ class Status
7
+ class Error < StandardError; end
8
+
9
+ include AwsService
10
+
11
+ attr_reader :events
12
+ def initialize(stack_name, options={})
13
+ @stack_name = stack_name
14
+ @options = options
15
+ reset
16
+ end
17
+
18
+ def run
19
+ unless stack_exists?(@stack_name)
20
+ puts "The stack #{@stack_name.color(:green)} does not exist."
21
+ return true
22
+ end
23
+
24
+ resp = cfn.describe_stacks(stack_name: @stack_name)
25
+ stack = resp.stacks.first
26
+
27
+ puts "The current status for the stack #{@stack_name.color(:green)} is #{stack.stack_status.color(:green)}"
28
+ if stack.stack_status =~ /_IN_PROGRESS$/
29
+ puts "Stack events (tailing):"
30
+ # tail all events until done
31
+ @hide_time_took = true
32
+ wait
33
+ else
34
+ puts "Stack events:"
35
+ # show the last events that was user initiated
36
+ refresh_events
37
+ show_events(true)
38
+ end
39
+ success?
40
+ end
41
+
42
+ def reset
43
+ @events = [] # constantly replaced with recent events
44
+ @last_shown_event_id = nil
45
+ @stack_deletion_completed = nil
46
+ end
47
+
48
+ # check for /(_COMPLETE|_FAILED)$/ status
49
+ def wait
50
+ puts "Waiting for stack to complete"
51
+ start_time = Time.now
52
+
53
+ refresh_events
54
+ until completed || @stack_deletion_completed
55
+ show_events
56
+ end
57
+ show_events(true) # show the final event
58
+
59
+ if @stack_deletion_completed
60
+ puts "Stack #{@stack_name} deleted."
61
+ return
62
+ end
63
+
64
+ if last_event_status =~ /_FAILED/
65
+ puts "Stack failed: #{last_event_status}".color(:red)
66
+ puts "Stack reason #{@events[0]["resource_status_reason"]}".color(:red)
67
+ elsif last_event_status =~ /_ROLLBACK_/
68
+ puts "Stack rolled back: #{last_event_status}".color(:red)
69
+ else # success
70
+ puts "Stack success status: #{last_event_status}".color(:green)
71
+ end
72
+
73
+ # Never gets here when deleting a stack because the describe stack returns nothing
74
+ # once the stack is deleted. Gets here for stack create and update though.
75
+ return if @hide_time_took # set in run
76
+ took = Time.now - start_time
77
+ puts "Time took for stack deployment: #{pretty_time(took).color(:green)}."
78
+ success?
79
+ end
80
+
81
+ def completed
82
+ last_event_status =~ /(_COMPLETE|_FAILED)$/ &&
83
+ @events[0]["logical_resource_id"] == @stack_name &&
84
+ @events[0]["resource_type"] == "AWS::CloudFormation::Stack"
85
+ end
86
+
87
+ def last_event_status
88
+ @events[0]["resource_status"]
89
+ end
90
+
91
+ # Only shows new events
92
+ def show_events(final=false)
93
+ if @last_shown_event_id.nil?
94
+ i = find_index(:start, final)
95
+ print_events(i)
96
+ else
97
+ i = find_index(:last_shown, final)
98
+ # puts "last_shown index #{i}"
99
+ print_events(i-1) unless i == 0
100
+ end
101
+
102
+ return if final
103
+ sleep 5 unless ENV['TEST']
104
+ refresh_events
105
+ end
106
+
107
+ def print_events(i)
108
+ @events[0..i].reverse.each do |e|
109
+ print_event(e)
110
+ end
111
+ @last_shown_event_id = @events[0]["event_id"]
112
+ # puts "@last_shown_event_id #{@last_shown_event_id.inspect}"
113
+ end
114
+
115
+ def print_event(e)
116
+ message = [
117
+ event_time(e["timestamp"]),
118
+ e["resource_status"],
119
+ e["resource_type"],
120
+ e["logical_resource_id"],
121
+ e["resource_status_reason"]
122
+ ].join(" ")
123
+ message = message.color(:red) if e["resource_status"] =~ /_FAILED/
124
+ puts message
125
+ end
126
+
127
+ # https://stackoverflow.com/questions/18000432/rails-12-hour-am-pm-range-for-a-day
128
+ def event_time(timestamp)
129
+ Time.parse(timestamp.to_s).localtime.strftime("%I:%M:%S%p")
130
+ end
131
+
132
+ # refreshes the loaded events in memory
133
+ def refresh_events
134
+ resp = cfn.describe_stack_events(stack_name: @stack_name)
135
+ @events = resp["stack_events"]
136
+ rescue Aws::CloudFormation::Errors::ValidationError => e
137
+ if e.message =~ /Stack .* does not exis/
138
+ @stack_deletion_completed = true
139
+ else
140
+ raise
141
+ end
142
+ end
143
+
144
+ def find_index(name, final=false)
145
+ send("#{name}_index", final)
146
+ end
147
+
148
+ def start_index(final=false)
149
+ index = @events.find_index do |event|
150
+ event["resource_type"] == "AWS::CloudFormation::Stack" &&
151
+ event["resource_status_reason"] == "User Initiated"
152
+ end
153
+ # Instead of paginating until until we find the first "User Initiated" "AWS::CloudFormation::Stack" event
154
+ # we'll use the max.
155
+ index ? index : @events.size - 1
156
+ end
157
+
158
+ def last_shown_index(_)
159
+ @events.find_index do |event|
160
+ event["event_id"] == @last_shown_event_id
161
+ end
162
+ end
163
+
164
+ def success?
165
+ resource_status = @events[0]["resource_status"]
166
+ %w[CREATE_COMPLETE UPDATE_COMPLETE].include?(resource_status)
167
+ end
168
+
169
+ def update_rollback?
170
+ @events[0]["resource_status"] == "UPDATE_ROLLBACK_COMPLETE"
171
+ end
172
+
173
+ def find_update_failed_event
174
+ i = @events.find_index do |event|
175
+ event["resource_type"] == "AWS::CloudFormation::Stack" &&
176
+ event["resource_status_reason"] == "User Initiated"
177
+ end
178
+
179
+ @events[0..i].reverse.find do |e|
180
+ e["resource_status"] == "UPDATE_FAILED"
181
+ end
182
+ end
183
+
184
+ def rollback_error_message
185
+ return unless update_rollback?
186
+
187
+ event = find_update_failed_event
188
+ return unless event
189
+
190
+ reason = event["resource_status_reason"]
191
+ messages_map.each do |pattern, message|
192
+ if reason =~ pattern
193
+ return message
194
+ end
195
+ end
196
+
197
+ reason # default message is original reason if not found in messages map
198
+ end
199
+
200
+ def messages_map
201
+ {
202
+ /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.",
203
+ /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.",
204
+ /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."
205
+ }
206
+ end
207
+
208
+ # http://stackoverflow.com/questions/4175733/convert-duration-to-hoursminutesseconds-or-similar-in-rails-3-or-ruby
209
+ def pretty_time(total_seconds)
210
+ minutes = (total_seconds / 60) % 60
211
+ seconds = total_seconds % 60
212
+ if total_seconds < 60
213
+ "#{seconds.to_i}s"
214
+ else
215
+ "#{minutes.to_i}m #{seconds.to_i}s"
216
+ end
217
+ end
218
+ end
219
+ end