lono 3.5.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -4
  3. data/.rspec +1 -0
  4. data/CHANGELOG.md +15 -1
  5. data/Gemfile +3 -3
  6. data/Guardfile +17 -8
  7. data/{LICENSE → LICENSE.txt} +1 -1
  8. data/README.md +20 -12
  9. data/Rakefile +1 -2
  10. data/{bin → exe}/lono +1 -0
  11. data/lib/lono.rb +12 -9
  12. data/lib/lono/cfn.rb +7 -9
  13. data/lib/lono/cfn/{aws_services.rb → aws_service.rb} +1 -1
  14. data/lib/lono/cfn/base.rb +41 -38
  15. data/lib/lono/cfn/create.rb +6 -2
  16. data/lib/lono/cfn/delete.rb +2 -2
  17. data/lib/lono/cfn/diff.rb +1 -1
  18. data/lib/lono/cfn/preview.rb +26 -15
  19. data/lib/lono/cfn/update.rb +11 -9
  20. data/lib/lono/cfn/util.rb +3 -3
  21. data/lib/lono/clean.rb +1 -1
  22. data/lib/lono/cli.rb +71 -39
  23. data/lib/lono/command.rb +42 -18
  24. data/lib/lono/completer.rb +162 -0
  25. data/lib/lono/completer/script.rb +6 -0
  26. data/lib/lono/completer/script.sh +10 -0
  27. data/lib/lono/completion.rb +15 -0
  28. data/lib/lono/core.rb +23 -9
  29. data/lib/lono/core/config.rb +20 -0
  30. data/lib/lono/default/settings.yml +33 -13
  31. data/lib/lono/help.rb +6 -79
  32. data/lib/lono/help/cfn.md +6 -0
  33. data/lib/lono/help/cfn/create.md +22 -0
  34. data/lib/lono/help/cfn/delete.md +5 -0
  35. data/lib/lono/help/cfn/diff.md +5 -0
  36. data/lib/lono/help/cfn/download.md +5 -0
  37. data/lib/lono/help/cfn/preview.md +11 -0
  38. data/lib/lono/help/cfn/update.md +21 -0
  39. data/lib/lono/help/completion.md +22 -0
  40. data/lib/lono/help/completion_script.md +3 -0
  41. data/lib/lono/help/generate.md +7 -0
  42. data/lib/lono/help/hello.md +5 -0
  43. data/lib/lono/help/import.md +7 -0
  44. data/lib/lono/help/inspect.md +4 -0
  45. data/lib/lono/help/inspect/depends.md +3 -0
  46. data/lib/lono/help/inspect/summary.md +3 -0
  47. data/lib/lono/help/new.md +8 -0
  48. data/lib/lono/help/param.md +3 -0
  49. data/lib/lono/{param/help.rb → help/param/generate.md} +1 -9
  50. data/lib/lono/help/script/build.md +5 -0
  51. data/lib/lono/help/script/upload.md +8 -0
  52. data/lib/lono/help/template.md +4 -0
  53. data/lib/lono/help/template/bashify.md +4 -0
  54. data/lib/lono/help/template/generate.md +7 -0
  55. data/lib/lono/help/user_data.md +3 -0
  56. data/lib/lono/importer.rb +43 -20
  57. data/lib/lono/inspector.rb +2 -19
  58. data/lib/lono/inspector/base.rb +2 -2
  59. data/lib/lono/inspector/{depends.rb → graph.rb} +3 -3
  60. data/lib/lono/inspector/summary.rb +1 -1
  61. data/lib/lono/new.rb +79 -26
  62. data/lib/lono/new/helper.rb +16 -0
  63. data/lib/lono/new/message.rb +35 -0
  64. data/lib/lono/param.rb +1 -2
  65. data/lib/lono/param/generator.rb +34 -86
  66. data/lib/lono/project_checker.rb +35 -40
  67. data/lib/lono/script.rb +19 -0
  68. data/lib/lono/script/base.rb +9 -0
  69. data/lib/lono/script/build.rb +73 -0
  70. data/lib/lono/script/upload.rb +81 -0
  71. data/lib/lono/sequence.rb +33 -0
  72. data/lib/lono/setting.rb +83 -0
  73. data/lib/lono/template.rb +8 -9
  74. data/lib/lono/template/{aws_services.rb → aws_service.rb} +1 -1
  75. data/lib/lono/template/context.rb +73 -0
  76. data/lib/lono/template/dsl.rb +63 -64
  77. data/lib/lono/template/helper.rb +201 -0
  78. data/lib/lono/template/template.rb +29 -221
  79. data/lib/lono/template/upload.rb +41 -33
  80. data/lib/lono/upgrade4.rb +175 -0
  81. data/lib/lono/user_data.rb +31 -0
  82. data/lib/lono/version.rb +1 -1
  83. data/lib/starter_projects/autoscaling/.gitignore +1 -0
  84. data/lib/starter_projects/{json_project → autoscaling}/Gemfile +0 -0
  85. data/lib/starter_projects/{yaml_project → autoscaling}/Guardfile +0 -0
  86. data/lib/starter_projects/autoscaling/README.md +118 -0
  87. data/lib/starter_projects/autoscaling/app/definitions/base.rb +2 -0
  88. data/lib/starter_projects/autoscaling/app/templates/autoscaling.yml +682 -0
  89. data/lib/starter_projects/autoscaling/config/params/base/autoscaling.txt +6 -0
  90. data/lib/starter_projects/autoscaling/config/settings.yml +33 -0
  91. data/lib/starter_projects/ec2/.gitignore +1 -0
  92. data/lib/starter_projects/{yaml_project → ec2}/Gemfile +0 -0
  93. data/lib/starter_projects/{json_project → ec2}/Guardfile +1 -1
  94. data/lib/starter_projects/ec2/README.md +86 -0
  95. data/lib/starter_projects/ec2/app/definitions/base.rb +2 -0
  96. data/lib/starter_projects/ec2/app/definitions/development.rb +1 -0
  97. data/lib/starter_projects/ec2/app/definitions/production.rb +1 -0
  98. data/lib/starter_projects/{yaml_project → ec2/app}/helpers/my_custom_helper.rb +0 -0
  99. data/lib/starter_projects/{json_project/templates/user_data/app.sh → ec2/app/partials/user_data/bootstrap.sh} +1 -2
  100. data/lib/starter_projects/{yaml_project → ec2/app}/templates/example.yml +0 -0
  101. data/lib/starter_projects/{json_project/params/base/api-web.txt → ec2/config/params/base/example.txt} +0 -0
  102. data/lib/starter_projects/ec2/config/params/development/example.txt +3 -0
  103. data/lib/starter_projects/ec2/config/params/production/example.txt +2 -0
  104. data/lib/starter_projects/ec2/config/settings.yml +33 -0
  105. data/lib/starter_projects/ec2/config/variables/base.rb +3 -0
  106. data/lib/starter_projects/ec2/config/variables/development.rb +2 -0
  107. data/lib/starter_projects/ec2/config/variables/production.rb +2 -0
  108. data/lib/starter_projects/ec2/welcome.txt +8 -0
  109. data/lib/starter_projects/skeleton/.gitignore +1 -0
  110. data/lib/starter_projects/skeleton/Gemfile +3 -0
  111. data/lib/starter_projects/skeleton/Guardfile +12 -0
  112. data/lib/starter_projects/skeleton/README.md +53 -0
  113. data/{spec/fixtures/my_project/templates/.gitkeep → lib/starter_projects/skeleton/app/definitions/base.rb} +0 -0
  114. data/lib/starter_projects/skeleton/config/settings.yml +33 -0
  115. data/lib/starter_projects/skeleton/welcome.txt +7 -0
  116. data/lono.gemspec +12 -10
  117. data/spec/fixtures/lono_project/.gitignore +1 -0
  118. data/spec/fixtures/lono_project/Gemfile +3 -0
  119. data/spec/fixtures/lono_project/Guardfile +12 -0
  120. data/spec/fixtures/lono_project/app/definitions/base.rb +10 -0
  121. data/spec/fixtures/lono_project/app/definitions/base/more.rb +7 -0
  122. data/spec/fixtures/lono_project/app/definitions/development.rb +1 -0
  123. data/spec/fixtures/lono_project/app/definitions/production.rb +1 -0
  124. data/spec/fixtures/lono_project/app/helpers/custom_helper.rb +5 -0
  125. data/spec/fixtures/lono_project/app/partials/security_group.yml +10 -0
  126. data/{lib/starter_projects/yaml_project/templates/partial → spec/fixtures/lono_project/app/partials}/user_data/bootstrap.sh +8 -2
  127. data/spec/fixtures/lono_project/app/templates/example.yml +50 -0
  128. data/{lib/starter_projects/yaml_project/params/base/api-web-prod.txt → spec/fixtures/lono_project/config/params/base/example.txt} +1 -0
  129. data/spec/fixtures/lono_project/config/params/development/example.txt +1 -0
  130. data/spec/fixtures/lono_project/config/params/production/example.txt +1 -0
  131. data/spec/fixtures/lono_project/config/settings.yml +31 -0
  132. data/spec/fixtures/lono_project/config/variables/base.rb +3 -0
  133. data/spec/fixtures/lono_project/config/variables/development.rb +1 -0
  134. data/spec/fixtures/lono_project/config/variables/production.rb +1 -0
  135. data/spec/fixtures/params/envonly/params/{prod → development}/network.txt +0 -0
  136. data/spec/fixtures/params/overlay/params/{prod → development}/network.txt +0 -0
  137. data/spec/fixtures/raw_templates/aws-waf-security-automations.template +2 -2
  138. data/spec/lib/lono/cfn_spec.rb +6 -9
  139. data/spec/lib/lono/cli_spec.rb +44 -0
  140. data/spec/lib/lono/completion_spec.rb +17 -0
  141. data/spec/lib/lono/inspect_spec.rb +6 -15
  142. data/spec/lib/lono/param/generator_spec.rb +45 -26
  143. data/spec/lib/lono/param_spec.rb +1 -3
  144. data/spec/lib/lono/setting_spec.rb +47 -0
  145. data/spec/lib/lono/template/dsl_spec.rb +33 -157
  146. data/spec/lib/lono/template_spec.rb +4 -16
  147. data/spec/spec_helper.rb +45 -14
  148. metadata +168 -82
  149. data/.coveralls.yml +0 -1
  150. data/lib/lono/cfn/help.rb +0 -103
  151. data/lib/lono/current_region.rb +0 -42
  152. data/lib/lono/inspector/help.rb +0 -21
  153. data/lib/lono/settings.rb +0 -45
  154. data/lib/lono/template/help.rb +0 -25
  155. data/lib/lono/template/helpers.rb +0 -136
  156. data/lib/starter_projects/json_project/.gitignore +0 -1
  157. data/lib/starter_projects/json_project/config/templates/base/blog.rb +0 -20
  158. data/lib/starter_projects/json_project/config/templates/base/stacks.rb +0 -58
  159. data/lib/starter_projects/json_project/templates/db.json +0 -212
  160. data/lib/starter_projects/json_project/templates/partial/host_record.json +0 -28
  161. data/lib/starter_projects/json_project/templates/partial/server.json +0 -45
  162. data/lib/starter_projects/json_project/templates/user_data/db.sh +0 -39
  163. data/lib/starter_projects/json_project/templates/user_data/db2.sh +0 -2
  164. data/lib/starter_projects/json_project/templates/user_data/ruby_script.rb +0 -5
  165. data/lib/starter_projects/json_project/templates/web.json +0 -386
  166. data/lib/starter_projects/yaml_project/.gitignore +0 -1
  167. data/lib/starter_projects/yaml_project/config/templates/base/blog.rb +0 -20
  168. data/lib/starter_projects/yaml_project/config/templates/base/stacks.rb +0 -56
  169. data/lib/starter_projects/yaml_project/config/templates/prod/stacks.rb +0 -1
  170. data/lib/starter_projects/yaml_project/config/templates/stag/stacks.rb +0 -1
  171. data/lib/starter_projects/yaml_project/config/variables/base/variables.rb +0 -4
  172. data/lib/starter_projects/yaml_project/config/variables/prod/variables.rb +0 -1
  173. data/lib/starter_projects/yaml_project/config/variables/stag/variables.rb +0 -1
  174. data/lib/starter_projects/yaml_project/params/base/example.txt +0 -2
  175. data/lib/starter_projects/yaml_project/params/prod/example.txt +0 -1
  176. data/lib/starter_projects/yaml_project/params/stag/example.txt +0 -1
  177. data/lib/starter_projects/yaml_project/templates/db.yml +0 -148
  178. data/lib/starter_projects/yaml_project/templates/partial/host_record.yml +0 -14
  179. data/lib/starter_projects/yaml_project/templates/partial/server.yml +0 -59
  180. data/lib/starter_projects/yaml_project/templates/web.yml +0 -206
  181. data/spec/fixtures/my_project/config/templates/base/stacks.rb +0 -3
  182. data/spec/fixtures/my_project/params/my-stack.txt +0 -3
  183. data/spec/fixtures/my_project/templates/my-stack.yml +0 -0
  184. data/spec/lib/lono/new_spec.rb +0 -59
  185. data/spec/lib/lono/template/template_spec.rb +0 -104
  186. data/spec/lib/lono_spec.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea871b8860abb2c1fbfc39edeae04a90c43f46780dd8fd4c37a1b97ca6480370
