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
@@ -10,7 +10,6 @@ Generates CloudFormation template, parameter files, and scripts in lono project
10
10
 
11
11
  $ lono generate
12
12
  Generating CloudFormation templates, parameters, and scripts
13
- No detected app/scripts
14
13
  Generating CloudFormation templates:
15
14
  output/templates/ec2.yml
16
15
  Generating parameter files:
@@ -1,54 +1,60 @@
1
1
  ## Examples
2
2
 
3
- lono new infra # skeleton project with barebones structure
4
- TEMPLATE=ec2 lono new infra # creates a single server
5
- TEMPLATE=autoscaling lono new infra
3
+ lono new infra # starter project with demo blueprint
6
4
 
7
5
  By default, `lono new` generates a skeleton project. Use `TEMPLATE` to generate different starter projects. List of the [starter templates](https://github.com/tongueroo/lono/tree/master/lib/starter_projects).
8
6
 
9
7
  ## Example Output
10
8
 
11
- $ lono new ec2
12
- => Creating new project called ec2.
13
- create ec2
14
- create ec2/.gitignore
15
- create ec2/Gemfile
16
- create ec2/Guardfile
17
- create ec2/README.md
18
- create ec2/app/definitions/base.rb
19
- create ec2/config/settings.yml
20
- create ec2/welcome.txt
21
- create ec2/app/helpers
22
- create ec2/app/partials
23
- create ec2/app/scripts
24
- create ec2/app/templates
25
- create ec2/app/user_data
26
- create ec2/config/params
27
- create ec2/config/variables
28
- create ec2/output
29
- => Installing dependencies with: bundle install
9
+ $ lono new infra
10
+ => Creating new project called infra.
11
+ create infra
12
+ create infra/.gitignore
13
+ create infra/Gemfile
14
+ create infra/Guardfile
15
+ create infra/README.md
16
+ create infra/configs/settings.yml
17
+ => Creating new blueprint called demo.
18
+ create infra/blueprints/demo
19
+ create infra/blueprints/demo/demo.gemspec
20
+ create infra/blueprints/demo/.gitignore
21
+ create infra/blueprints/demo/.meta/config.yml
22
+ create infra/blueprints/demo/Gemfile
23
+ create infra/blueprints/demo/README.md
24
+ create infra/blueprints/demo/setup/configs.rb
25
+ exist infra/blueprints/demo
26
+ create infra/blueprints/demo/app/templates/demo.rb
27
+ create infra/blueprints/demo/app/user_data/bootstrap.sh
28
+ exist infra/blueprints/demo/app/templates
29
+ exist infra
30
+ create infra/configs/demo/params/base.txt
31
+ create infra/configs/demo/params/development.txt
32
+ create infra/configs/demo/variables/base.rb
33
+ create infra/configs/demo/variables/development.rb
30
34
  => Initialize git repo
35
+ => Installing dependencies with: bundle install
36
+ => Commit git repo
31
37
  ================================================================
32
- Congrats 🎉 You have successfully created a lono project.
38
+ Congrats You have successfully created a lono project. A starter demo blueprint was created
39
+ and is at blueprints/demo. Check things out by going into the created infra folder.
33
40
 
34
- Cd into your project and check things out:
41
+ cd infra
35
42
 
36
- cd ec2
43
+ To generate the blueprint templates without launching a stack, you can run:
37
44
 
38
- Add and edit templates for your project. When you are ready to launch a CloudFormation stack run:
45
+ lono generate demo
39
46
 
40
- lono cfn create STACK_NAME
47
+ The generated files are created at `output/demo/templates` and `output/demo/params`.
41
48
 
42
- You can also get started quickly by importing other CloudFormation templates into lono. For example:
49
+ To deploy the CloudFormation stack:
43
50
 
44
- lono import https://s3-us-west-2.amazonaws.com/cloudformation-templates-us-west-2/EC2InstanceWithSecurityGroupSample.template --name ec2
51
+ lono cfn deploy my-demo --blueprint demo
45
52
 
46
- To re-generate your templates without launching a stack, you can run:
53
+ If you name the stack according to conventions, you can simply run:
47
54
 
48
- lono generate
55
+ lono cfn deploy demo
49
56
 
50
- The generated CloudFormation templates are in the output/templates folder.
51
- The generated stack parameters are in the output/params folder. Here's the command with some output filtered to focus on learning.
57
+ To list and create additional blueprints refer to https://lono.cloud/docs/core/blueprints
52
58
 
53
59
  More info: http://lono.cloud/
54
- $
60
+ $
@@ -1,3 +1,3 @@
1
1
  ## Examples
2
2
 
3
- lono param generate
3
+ lono param generate
@@ -1,5 +1,5 @@
1
1
  ## Example
2
2
 
3
- To generate CloudFormation json parameter files in the params folder to `output/params`:
3
+ To generate CloudFormation json parameter files in the `output` folder:
4
4
 
5
5
  lono param generate
@@ -1,4 +1,4 @@
1
1
  ## Examples
2
2
 
3
- lono template generate --help
4
- lono template bashify --help
3
+ lono template generate --help
4
+ lono template bashify --help
@@ -2,7 +2,7 @@
2
2
 
3
3
  With more complex CloudFormation templates, the dependency can get difficult to follow. Visualizing the dependencies is helpful.
4
4
 
5
- lono import https://s3.amazonaws.com/solutions-reference/aws-waf-security-automations/latest/aws-waf-security-automations.template --name waf
5
+ lono import https://s3.amazonaws.com/solutions-reference/aws-waf-security-automations/latest/aws-waf-security-automations.template --blueprint waf
6
6
  lono xgraph waf
7
7
 
8
8
  This above command generates a dependency chart. The command uses the DependsOn attribute specified in each resource to figure this out. It does not show implied dependencies that CloudFormaton automatically computes for us. The chart looks like this:
@@ -2,6 +2,6 @@ require "thor"
2
2
 
3
3
  class Lono::Inspector
4
4
  autoload :Base, 'lono/inspector/base'
5
- autoload :Graph, 'lono/inspector/graph'
6
5
  autoload :Summary, 'lono/inspector/summary'
6
+ autoload :Graph, 'lono/inspector/graph'
7
7
  end
@@ -1,23 +1,39 @@
1
1
  class Lono::Inspector::Base
2
- def initialize(stack_name, options)
3
- @stack_name = stack_name
4
- @options = options
2
+ include Lono::Blueprint::Root
3
+
4
+ def initialize(blueprint, template, options)
5
+ @blueprint, @template, @options = blueprint, template, options
6
+ end
7
+
8
+ def run
9
+ blueprints = Lono::Blueprint::Find.one_or_all(@blueprint)
10
+ blueprints.each do |blueprint|
11
+ @blueprint_name = blueprint
12
+
13
+ generate_templates
14
+ set_blueprint_root(blueprint)
15
+ templates = @template ? [@template] : all_templates
16
+ templates.each do |template_name|
17
+ perform(template_name)
18
+ end
19
+ end
5
20
  end
6
21
 
7
22
  def generate_templates
8
- Lono::Template::DSL.new(@options.clone.merge(quiet: true)).run
23
+ Lono::Template::Generator.new(@blueprint_name, @options.clone.merge(quiet: false)).run
9
24
  end
10
25
 
11
- def run
12
- generate_templates
13
- perform
26
+ def all_templates
27
+ templates_path = "#{Lono.config.output_path}/#{@blueprint_name}/templates"
28
+ Dir.glob("#{templates_path}/**").map do |path|
29
+ path.sub("#{templates_path}/", '').sub('.yml','') # template_name
30
+ end
14
31
  end
15
32
 
16
33
  def data
17
- return @data if @data
18
- template_path = "#{Lono.config.output_path}/templates/#{@stack_name}.yml"
34
+ template_path = "#{Lono.config.output_path}/#{@blueprint_name}/templates/#{@template_name}.yml"
19
35
  check_template_exists(template_path)
20
- @data = YAML.load(IO.read(template_path))
36
+ YAML.load(IO.read(template_path))
21
37
  end
22
38
 
23
39
  # Check if the template exists and print friendly error message. Exits if it
@@ -2,13 +2,17 @@ require "yaml"
2
2
  require "graph"
3
3
 
4
4
  class Lono::Inspector::Graph < Lono::Inspector::Base
5
- def initialize(stack_name, options)
5
+ def initialize(blueprint, template, options)
6
6
  super
7
7
  @nodes = [] # lookup map
8
8
  end
9
9
 
10
- def perform
11
- puts "Generating dependencies tree..."
10
+ def perform(template_name)
11
+ # little dirty but @template_name is used in data method
12
+ # so we dont have to pass it to the data method
13
+ @template_name = template_name
14
+
15
+ puts "Generating dependencies tree for template #{@template_name}..."
12
16
  return if @options[:noop]
13
17
 
14
18
  # First loop through top level nodes and build set depends_on property
@@ -1,6 +1,10 @@
1
1
  class Lono::Inspector::Summary < Lono::Inspector::Base
2
- def perform
3
- puts "=> CloudFormation Template Summary:".color(:green)
2
+ def perform(template_name)
3
+ # little dirty but @template_name is used in data method
4
+ # so we dont have to pass it to the data method
5
+ @template_name = template_name
6
+
7
+ puts "=> CloudFormation Template Summary for template #{@template_name.color(:sienna)}:"
4
8
  return if @options[:noop]
5
9
 
6
10
  print_parameters_summary
@@ -46,14 +50,22 @@ class Lono::Inspector::Summary < Lono::Inspector::Base
46
50
  end
47
51
 
48
52
  def resource_types
53
+ resources = data["Resources"]
54
+ return unless resources
55
+
49
56
  types = Hash.new(0)
50
- data["Resources"].each do |logical_id, resource|
57
+ resources.each do |logical_id, resource|
51
58
  types[resource["Type"]] += 1
52
59
  end
53
60
  types
54
61
  end
55
62
 
56
63
  def print_resource_types
64
+ unless resource_types
65
+ puts "No resources found."
66
+ return
67
+ end
68
+
57
69
  types = resource_types.sort_by {|r| r[1] * -1} # Hash -> 2D Array
58
70
  types.each do |a|
59
71
  type, count = a
@@ -0,0 +1,46 @@
1
+ require "digest"
2
+
3
+ # 1. md5sum the file or zipfile - shared
4
+ # 2. add prefix and md5sum - shared, lets break out prefix adding logic to elsewhere
5
+
6
+ # Using md5sum on the zipped file will an always changing value since the timestamp and other metadata of the zipfile
7
+ # changes whenever we create it.
8
+ #
9
+ # This is custom checksum logic that only accounts for the contents of the files in the directory.
10
+ module Lono
11
+ class Md5
12
+ class << self
13
+ extend Memoist
14
+
15
+ # This checksum within the file name is to mainly make sure that Lambda::Function resources "change" and an update is triggered.
16
+ # There's another checksum in the upload code that makes sure we don't upload the code again to speed up things.
17
+ def sum(path)
18
+ files = Dir["#{path}/**/*"]
19
+ files = files.reject { |f| File.directory?(f) }
20
+ .reject { |f| File.symlink?(f) }
21
+ files.sort!
22
+ content = files.map do |f|
23
+ Digest::MD5.file(f).to_s[0..7]
24
+ end.join
25
+
26
+ md5 = Digest::MD5.new
27
+ md5.update(content)
28
+ md5.hexdigest.to_s[0..7]
29
+ end
30
+ memoize :sum
31
+
32
+ def name(path)
33
+ relative_path = name_without_md5(path)
34
+ relative_path = relative_path.sub(/\.(\w+)$/,'') # strip extension
35
+ ext = File.directory?(path) ? "zip" : $1
36
+ md5 = sum(path)
37
+ "#{relative_path}-#{md5}.#{ext}"
38
+ end
39
+
40
+ def name_without_md5(path)
41
+ regexp = %r{.*/output/[\w_-]+/files/}
42
+ path.sub(regexp, '') # relative_path w/o md5
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,9 +1,6 @@
1
1
  module Lono
2
2
  class New < Sequence
3
- autoload :Helper, 'lono/new/helper'
4
- autoload :Message, 'lono/new/message'
5
3
  include Helper
6
- include Message
7
4
 
8
5
  argument :project_name
9
6
 
@@ -13,19 +10,20 @@ module Lono
13
10
  # Also options from the cli can be pass through to here
14
11
  def self.cli_options
15
12
  [
16
- [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
17
13
  [:bundle, type: :boolean, default: true, desc: "Runs bundle install on the project"],
14
+ [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
18
15
  [:git, type: :boolean, default: true, desc: "Git initialize the project"],
16
+ [:type, default: "dsl", desc: "Blueprint type: dsl or erb"],
19
17
  ]
20
18
  end
21
19
 
22
20
  cli_options.each do |args|
23
- class_option *args
21
+ class_option(*args)
24
22
  end
25
23
 
26
24
  # for specs
27
25
  def set_cwd
28
- @cwd = ENV['TEST'] ? File.dirname(Lono.root) : Dir.pwd
26
+ @cwd = Dir.pwd
29
27
  end
30
28
 
31
29
  def create_project
@@ -33,17 +31,9 @@ module Lono
33
31
  directory ".", "#{@cwd}/#{project_name}"
34
32
  end
35
33
 
36
- def create_empty_directories
37
- meths = Lono::Core::Config::PATHS.keys
38
- meths.each do |meth|
39
- path = "#{@cwd}/#{project_name}/#{Lono.config.send(meth)}"
40
- next if File.exist?(path)
41
- if ENV['TEST']
42
- empty_directory Lono.config.send(meth)
43
- else
44
- empty_directory path
45
- end
46
- end
34
+ def create_starter_blueprint
35
+ # https://github.com/erikhuda/thor/wiki/Invocations
36
+ Lono::Blueprint.start(["demo", "--from-new", "--type", @options[:type], "--project-name", project_name])
47
37
  end
48
38
 
49
39
  # After this commands are executed with the newly created project
@@ -57,6 +47,11 @@ module Lono
57
47
  chmod("exe", 0755 & ~File.umask, verbose: false) if File.exist?("exe")
58
48
  end
59
49
 
50
+ def git_init
51
+ return if File.exist?(".git") # this is a clone repo
52
+ run_git_init
53
+ end
54
+
60
55
  def bundle_install
61
56
  return unless options[:bundle]
62
57
 
@@ -66,19 +61,36 @@ module Lono
66
61
  end
67
62
  end
68
63
 
69
- def git_init
70
- return if !options[:git]
71
- return unless git_installed?
72
- return if File.exist?(".git") # this is a clone repo
73
-
74
- puts "=> Initialize git repo"
75
- run("git init")
76
- run("git add .")
77
- run("git commit -m 'first commit'")
64
+ def git_commit
65
+ run_git_commit
78
66
  end
79
67
 
80
- def final_message
81
- puts welcome_message
68
+ def welcome_message
69
+ puts <<~EOL
70
+ #{"="*64}
71
+ Congrats 🎉 You have successfully created a lono project. A starter demo blueprint was created
72
+ and is at blueprints/demo. Check things out by going into the created infra folder.
73
+
74
+ cd #{project_name}
75
+
76
+ To generate the blueprint templates without launching a stack, you can run:
77
+
78
+ lono generate demo
79
+
80
+ The generated files are created at `output/demo/templates` and `output/demo/params`.
81
+
82
+ To deploy the CloudFormation stack:
83
+
84
+ lono cfn deploy my-demo --blueprint demo
85
+
86
+ If you name the stack according to conventions, you can simply run:
87
+
88
+ lono cfn deploy demo
89
+
90
+ To list and create additional blueprints refer to https://lono.cloud/docs/core/blueprints
91
+
92
+ More info: http://lono.cloud/
93
+ EOL
82
94
  end
83
95
  end
84
96
  end
@@ -4,9 +4,8 @@ module Lono::New::Helper
4
4
  project_name.underscore.camelize
5
5
  end
6
6
 
7
- # Files should be named with underscores instead of dashes even
8
- # though project name can contain a dash. This is because autoloading
9
- # works will underscores in the filenames only.
7
+ # Files should be named with underscores instead of dashes even though project name can contain a dash.
8
+ # This is because autoloading works with underscores in the filenames only.
10
9
  def underscored_name
11
10
  project_name.underscore
12
11
  end
@@ -1,16 +1,17 @@
1
1
  require "thor"
2
2
 
3
- class Lono::Param < Lono::Command
4
- autoload :Generator, 'lono/param/generator'
3
+ module Lono
4
+ class Param < Lono::Command
5
+ class_option :verbose, type: :boolean
6
+ class_option :noop, type: :boolean
7
+ class_option :mute, type: :boolean
5
8
 
6
- class_option :verbose, type: :boolean
7
- class_option :noop, type: :boolean
8
- class_option :mute, type: :boolean
9
-
10
- desc "generate", "Generate all parameter files to `output/params`."
11
- long_desc Lono::Help.text("param/generate")
12
- option :path, desc: "Name of the source that maps to the params txt file. name -> params/NAME.txt. Use this to override the params/NAME.txt convention"
13
- def generate
14
- Generator.generate_all(options)
9
+ desc "generate", "Generate all parameter files to `output/params`."
10
+ long_desc Lono::Help.text("param/generate")
11
+ def generate(blueprint=nil)
12
+ Blueprint::Find.one_or_all(blueprint).each do |b|
13
+ Generator.new(b, options).generate
14
+ end
15
+ end
15
16
  end
16
17
  end