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,14 @@
1
+ module Lono::AppFile
2
+ class Registry
3
+ @@items = []
4
+ class << self
5
+ def register(name, blueprint, options={})
6
+ @@items << Item.new(name, blueprint, options) unless @@items.detect { |i| i.name == name }
7
+ end
8
+
9
+ def items
10
+ @@items
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,46 @@
1
+ module Lono::AppFile
2
+ class Registry
3
+ # Holds metadata about the item in the regsitry.
4
+ class Item
5
+ attr_reader :name, :options
6
+ def initialize(name, blueprint, options={})
7
+ @name, @blueprint, @options = name, blueprint, options
8
+ end
9
+
10
+ def path
11
+ "#{Lono.root}/output/#{@blueprint}/files/#{@name}"
12
+ end
13
+
14
+ def directory?
15
+ File.directory?(path)
16
+ end
17
+
18
+ def file?
19
+ File.file?(path)
20
+ end
21
+
22
+ def s3_path
23
+ file_path = zip_file_path.sub(%r{.*/output/[\w_-]+/files/}, '') # dont use basename. there might be subfolders
24
+ "#{s3_prefix}/#{file_path}"
25
+ end
26
+
27
+ # full path
28
+ def zip_file_path
29
+ "#{File.dirname(path)}/#{zip_file_name}"
30
+ end
31
+
32
+ def zip_file_name
33
+ "#{File.basename(path)}-#{Lono::Md5.sum(path)}.zip"
34
+ end
35
+
36
+ private
37
+ def md5_path
38
+ Lono::Md5.name(path)
39
+ end
40
+
41
+ def s3_prefix
42
+ "#{Lono.env}/#{@blueprint}/files" # development/ecs-asg/files
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ module Lono::AppFile
2
+ class Upload < Base
3
+ include Lono::AwsServices
4
+ extend Memoist
5
+
6
+ def initialize(blueprint, options={})
7
+ @blueprint, @options = blueprint, options
8
+ end
9
+
10
+ def upload
11
+ puts "Uploading app/files..."
12
+
13
+ Registry.items.each do |item|
14
+ s3_upload(item)
15
+ end
16
+ end
17
+
18
+ # TODO: check md5sum and only upload if it changes
19
+ def s3_upload(item)
20
+ filepath = item.zip_file_path
21
+ s3_key = item.s3_path
22
+ s3_path = "s3://#{s3_bucket}/#{s3_key}"
23
+ message = "Uploading: #{filepath} to #{s3_path}".color(:green)
24
+ message = "NOOP: #{message}" if @options[:noop]
25
+ puts message
26
+ return if @options[:noop]
27
+
28
+ s3.put_object(
29
+ body: IO.read(filepath),
30
+ bucket: s3_bucket,
31
+ key: s3_key,
32
+ )
33
+ end
34
+
35
+ def s3_bucket
36
+ Lono::S3::Bucket.name
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ require "zeitwerk"
2
+
3
+ module Lono
4
+ class Autoloader
5
+ class Inflector < Zeitwerk::Inflector
6
+ def camelize(basename, _abspath)
7
+ map = { cli: "CLI", version: "VERSION" }
8
+ map[basename.to_sym] || super
9
+ end
10
+ end
11
+
12
+ class << self
13
+ def setup
14
+ loader = Zeitwerk::Loader.new
15
+ loader.inflector = Inflector.new
16
+ loader.push_dir(File.dirname(__dir__)) # lib
17
+ # loader.log! # uncomment to debug
18
+ loader.setup
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,46 @@
1
+ require "aws-sdk-cloudformation"
2
+ require "aws-sdk-ec2"
3
+ require "aws-sdk-iam"
4
+ require "aws-sdk-s3"
5
+
6
+ module Lono
7
+ module AwsServices
8
+ extend Memoist
9
+ include Util
10
+
11
+ def ec2
12
+ Aws::EC2::Client.new
13
+ end
14
+ memoize :ec2
15
+
16
+ def iam
17
+ Aws::IAM::Client.new
18
+ end
19
+ memoize :iam
20
+
21
+ def sts
22
+ Aws::STS::Client.new # part of aws-sdk-core
23
+ end
24
+ memoize :sts
25
+
26
+ def s3
27
+ Aws::S3::Client.new
28
+ end
29
+ memoize :s3
30
+
31
+ def s3_resource
32
+ Aws::S3::Resource.new
33
+ end
34
+ memoize :s3_resource
35
+
36
+ def s3_presigner
37
+ Aws::S3::Presigner.new(client: s3)
38
+ end
39
+ memoize :s3_presigner
40
+
41
+ def cfn
42
+ Aws::CloudFormation::Client.new
43
+ end
44
+ memoize :cfn
45
+ end
46
+ end
@@ -0,0 +1,49 @@
1
+ module Lono::AwsServices
2
+ module Util
3
+ def stack_exists?(stack_name)
4
+ return true if testing_update?
5
+ return false if @options[:noop]
6
+
7
+ exist = nil
8
+ begin
9
+ # When the stack does not exist an exception is raised. Example:
10
+ # Aws::CloudFormation::Errors::ValidationError: Stack with id blah does not exist
11
+ cfn.describe_stacks(stack_name: stack_name)
12
+ exist = true
13
+ rescue Aws::CloudFormation::Errors::ValidationError => e
14
+ if e.message =~ /does not exist/
15
+ exist = false
16
+ elsif e.message.include?("'stackName' failed to satisfy constraint")
17
+ # Example of e.message when describe_stack with invalid stack name
18
+ # "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:/._+]*"
19
+ puts "Invalid stack name: #{stack_name}"
20
+ puts "Full error message: #{e.message}"
21
+ exit 1
22
+ else
23
+ raise # re-raise exception because unsure what other errors can happen
24
+ end
25
+ end
26
+ exist
27
+ end
28
+
29
+ def find_stack(stack_name)
30
+ resp = cfn.describe_stacks(stack_name: stack_name)
31
+ resp.stacks.first
32
+ rescue Aws::CloudFormation::Errors::ValidationError => e
33
+ # example: Stack with id demo-web does not exist
34
+ if e.message =~ /Stack with/ && e.message =~ /does not exist/
35
+ nil
36
+ else
37
+ raise
38
+ end
39
+ end
40
+
41
+ def rollback_complete?(stack)
42
+ stack.stack_status == 'ROLLBACK_COMPLETE'
43
+ end
44
+
45
+ def testing_update?
46
+ ENV['TEST'] && self.class.name == "LonoCfn::Update"
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,113 @@
1
+ module Lono
2
+ class Blueprint < Sequence
3
+ include Helper
4
+
5
+ argument :blueprint_name
6
+
7
+ def self.source_root
8
+ templates = File.expand_path("../templates", File.dirname(__FILE__))
9
+ "#{templates}/blueprint"
10
+ end
11
+
12
+ def self.cli_options
13
+ [
14
+ [:bundle, type: :boolean, default: true, desc: "Runs bundle install on the project"],
15
+ [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
16
+ [:from_new, type: :boolean, desc: "Called from `lono new` command."],
17
+ [:project_name, default: '', desc: "Only used with from_new internally"],
18
+ [:type, default: "dsl", desc: "Blueprint type: dsl or erb"],
19
+ ]
20
+ end
21
+
22
+ cli_options.each do |args|
23
+ class_option(*args)
24
+ end
25
+
26
+ # for specs
27
+ def set_cwd
28
+ @cwd = ENV['TEST'] ? File.dirname(Lono.root) : "#{Dir.pwd}/blueprints"
29
+
30
+ if options[:from_new]
31
+ # At this point @cwd will have the project_name from `lono new`
32
+ # Yup, it's confusing. Here's an example to explain:
33
+ #
34
+ # lono new my-infra - sets @cwd = my-infra
35
+ #
36
+ # Then within the new Thor::Group this is called
37
+ #
38
+ # Lono::Blueprint.start(["ec2", "--from-new"])
39
+ #
40
+ # So @cwd = my-infra/blueprints
41
+ @cwd = "#{options[:project_name]}/blueprints"
42
+ end
43
+ end
44
+
45
+ def create_project
46
+ puts "=> Creating new blueprint called #{blueprint_name}."
47
+ directory ".", "#{@cwd}/#{blueprint_name}"
48
+ end
49
+
50
+ def create_app_folder
51
+ directory "../blueprint_types/#{@options[:type]}", "#{@cwd}/#{blueprint_name}"
52
+ end
53
+
54
+ def create_empty_directories
55
+ # Note: Not using Lono::Core::Config::PATHS.keys to create all of them because
56
+ # think it is more common to not have all the folders. Instead create them explicitly.
57
+ empty_directory "#{@cwd}/#{blueprint_name}/app/templates"
58
+ end
59
+
60
+ def create_starter_configs
61
+ if options[:from_new] # lono new command
62
+ directory "../blueprint_configs", options[:project_name]
63
+ else # lono blueprint command
64
+ directory "../blueprint_configs", "."
65
+ end
66
+ end
67
+
68
+ # After this commands are executed with the newly created project
69
+ def set_destination_root
70
+ destination_root = "#{@cwd}/#{blueprint_name}"
71
+ self.destination_root = destination_root
72
+ FileUtils.cd(self.destination_root)
73
+ end
74
+
75
+ def bundle_install
76
+ return if options[:from_new]
77
+ return unless options[:bundle]
78
+
79
+ puts "=> Installing dependencies with: bundle install"
80
+ Bundler.with_clean_env do
81
+ system("BUNDLE_IGNORE_CONFIG=1 bundle install")
82
+ end
83
+ end
84
+
85
+ def welcome_message
86
+ return if options[:from_new]
87
+ puts <<~EOL
88
+ #{"="*64}
89
+ Congrats 🎉 You have successfully created a lono blueprint.
90
+
91
+ Cd into your blueprint and check things out.
92
+
93
+ cd #{blueprint_name}
94
+
95
+ More info: https://lono.cloud/docs/core/blueprints
96
+
97
+ EOL
98
+ end
99
+
100
+ def tree
101
+ return if options[:from_new]
102
+ tree_installed = system("type tree > /dev/null")
103
+ return unless tree_installed
104
+
105
+ structure = `tree .`
106
+ puts <<~EOL
107
+ Here's the structure of your blueprint:
108
+
109
+ #{structure}
110
+ EOL
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,90 @@
1
+ require "yaml"
2
+
3
+ class Lono::Blueprint
4
+ class Find
5
+ class << self
6
+ extend Memoist
7
+
8
+ def one_or_all(blueprint)
9
+ blueprint ? [blueprint] : all_blueprints
10
+ end
11
+
12
+ # Returns both project and gem blueprints
13
+ def all_blueprints
14
+ project_blueprints = all_project_blueprint_infos.map { |info| info.name }
15
+
16
+ gem_blueprints = specs.map do |spec|
17
+ dot_lono = dot_meta_path(spec)
18
+ config = YAML.load_file(dot_lono)
19
+ config["blueprint_name"]
20
+ end
21
+
22
+ all = project_blueprints + gem_blueprints
23
+ all.uniq
24
+ end
25
+
26
+ # Returns blueprint root full path. Can be:
27
+ #
28
+ # 1. projects blueprints/BLUEPRINT - higher precedence
29
+ # 2. full gem path
30
+ #
31
+ def find(blueprint)
32
+ # Check projects blueprints
33
+ info = all_project_blueprint_infos.find { |info| info.name == blueprint}
34
+ return info.path if info
35
+
36
+ # Check gem specs
37
+ result = specs.find do |spec|
38
+ dot_lono = dot_meta_path(spec)
39
+ config = YAML.load_file(dot_lono)
40
+ config["blueprint_name"] == blueprint
41
+ end
42
+ result.full_gem_path if result
43
+ end
44
+
45
+ # Returns: Array of Blueprint::Info. Example:
46
+ #
47
+ # [#<Lono::Blueprint::Info:0x0000561e620e0548
48
+ # @name="ecs-spot-fleet",
49
+ # @path="/full/path/to/blueprint/ecs-spot-demo">,
50
+ # #<Lono::Blueprint::Info:0x0000561e61e132c0
51
+ # @name="ec2",
52
+ # @path="/full/path/to/blueprint/ec2">]
53
+ def all_project_blueprint_infos
54
+ infos = []
55
+ Dir.glob("#{Lono.root}/blueprints/*").select do |p|
56
+ dot_lono = dot_meta_path(p)
57
+ next unless File.exist?(dot_lono)
58
+ config = YAML.load_file(dot_lono)
59
+ infos << Info.new(config["blueprint_name"], p)
60
+ end
61
+ infos
62
+ end
63
+
64
+ # Only the blueprint specs
65
+ def specs
66
+ specs = Bundler.load.specs
67
+ specs.select do |spec|
68
+ File.exist?(dot_meta_path(spec))
69
+ end
70
+ end
71
+ memoize :specs
72
+
73
+ def dot_meta_path(source)
74
+ if source.is_a?(String) # path to folder
75
+ "#{source}/.meta/config.yml"
76
+ else # spec
77
+ "#{source.full_gem_path}/.meta/config.yml"
78
+ end
79
+ end
80
+
81
+ def bundler_version_check!
82
+ return unless Bundler.bundler_major_version >= 1 # LockfileParser only works for Bundler version 2+
83
+
84
+ puts "ERROR: The bundler version detected is too old. Please use bundler 2+".color(:red)
85
+ puts "Current detected bundler version is #{Bundler.bundler_major_version}"
86
+ exit 1
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,18 @@
1
+ class Lono::Blueprint
2
+ module Helper
3
+ extend Memoist
4
+
5
+ def user_info
6
+ git_author_name = git_installed? ? `git config user.name`.chomp : ""
7
+ git_user_email = git_installed? ? `git config user.email`.chomp : ""
8
+ github_username = git_installed? ? `git config github.user`.chomp : ""
9
+
10
+ {
11
+ :author => git_author_name.empty? ? "TODO: Write your name" : git_author_name,
12
+ :email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email,
13
+ :github_username => github_username.empty? ? "[USERNAME]" : github_username,
14
+ }
15
+ end
16
+ memoize :user_info
17
+ end
18
+ end