4
- data.tar.gz: d52b9f70968c615adb50d16b3c84327b2300123b049a48abfa3affd2e5d6699a
3
+ metadata.gz: 813d3d801fda95c8b91d3664909e105efa0233aa589324dd8480ff70d8364e83
4
+ data.tar.gz: 47425854afafa70350676c4e2a8af6b409c10f272d0547e679d45bec168ed0e5
5
5
  SHA512:
6
- metadata.gz: 93bff1d68869ca94ba8ddc8014ceef8f403962d3f0f04261a6461c76e5e354fd2780e8c50e0a1cdcdb458ef5820ee2683014249a163b4d13e7a3f2e4afe0483b
7
- data.tar.gz: cf812cbf0e9eb23190ddeb615d5d7471bcd19ea31b1094e80ec642ac3b04fa15a2123c8cf43431cf1e8331d41ae3b34e4bbd665167d7fbced8a22c4717a76526
6
+ metadata.gz: c8c3bcc99b77b005f58d93d6893e44e74badf2bb86dc44dda78d0d364f003c4473a847ad7875ccbd9fac77177e884214dfdd0c546e80b0d5e9013a4652bacf2a
7
+ data.tar.gz: '049cebb1112d4ddacbe892965b615fffd93b0fc96ced048aae471d4798d42852f544f3a2ba51989ea711a88661cb3ccb76104afac4c5e204cf21efe52f7736b4'
data/.gitignore CHANGED
@@ -1,10 +1,21 @@
1
- .DS_Store
2
1
  *.gem
2
+ *.rbc
3
3
  .bundle
4
+ .config
5
+ .DS_Store
6
+ .yardoc
7
+ _yardoc
4
8
  coverage
9
+ doc/
5
10
  Gemfile.lock
6
- pkg
7
- tmp
11
+ InstalledFiles
12
+ lib/bundler/man
8
13
  output
9
- spec/project
14
+ pkg
15
+ rdoc
10
16
  spec/fixtures/my_project/templates/aws-waf-security-automations.yml
17
+ spec/project
18
+ spec/reports
19
+ test/tmp
20
+ test/version_tmp
21
+ tmp
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --format documentation
3
+ --require spec_helper
data/CHANGELOG.md CHANGED
@@ -3,6 +3,20 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [4.0.0]
7
+ - lono upgrade4 command
8
+ - simplified lono project structure
9
+ - app/scripts upload support and extract_scripts helper
10
+ - new settings.yml format: environment support, simplified s3_folder and aws_profiles options
11
+ - revamped starter projects
12
+ - added focus to lono import flow
13
+ - move lono summary up to top-level cli
14
+ - cli auto-completion support
15
+ - improved YAML parse error: shows error line immediately to user of output template
16
+ - better ERB template error rendering with render_me_pretty gem
17
+ - remove json support. focus on yaml.
18
+ - lono user_data command
19
+
6
20
  ## [3.5.0]
7
21
  - Using Lono.root instead of scattered project_root parameters
8
22
  - prefer use of Lono.env over LONO_ENV internally
@@ -65,7 +79,7 @@ This project *tries* to adhere to [Semantic Versioning](http://semver.org/), eve
65
79
  - Format and Extension Detection
66
80
  - Custom Helper Support
67
81
  - Source Name Convention Support
68
- - Settings File Support
82
+ - Setting File Support
69
83
 
70
84
  ## [2.1.0]
71
85
  - improve instance_eval error when lono.rb errors, print out line of code and context
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
+
3
+ # Specify your gem dependencies in lono.gemspec
2
4
  gemspec
3
5
 
4
- group :development do
5
- gem 'coveralls', require: false
6
- end
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/Guardfile CHANGED
@@ -1,10 +1,19 @@
1
- guard 'bundler' do
2
- watch('Gemfile')
1
+ guard "bundler", cmd: "bundle" do
2
+ watch("Gemfile")
3
+ watch(/^.+\.gemspec/)
3
4
  end
4
5
 
5
- guard 'rspec' do
6
- watch(%r{^spec/.+_spec\.rb$})
7
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
8
- watch(%r{^lib/.*/(.+)\.rb$}) { |m| "spec/lib/lono_spec.rb" }
9
- # watch('spec/spec_helper.rb') { "spec" }
10
- end
6
+ guard :rspec, cmd: "bundle exec rspec" do
7
+ require "guard/rspec/dsl"
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2017 Tung Nguyen
1
+ Copyright (c) 2018 Tung Nguyen
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <div align="center">
2
+ <img src="http://lono.cloud/img/logos/lono-logo.png" style="max-width: 300px" />
3
+ </div>
4
+
1
5
  # Lono
2
6
 
3
7
  [![Gem Version](https://badge.fury.io/rb/lono.png)](http://badge.fury.io/rb/lono)
@@ -11,14 +15,20 @@
11
15
  [3]: https://codeclimate.com/repos/51d7f1407e00a4042c010ab4/badges/5273fe6cdb5a13e58554/gpa.png
12
16
  [4]: https://codeclimate.com/repos/51d7f1407e00a4042c010ab4/feed
13
17
 
14
- Lono is a tool to help you easily manage your CloudFormation templates. Lono handles the entire CloudFormation lifecyle. It starts with helping you craft of the templates and helps you all the way to end when you provision of the infrastructure.
18
+ Lono is a tool to help you manage your CloudFormation templates. Lono handles the entire CloudFormation lifecyle. It helps you craft the templates and then provisions of the infrastructure.
15
19
 
16
- * Lono generates CloudFormation templates based on ERB ruby templates in either `yaml` or `json` format.
17
- * Lono takes simple env-like files to and generates the CloudFormation parameter files.
18
- * Lono wraps the CloudFormation api calls in a simple interface using the generated files to launch the CloudFormation stacks.
20
+ * Lono generates CloudFormation templates based on ERB ruby templates in `yaml` format.
21
+ * Lono takes simple env-like files and generates the CloudFormation parameter files.
22
+ * Lono provides a simple CLI interface to launch the CloudFormation stacks.
19
23
 
20
24
  See [lono.cloud](http://lono.cloud) for full lono documentation.
21
25
 
26
+ ## Important
27
+
28
+ If you are on version 3, you can run `lono upgrade4` within your project to upgrade it to version 4. Refer to the [CHANGELOG](CHANGELOG.md).
29
+
30
+ ## Blog Posts
31
+
22
32
  These blog posts also cover lono:
23
33
 
24
34
  * [Why Generate CloudFormation Templates with Lono](https://medium.com/boltops/why-generate-cloudformation-templates-with-lono-65b8ea5eb87d)
@@ -35,23 +45,21 @@ It only takes a couple of commands to start using lono.
35
45
  gem install lono
36
46
  lono new infra
37
47
  cd infra
38
- lono generate # not needed but showing for explanation
39
- lono cfn create example
48
+ lono import https://s3-us-west-2.amazonaws.com/cloudformation-templates-us-west-2/EC2InstanceWithSecurityGroupSample.template --name ec2
49
+ # update the generated params file
50
+ lono cfn create ec2
40
51
  ```
41
-
42
- This sets up a starter lono project called infra with example templates. You cd into the folder and call `lono cfn create` which automatically generates the CloudFormation template and parameter files to `output` and `output/params` and launches the stack.
43
-
44
52
  ![Lono flowchart](http://tongueroo.com/images/github-readmes/lono-flowchart.png "Lono flowchart")
45
53
 
46
- ### lono cfn summary
54
+ ### Lono Cfn Lifecycle Commands
47
55
 
48
- Lono also provides a `lono cfn` management command that allows you to launch stacks from the lono templates. The `lono cfn` tool automatically runs `lono generate` internally and then launches the CloudFormation stack all in one command. Provided that you are in a lono project and have a `my-stack` lono template definition. To create a stack you can simply run:
56
+ Lono provides a `lono cfn` lifecycle command that allows you to launch stacks quickly. The `lono cfn` tool automatically runs `lono generate` internally and then launches the CloudFormation stack all in one command. If you are in a lono project and have a `my-stack` lono template definition. To create a stack you can simply run:
49
57
 
50
58
  ```
51
59
  $ lono cfn create my-stack
52
60
  ```
53
61
 
54
- The above command will generate files to `output/my-stack.json` and `output/params/my-stack.txt` and use them to create a CloudFormation stack. Here are some more examples of cfn commands:
62
+ The above command will generate files to `output/templates/my-stack.json` and `output/params/my-stack.txt` and use them to create a CloudFormation stack. Here are some more examples of cfn commands:
55
63
 
56
64
  ```
57
65
  $ lono cfn create mystack-$(date +%Y%m%d%H%M%S) --template mystack --params mystack
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
- #!/usr/bin/env rake
2
1
  require "bundler/gem_tasks"
3
2
  require "rspec/core/rake_task"
4
3
 
5
- task default: :spec
4
+ task :default => :spec
6
5
 
7
6
  RSpec::Core::RakeTask.new
data/{bin → exe}/lono RENAMED
@@ -6,5 +6,6 @@ Signal.trap("INT") {
6
6
  sleep 1
7
7
  exit
8
8
  }
9
+
9
10
  require_relative "../lib/lono"
10
11
  Lono::CLI.start
data/lib/lono.rb CHANGED
@@ -1,10 +1,10 @@
1
- require 'json'
2
- require 'yaml'
3
- require 'pp'
1
+ require 'active_support/core_ext/string'
4
2
  require 'colorize'
5
3
  require 'fileutils'
6
- # http://guides.rubyonrails.org/active_support_core_extensions.html#inflections
7
- require 'active_support/core_ext/string'
4
+ require 'json'
5
+ require 'pp'
6
+ require 'render_me_pretty'
7
+ require 'yaml'
8
8
 
9
9
  # vendor because need https://github.com/futurechimp/plissken/pull/6 to be merged
10
10
  $:.unshift(File.expand_path("../../vendor/plissken/lib", __FILE__))
@@ -19,17 +19,20 @@ module Lono
19
19
  autoload :Command, 'lono/command'
20
20
  autoload :CLI, 'lono/cli'
21
21
  autoload :New, 'lono/new'
22
+ autoload :Sequence, 'lono/sequence'
22
23
  autoload :Template, 'lono/template'
23
24
  autoload :Cfn, 'lono/cfn'
24
25
  autoload :Param, 'lono/param'
25
26
  autoload :Clean, 'lono/clean'
26
- autoload :Settings, 'lono/settings'
27
+ autoload :Setting, 'lono/setting'
27
28
  autoload :Importer, 'lono/importer'
28
29
  autoload :Inspector, 'lono/inspector'
29
- autoload :CurrentRegion, 'lono/current_region'
30
+ autoload :Completion, 'lono/completion'
31
+ autoload :Completer, 'lono/completer'
30
32
  autoload :Core, 'lono/core'
33
+ autoload :Upgrade4, 'lono/upgrade4'
34
+ autoload :Script, 'lono/script'
35
+ autoload :UserData, 'lono/user_data'
31
36
 
32
37
  extend Core
33
38
  end
34
-
35
- Lono.setup!
data/lib/lono/cfn.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  require "thor"
2
2
 
3
3
  class Lono::Cfn < Lono::Command
4
- autoload :Help, 'lono/cfn/help'
5
- autoload :AwsServices, 'lono/cfn/aws_services'
4
+ autoload :AwsService, 'lono/cfn/aws_service'
6
5
  autoload :Util, 'lono/cfn/util'
7
6
  autoload :CLI, 'lono/cfn/cli'
8
7
  autoload :Base, 'lono/cfn/base'
@@ -21,20 +20,19 @@ class Lono::Cfn < Lono::Command
21
20
  class_option :template, desc: "override convention and specify the template file to use"
22
21
  class_option :param, desc: "override convention and specify the param file to use"
23
22
  class_option :lono, type: :boolean, desc: "invoke lono to generate CloudFormation templates", default: true
24
- class_option :s3_upload, type: :boolean, desc: "uploads templates to s3 if s3.path detected", default: true
25
23
  class_option :capabilities, type: :array, desc: "iam capabilities. Ex: CAPABILITY_IAM, CAPABILITY_NAMED_IAM"
26
24
  class_option :iam, type: :boolean, desc: "Shortcut for common IAM capabilities: CAPABILITY_IAM, CAPABILITY_NAMED_IAM"
27
25
  class_option :rollback, type: :boolean, desc: "rollback", default: true
28
26
 
29
27
  desc "create STACK", "create a CloudFormation stack"
30
28
  option :randomize_stack_name, type: :boolean, desc: "tack on random string at the end of the stack name", default: nil
31
- long_desc Help.create
29
+ long_desc Lono::Help.text("cfn/create")
32
30
  def create(name)
33
31
  Create.new(name, options).run
34
32
  end
35
33
 
36
34
  desc "update STACK", "update a CloudFormation stack"
37
- long_desc Help.update
35
+ long_desc Lono::Help.text("cfn/update")
38
36
  option :change_set, type: :boolean, default: true, desc: "Uses generated change set to update the stack. If false, will perform normal update-stack."
39
37
  option :diff, type: :boolean, default: true, desc: "Show diff of the source code template changes before continuing."
40
38
  option :preview, type: :boolean, default: true, desc: "Show preview of the stack changes before continuing."
@@ -44,14 +42,14 @@ class Lono::Cfn < Lono::Command
44
42
  end
45
43
 
46
44
  desc "delete STACK", "delete a CloudFormation stack"
47
- long_desc Help.delete
45
+ long_desc Lono::Help.text("cfn/delete")
48
46
  option :sure, type: :boolean, desc: "Skips are you sure prompt"
49
47
  def delete(name)
50
48
  Delete.new(name, options).run
51
49
  end
52
50
 
53
51
  desc "preview STACK", "preview a CloudFormation stack update"
54
- long_desc Help.preview
52
+ long_desc Lono::Help.text("cfn/preview")
55
53
  option :keep, type: :boolean, desc: "keep the changeset instead of deleting it afterwards"
56
54
  option :diff, type: :boolean, default: true, desc: "Show diff of the source code template changes also."
57
55
  def preview(name)
@@ -60,13 +58,13 @@ class Lono::Cfn < Lono::Command
60
58
  end
61
59
 
62
60
  desc "diff STACK", "diff of newly generated template vs existing template in AWS"
63
- long_desc Help.diff
61
+ long_desc Lono::Help.text("cfn/diff")
64
62
  def diff(name)
65
63
  Diff.new(name, options).run
66
64
  end
67
65
 
68
66
  desc "download STACK", "download CloudFormation template from existing stack"
69
- long_desc Help.download
67
+ long_desc Lono::Help.text("cfn/download")
70
68
  option :name, desc: "Name you want to save the template as. Default: existing stack name."
71
69
  def download(stack_name)
72
70
  Download.new(stack_name, options).run
@@ -1,6 +1,6 @@
1
1
  require "aws-sdk-cloudformation"
2
2
 
3
- module Lono::Cfn::AwsServices
3
+ module Lono::Cfn::AwsService
4
4
  def cfn
5
5
  @cfn ||= Aws::CloudFormation::Client.new
6
6
  end
data/lib/lono/cfn/base.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "lono"
2
2
 
3
3
  class Lono::Cfn::Base
4
- include Lono::Cfn::AwsServices
4
+ include Lono::Cfn::AwsService
5
5
  include Lono::Cfn::Util
6
6
 
7
7
  attr_reader :randomize_stack_name
@@ -42,7 +42,7 @@ class Lono::Cfn::Base
42
42
  puts " #{command_with_iam(capabilities)}"
43
43
 
44
44
  puts "Please confirm (y/n)"
45
- confirm = $stdin.gets
45
+ $stdin.gets
46
46
  end
47
47
 
48
48
  def command_with_iam(capabilities)
@@ -51,24 +51,35 @@ class Lono::Cfn::Base
51
51
 
52
52
  def generate_all
53
53
  if @options[:lono]
54
+ build_scripts
54
55
  generate_templates
55
- upload_templates if @options[:s3_upload] and !@options[:noop]
56
+ unless @options[:noop]
57
+ upload_scripts
58
+ upload_templates
59
+ end
56
60
  end
57
61
  params = generate_params(mute: @options[:mute_params])
58
62
  check_for_errors
59
63
  params
60
64
  end
61
65
 
66
+ def build_scripts
67
+ Lono::Script::Build.new.run
68
+ end
69
+
62
70
  def generate_templates
63
- Lono::Template::DSL.new(pretty: true).run
71
+ Lono::Template::DSL.new.run
64
72
  end
65
73
 
74
+ # only upload templates if s3_folder configured in settings
66
75
  def upload_templates
67
- # only upload templates if s3.path configured in settings
68
- settings = Lono::Settings.new
69
- return unless settings.s3_path
76
+ Lono::Template::Upload.new.run if s3_folder
77
+ end
70
78
 
71
- Lono::Template::Upload.new(pretty: true).run
79
+ # only upload templates if s3_folder configured in settings
80
+ def upload_scripts
81
+ return unless s3_folder
82
+ Lono::Script::Upload.new.run
72
83
  end
73
84
 
74
85
  def generate_params(options={})
@@ -97,13 +108,13 @@ class Lono::Cfn::Base
97
108
  def check_files
98
109
  errors, warns = [], []
99
110
  unless File.exist?(@template_path)
100
- warns << "Template file missing: could not find #{@template_path}"
111
+ errors << "Template file missing: could not find #{@template_path}"
101
112
  end
102
113
  # Examples:
103
114
  # @param_path = params/prod/ecs.txt
104
115
  # => output/params/prod/ecs.json
105
116
  output_param_path = @param_path.sub(/\.txt/, '.json')
106
- output_param_path = "#{Lono.root}/output/#{output_param_path}"
117
+ output_param_path = "#{Lono.config.output_path}/#{output_param_path}"
107
118
  if @options[:param] && !File.exist?(output_param_path)
108
119
  warns << "Parameters file missing: could not find #{output_param_path}"
109
120
  end
@@ -117,7 +128,7 @@ class Lono::Cfn::Base
117
128
  # Type - :param or :template
118
129
  def get_source_path(path, type)
119
130
  if path.nil?
120
- default_convention_path = convention_path(@stack_name, type)
131
+ convention_path(@stack_name, type) # default convention
121
132
  else
122
133
  # convention path based on the input from the user
123
134
  convention_path(path, type)
@@ -127,36 +138,15 @@ class Lono::Cfn::Base
127
138
  def convention_path(name, type)
128
139
  path = case type
129
140
  when :template
130
- format = detect_format
131
- "#{Lono.root}/output/#{name}.#{format}"
141
+ "#{Lono.config.output_path}/templates/#{name}.yml"
132
142
  when :param
133
- "#{Lono.root}/params/#{Lono.env}/#{name}.txt"
143
+ "#{Lono.config.params_path}/#{Lono.env}/#{name}.txt"
134
144
  else
135
145
  raise "hell: dont come here"
136
146
  end
137
147
  path.sub(/^\.\//, '')
138
148
  end
139
149
 
140
- # Returns String with value of "yml" or "json".
141
- def detect_format
142
- formats = Dir.glob("#{Lono.root}/templates/**/*").
143
- map { |path| path.sub(/\.erb$/, '') }.
144
- map { |path| File.extname(path) }.
145
- reject { |s| s.empty? }. # reject ""
146
- select { |s| s.include?("yml") || s.include?("json") }.
147
- uniq
148
- if formats.size > 1
149
- puts "ERROR: Detected multiple formats: #{formats.join(", ")}".colorize(:red)
150
- puts "All the output files must use the same format. Either all json or all yml."
151
- exit 1
152
- elsif formats.size == 1
153
- formats.first.sub(/^\./,'')
154
- else
155
- puts "WARN: Did not detect any template formats. Defaulting to yml. Please check the config and templates folders.".colorize(:yellow)
156
- "yml" # default format
157
- end
158
- end
159
-
160
150
  # All CloudFormation states listed here:
161
151
  # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-describing-stacks.html
162
152
  def stack_status(stack_name)
@@ -164,15 +154,15 @@ class Lono::Cfn::Base
164
154
  return false if @options[:noop]
165
155
 
166
156
  resp = cfn.describe_stacks(stack_name: stack_name)
167
- status = resp.stacks[0].stack_status
157
+ resp.stacks[0].stack_status
168
158
  end
169
159
 
170
- def exist_unless_updatable(status)
160
+ def exit_unless_updatable!(status)
171
161
  return true if testing_update?
172
162
  return false if @options[:noop]
173
163
 
174
164
  unless status =~ /_COMPLETE$/
175
- puts "Cannot create a change set for the stack because the #{@stack_name} is not in an updatable state. Stack status: #{status}"
165
+ puts "Cannot create a change set for the stack because the #{@stack_name} is not in an updatable state. Stack status: #{status}".colorize(:red)
176
166
  quit(1)
177
167
  end
178
168
  end
@@ -202,7 +192,7 @@ class Lono::Cfn::Base
202
192
  end
203
193
 
204
194
  # otherwise use the settings preference
205
- settings = Lono::Settings.new
195
+ settings = Lono::Setting.new
206
196
  settings.data['randomize_stack_name']
207
197
  end
208
198
 
@@ -212,4 +202,17 @@ class Lono::Cfn::Base
212
202
  ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]
213
203
  end
214
204
  end
205
+
206
+ def show_parameters(params, meth=nil)
207
+ params = params.clone.compact
208
+ params[:template_body] = "Hidden due to size... View at: #{@template_path}"
209
+ to = meth || "AWS API"
210
+ puts "Parameters passed to #{to}:"
211
+ puts YAML.dump(params.deep_stringify_keys)
212
+ end
213
+
214
+ def s3_folder
215
+ setting = Lono::Setting.new
216
+ setting.s3_folder
217
+ end
215
218
  end