lono 8.0.0.pre.rc1 → 8.0.0.pre.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/.cody/acceptance/bin/build.sh +5 -5
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +84 -0
  4. data/.github/ISSUE_TEMPLATE/documentation.md +12 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +64 -0
  6. data/.github/ISSUE_TEMPLATE/question.md +14 -0
  7. data/.github/ISSUE_TEMPLATE.md +7 -0
  8. data/.github/PULL_REQUEST_TEMPLATE.md +50 -0
  9. data/CHANGELOG.md +59 -2
  10. data/Gemfile +1 -3
  11. data/README.md +2 -7
  12. data/lib/lono/app/callable_option/concern.rb +12 -0
  13. data/lib/lono/app/callable_option.rb +56 -0
  14. data/lib/lono/app.rb +56 -20
  15. data/lib/lono/autoloader.rb +1 -0
  16. data/lib/lono/aws_services/helper.rb +0 -2
  17. data/lib/lono/blueprint.rb +1 -18
  18. data/lib/lono/builder/allow/base.rb +54 -0
  19. data/lib/lono/builder/allow/env.rb +17 -0
  20. data/lib/lono/builder/allow/region.rb +20 -0
  21. data/lib/lono/builder/allow.rb +8 -0
  22. data/lib/lono/builder/configset/combiner.rb +145 -0
  23. data/lib/lono/builder/configset/definition/base.rb +47 -0
  24. data/lib/lono/builder/configset/definition/context.rb +70 -0
  25. data/lib/lono/{configset/strategy/helpers/dsl → builder/configset/definition/dsl/syntax}/auth.rb +1 -1
  26. data/lib/lono/builder/configset/definition/dsl/syntax/content.rb +22 -0
  27. data/lib/lono/{configset/strategy/helpers/dsl/syntax.rb → builder/configset/definition/dsl/syntax/core.rb} +15 -9
  28. data/lib/lono/{configset/strategy/helpers/dsl → builder/configset/definition/dsl/syntax}/package.rb +1 -1
  29. data/lib/lono/builder/configset/definition/dsl/syntax.rb +5 -0
  30. data/lib/lono/{configset/strategy → builder/configset/definition}/dsl.rb +10 -14
  31. data/lib/lono/{configset/strategy → builder/configset/definition}/erb.rb +13 -16
  32. data/lib/lono/builder/configset/definition.rb +18 -0
  33. data/lib/lono/builder/configset/evaluator.rb +10 -0
  34. data/lib/lono/builder/configset/registration.rb +35 -0
  35. data/lib/lono/builder/context.rb +33 -18
  36. data/lib/lono/builder/dsl/evaluator.rb +45 -0
  37. data/lib/lono/builder/dsl/finalizer/base.rb +8 -0
  38. data/lib/lono/builder/dsl/finalizer/configsets.rb +20 -0
  39. data/lib/lono/builder/dsl/finalizer/files/base.rb +4 -0
  40. data/lib/lono/builder/dsl/finalizer/files/build.rb +50 -0
  41. data/lib/lono/builder/dsl/finalizer/files/replace.rb +36 -0
  42. data/lib/lono/builder/dsl/finalizer/files.rb +9 -0
  43. data/lib/lono/builder/{template/dsl → dsl}/finalizer/parameter_groups.rb +6 -5
  44. data/lib/lono/builder/dsl/finalizer.rb +15 -0
  45. data/lib/lono/builder/{template/dsl/evaluator/helpers/ec2_helper.rb → dsl/helpers/ec2.rb} +3 -3
  46. data/lib/lono/builder/dsl/helpers/files.rb +7 -0
  47. data/lib/lono/builder/{template/helpers.rb → dsl/helpers/partials.rb} +48 -57
  48. data/lib/lono/builder/dsl/helpers/s3.rb +14 -0
  49. data/lib/lono/builder/{context/ssm_fetcher.rb → dsl/helpers/ssm/fetcher.rb} +5 -3
  50. data/lib/lono/builder/{context/helpers.rb → dsl/helpers/ssm.rb} +3 -3
  51. data/lib/lono/builder/{template/dsl/evaluator/helpers/stack_helper.rb → dsl/helpers/stack.rb} +6 -6
  52. data/lib/lono/builder/{template/dsl/evaluator/helpers/tags_helper.rb → dsl/helpers/tags.rb} +2 -2
  53. data/lib/lono/builder/dsl/helpers/template_file.rb +66 -0
  54. data/lib/lono/builder/dsl/helpers.rb +5 -0
  55. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/base.rb +4 -5
  56. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/condition.rb +1 -1
  57. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/mapping.rb +1 -1
  58. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/output.rb +1 -1
  59. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/parameter.rb +1 -1
  60. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/resource/property_mover.rb +12 -2
  61. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/resource.rb +1 -1
  62. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/section.rb +1 -1
  63. data/lib/lono/builder/dsl/syntax/core/squeezer.rb +40 -0
  64. data/lib/lono/builder/{template/dsl/evaluator/section/methods.rb → dsl/syntax/core.rb} +2 -2
  65. data/lib/lono/builder/{template/dsl/evaluator → dsl/syntax}/fn.rb +1 -3
  66. data/lib/lono/builder/{template/dsl/evaluator → dsl}/syntax/parameter_group.rb +1 -1
  67. data/lib/lono/builder/dsl/syntax.rb +9 -0
  68. data/lib/lono/builder/{template/dsl.rb → dsl.rb} +2 -2
  69. data/lib/lono/builder/param.rb +5 -2
  70. data/lib/lono/builder/template/upload.rb +2 -15
  71. data/lib/lono/builder/template.rb +1 -3
  72. data/lib/lono/builder/{template/dsl/evaluator → util}/stringify.rb +1 -1
  73. data/lib/lono/builder.rb +39 -0
  74. data/lib/lono/bundler/component/props/extension.rb +0 -1
  75. data/lib/lono/bundler/extract/tar.rb +0 -1
  76. data/lib/lono/bundler/util/git.rb +18 -16
  77. data/lib/lono/cfn/base.rb +2 -2
  78. data/lib/lono/cfn/cancel.rb +5 -5
  79. data/lib/lono/cfn/concerns/build.rb +1 -1
  80. data/lib/lono/cfn/delete.rb +5 -2
  81. data/lib/lono/cfn/deploy/iam.rb +1 -2
  82. data/lib/lono/cfn/deploy/rollback.rb +1 -3
  83. data/lib/lono/cfn/deploy.rb +46 -5
  84. data/lib/lono/cfn/download.rb +0 -1
  85. data/lib/lono/cfn/plan/changeset.rb +3 -3
  86. data/lib/lono/cfn/plan/diff/data.rb +11 -1
  87. data/lib/lono/cfn/plan/diff/file.rb +2 -1
  88. data/lib/lono/cfn/plan/param.rb +1 -1
  89. data/lib/lono/cfn/plan/template.rb +2 -2
  90. data/lib/lono/cfn/plan.rb +1 -0
  91. data/lib/lono/cli/abstract.rb +0 -6
  92. data/lib/lono/cli/base.rb +6 -3
  93. data/lib/lono/cli/clean.rb +3 -2
  94. data/lib/lono/cli/help/cfn/status.md +0 -1
  95. data/lib/lono/cli/help/new/helper.md +27 -0
  96. data/lib/lono/cli/help/new/hook.md +14 -0
  97. data/lib/lono/cli/help/new/project.md +3 -10
  98. data/lib/lono/cli/help/seed.md +22 -21
  99. data/lib/lono/cli/iam.rb +27 -0
  100. data/lib/lono/cli/list.rb +3 -6
  101. data/lib/lono/cli/new/blueprint.rb +3 -9
  102. data/lib/lono/cli/new/configset.rb +11 -44
  103. data/lib/lono/cli/new/helper.rb +19 -11
  104. data/lib/lono/cli/new/hook.rb +32 -0
  105. data/lib/lono/cli/new/sequence.rb +6 -1
  106. data/lib/lono/cli/new.rb +9 -9
  107. data/lib/lono/cli/s3.rb +3 -3
  108. data/lib/lono/cli/script/build.rb +0 -5
  109. data/lib/lono/cli/status.rb +18 -0
  110. data/lib/lono/{inspector → cli}/summary.rb +23 -33
  111. data/lib/lono/cli.rb +16 -16
  112. data/lib/lono/command.rb +28 -2
  113. data/lib/lono/component.rb +29 -0
  114. data/lib/lono/concerns/aws_info.rb +14 -0
  115. data/lib/lono/concerns/names.rb +9 -0
  116. data/lib/lono/configset.rb +17 -0
  117. data/lib/lono/core.rb +11 -1
  118. data/lib/lono/ext/bundler.rb +7 -0
  119. data/lib/lono/ext/core/module.rb +31 -0
  120. data/lib/lono/ext/core/object.rb +32 -0
  121. data/lib/lono/ext/core/string.rb +9 -0
  122. data/lib/lono/ext.rb +4 -0
  123. data/lib/lono/files/base.rb +12 -0
  124. data/lib/lono/{utils → files/builder/lambda_layer}/rsync.rb +3 -5
  125. data/lib/lono/{app_file/build → files/builder}/lambda_layer/ruby_packager.rb +104 -79
  126. data/lib/lono/files/builder/lambda_layer/ruby_version.rb +38 -0
  127. data/lib/lono/files/builder/lambda_layer.rb +17 -0
  128. data/lib/lono/files/builder.rb +37 -0
  129. data/lib/lono/files/compressor.rb +53 -0
  130. data/lib/lono/files/concerns/post_processing.rb +52 -0
  131. data/lib/lono/files/concerns/registration.rb +16 -0
  132. data/lib/lono/files/registry.rb +6 -0
  133. data/lib/lono/files.rb +41 -0
  134. data/lib/lono/hooks/builder.rb +50 -0
  135. data/lib/lono/hooks/concern.rb +9 -0
  136. data/lib/lono/hooks/dsl.rb +20 -0
  137. data/lib/lono/hooks/runner.rb +46 -0
  138. data/lib/lono/layering/layer.rb +64 -56
  139. data/lib/lono/logger.rb +2 -3
  140. data/lib/lono/names.rb +7 -10
  141. data/lib/lono/s3/bucket.rb +43 -37
  142. data/lib/lono/s3/rollback.rb +8 -0
  143. data/lib/lono/s3/uploader.rb +33 -28
  144. data/lib/lono/script/build.rb +0 -5
  145. data/lib/lono/seeder.rb +38 -29
  146. data/lib/lono/user_data.rb +3 -1
  147. data/lib/lono/utils/sh.rb +32 -0
  148. data/lib/lono/utils.rb +5 -0
  149. data/lib/lono/version.rb +1 -1
  150. data/lib/lono/yamler/validator.rb +7 -22
  151. data/lib/lono.rb +8 -0
  152. data/lib/templates/configset/configset.rb +2 -16
  153. data/lib/templates/examples/configset/configset.rb +16 -0
  154. data/lib/templates/helper/%underscore_name%_helper.rb.tt +1 -1
  155. data/lib/templates/hook/config/hooks.rb.tt +14 -0
  156. data/lono.gemspec +1 -1
  157. metadata +99 -93
  158. data/lib/lono/app_file/base.rb +0 -28
  159. data/lib/lono/app_file/build/lambda_layer.rb +0 -20
  160. data/lib/lono/app_file/build.rb +0 -79
  161. data/lib/lono/app_file/registry/item.rb +0 -24
  162. data/lib/lono/app_file/registry.rb +0 -16
  163. data/lib/lono/app_file/upload.rb +0 -12
  164. data/lib/lono/builder/context/loader/load_files.rb +0 -23
  165. data/lib/lono/builder/context/loader.rb +0 -35
  166. data/lib/lono/builder/context/params.rb +0 -7
  167. data/lib/lono/builder/template/configset_injector.rb +0 -52
  168. data/lib/lono/builder/template/dsl/evaluator/helpers/core_helper.rb +0 -14
  169. data/lib/lono/builder/template/dsl/evaluator/helpers/file_helper.rb +0 -44
  170. data/lib/lono/builder/template/dsl/evaluator/helpers/s3_helper.rb +0 -16
  171. data/lib/lono/builder/template/dsl/evaluator/helpers.rb +0 -16
  172. data/lib/lono/builder/template/dsl/evaluator/squeezer.rb +0 -24
  173. data/lib/lono/builder/template/dsl/evaluator/syntax/extend_with.rb +0 -9
  174. data/lib/lono/builder/template/dsl/evaluator/syntax.rb +0 -11
  175. data/lib/lono/builder/template/dsl/evaluator.rb +0 -45
  176. data/lib/lono/builder/template/dsl/finalizer.rb +0 -12
  177. data/lib/lono/builder/template/evaluate.rb +0 -52
  178. data/lib/lono/builder/template/post_processor.rb +0 -67
  179. data/lib/lono/cli/build.rb +0 -101
  180. data/lib/lono/cli/code.rb +0 -22
  181. data/lib/lono/cli/help/blueprint/new.md +0 -56
  182. data/lib/lono/cli/new/extension.rb +0 -57
  183. data/lib/lono/configset/builder.rb +0 -59
  184. data/lib/lono/configset/combiner.rb +0 -164
  185. data/lib/lono/configset/evaluate_file.rb +0 -8
  186. data/lib/lono/configset/meta/dsl.rb +0 -12
  187. data/lib/lono/configset/meta.rb +0 -19
  188. data/lib/lono/configset/s3_file/build.rb +0 -34
  189. data/lib/lono/configset/s3_file/item.rb +0 -38
  190. data/lib/lono/configset/s3_file/registry.rb +0 -12
  191. data/lib/lono/configset/s3_file/upload.rb +0 -12
  192. data/lib/lono/configset/strategy/base.rb +0 -83
  193. data/lib/lono/configset/strategy/helpers/dsl/core.rb +0 -18
  194. data/lib/lono/configset/strategy/helpers/dsl.rb +0 -8
  195. data/lib/lono/configset/strategy/helpers/erb.rb +0 -9
  196. data/lib/lono/extensions/dsl.rb +0 -8
  197. data/lib/lono/extensions/loader.rb +0 -19
  198. data/lib/lono/extensions.rb +0 -18
  199. data/lib/lono/importer/base.rb +0 -48
  200. data/lib/lono/importer/converter.rb +0 -19
  201. data/lib/lono/importer/download.rb +0 -46
  202. data/lib/lono/importer/dsl.rb +0 -36
  203. data/lib/lono/importer/params.rb +0 -56
  204. data/lib/lono/importer/service/coder.rb +0 -81
  205. data/lib/lono/inspector/base.rb +0 -32
  206. data/lib/lono/lookup.rb +0 -12
  207. data/lib/lono/seeder/service_role.rb +0 -11
  208. data/lib/lono/utils/context.rb +0 -15
  209. data/lib/lono/utils/item/file_methods.rb +0 -29
  210. data/lib/lono/utils/item/zip.rb +0 -42
  211. data/lib/templates/extension/lib/%extension_name%/autoloader.rb.tt +0 -23
  212. data/lib/templates/extension/lib/%extension_name%/helpers/mappings.rb.tt +0 -24
  213. data/lib/templates/extension/lib/%extension_name%/helpers/outputs.rb.tt +0 -7
  214. data/lib/templates/extension/lib/%extension_name%/helpers/parameters.rb.tt +0 -10
  215. data/lib/templates/extension/lib/%extension_name%/helpers/resources/resource.rb.tt +0 -4
  216. data/lib/templates/extension/lib/%extension_name%/helpers/variables.rb.tt +0 -6
  217. data/lib/templates/extension/lib/%extension_name%/version.rb.tt +0 -3
  218. data/lib/templates/extension/lib/%extension_name%.rb.tt +0 -8
@@ -0,0 +1,50 @@
1
+ class Lono::Builder::Dsl::Finalizer::Files
2
+ class Build < Base
3
+ def initialize(options={})
4
+ super
5
+ @output_path = "#{Lono.root}/.output/files"
6
+ end
7
+
8
+ def run
9
+ return if Lono::Files.empty?
10
+ logger.debug "Building files"
11
+ clean
12
+ validate!
13
+ build_files
14
+ end
15
+
16
+ def build_files
17
+ Lono::Files.files.each do |file| # using singular file, but is like a "file_list"
18
+ file.build
19
+ file.build_lambda_layer(@cfn)
20
+ file.compress
21
+ # UploadNote: Instead of part of the build process here, uploading happen as part
22
+ # of create_stack or execute_change_set after user confirms action. IE:
23
+ # Cfn::Deploy#create and Cfn::Deploy#update
24
+ end
25
+ end
26
+
27
+ def clean
28
+ FileUtils.rm_rf(@output_path)
29
+ end
30
+
31
+ def validate!
32
+ missing = Lono::Files.files.select do |file|
33
+ !File.exist?(file.full_path)
34
+ end
35
+ return if missing.empty?
36
+
37
+ logger.info "ERROR: These files are missing".color(:red)
38
+ logger.info <<~EOL
39
+ The file helper is calling them.
40
+ They need to exist to be uploaded to s3.
41
+ EOL
42
+ missing.each do |file|
43
+ logger.info " #{pretty_path(file.full_path)}"
44
+ logger.info " Called at #{file.call_line}"
45
+ end
46
+ logger.info "Please double check that they exist."
47
+ exit 1
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,36 @@
1
+ class Lono::Builder::Dsl::Finalizer::Files
2
+ class Replace < Base
3
+ def run
4
+ replacements.each do |placeholder, replacement|
5
+ update_template!(@cfn)
6
+ end
7
+ @cfn
8
+ end
9
+
10
+ def replacements
11
+ data = Lono::Files.files.inject({}) do |result, file|
12
+ result.merge(file.marker => file.s3_key)
13
+ end
14
+ # Edge case when bucket is created for the first time and files_bucket is
15
+ # not available yet. So we call it at this point.
16
+ Lono::S3::Bucket.ensure_exist
17
+ data["LONO://S3_BUCKET"] = Lono::S3::Bucket.name
18
+ data
19
+ end
20
+
21
+ def update_template!(hash)
22
+ hash.each do |k, v|
23
+ if v.is_a?(String)
24
+ if v =~ %r{^LONO://}
25
+ v.replace(replacements[v]) # replace the placeholder
26
+ end
27
+ elsif v.is_a?(Hash)
28
+ update_template!(v) # recurse
29
+ elsif v.is_a?(Array)
30
+ v.each { |x| update_template!(x) if x.is_a?(Hash) }
31
+ end
32
+ end
33
+ hash
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ class Lono::Builder::Dsl::Finalizer
2
+ class Files < Base
3
+ # Replaces metadata under each logical id resource.
4
+ def run
5
+ Build.new(@options).run
6
+ @cfn = Replace.new(@options).run
7
+ end
8
+ end
9
+ end
@@ -1,10 +1,11 @@
1
- class Lono::Builder::Template::Dsl::Finalizer
2
- class ParameterGroups
1
+ class Lono::Builder::Dsl::Finalizer
2
+ class ParameterGroups < Base
3
3
  extend Memoist
4
- include Lono::Builder::Template::Dsl::Evaluator::Stringify
4
+ include Lono::Builder::Util::Stringify
5
5
 
6
- def initialize(cfn, parameters)
7
- @cfn, @parameters = cfn, parameters
6
+ def initialize(options={})
7
+ super
8
+ @parameters = options[:parameters]
8
9
  end
9
10
 
10
11
  def run
@@ -0,0 +1,15 @@
1
+ class Lono::Builder::Dsl
2
+ class Finalizer
3
+ def initialize(cfn, options={})
4
+ @cfn, @options = cfn, options
5
+ end
6
+
7
+ def run
8
+ o = @options.merge(cfn: @cfn)
9
+ @cfn = ParameterGroups.new(o).run
10
+ @cfn = Configsets.new(o).run
11
+ @cfn = Files.new(o).run
12
+ @cfn
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
- module Lono::Builder::Template::Dsl::Evaluator::Helpers
2
- module Ec2Helper
1
+ module Lono::Builder::Dsl::Helpers
2
+ module Ec2
3
3
  extend Memoist
4
4
 
5
5
  def default_vpc
@@ -20,7 +20,7 @@ module Lono::Builder::Template::Dsl::Evaluator::Helpers
20
20
  def key_pairs(regexp=nil)
21
21
  resp = ec2.describe_key_pairs
22
22
  key_names = resp.key_pairs.map(&:key_name)
23
- key_names.select! { |k| k =~ regexp }
23
+ key_names.select! { |k| k =~ regexp } if regexp
24
24
  key_names
25
25
  end
26
26
  end
@@ -0,0 +1,7 @@
1
+ module Lono::Builder::Dsl::Helpers
2
+ module Files
3
+ def files(path, o={})
4
+ Lono::Files.register(@options.merge(path: path).merge(o))
5
+ end
6
+ end
7
+ end
@@ -1,7 +1,7 @@
1
1
  require "aws-sdk-core"
2
2
 
3
- class Lono::Builder::Template
4
- module Helpers
3
+ module Lono::Builder::Dsl::Helpers
4
+ module Partials
5
5
  def template_s3_path(template_name)
6
6
  # hi-jacking Uploader for https_url
7
7
  template_path = "output/#{@blueprint.name}/templates/#{template_name}.yml"
@@ -9,9 +9,7 @@ class Lono::Builder::Template
9
9
  end
10
10
 
11
11
  def template_params(param_name)
12
- o = {
13
- allow_not_exists: true
14
- }.merge(@options)
12
+ o = @options.dup
15
13
  o["param"] = param_name
16
14
  generator = Lono::CLI::Param::Generator.new(o)
17
15
  # do not generate because lono cfn calling logic already generated it we only need the values
@@ -22,62 +20,54 @@ class Lono::Builder::Template
22
20
  end
23
21
  end
24
22
 
25
- # Adjust the partial path so that it will use app/user_data
26
- def user_data(path,vars={}, options={})
27
- options.merge!(user_data: true)
28
- partial(path,vars, options)
23
+ # The partial's path is a relative path.
24
+ #
25
+ # Example:
26
+ # Given file in app/partials/iam/docker.yml
27
+ #
28
+ # <%= partial("iam/docker", {}, indent: 10) %>
29
+ # <%= partial("iam/docker.yml", {}, indent: 10) %>
30
+ #
31
+ # If the user specifies the extension then use that instead of auto-adding
32
+ # the detected format.
33
+ def partial(path,vars={}, options={})
34
+ path = partial_path_for(path)
35
+ path = auto_add_format(path)
36
+
37
+ instance_variables!(vars)
38
+ result = render_path(path)
39
+
40
+ result = indent(result, options[:indent]) if options[:indent]
41
+ result + "\n"
29
42
  end
30
43
 
31
- def current_region
32
- region = Aws.config[:region]
33
- region ||= ENV['AWS_REGION']
34
- return region if region
35
-
36
- default_region = 'us-east-1' # fallback if default not found in ~/.aws/config
37
- if ENV['AWS_PROFILE']
38
- path = "#{ENV['HOME']}/.aws/config"
39
- if File.exist?(path)
40
- lines = IO.readlines(path)
41
- capture_default, capture_current = false, false
42
- lines.each do | line|
43
- if line.include?('[default]')
44
- capture_default = true # next line
45
- next
46
- end
47
- if capture_default && line.match(/region = /)
48
- # over default from above
49
- default_region = line.split(' = ').last.strip
50
- capture_default = false
51
- end
52
-
53
- md = line.match(/\[profile (.*)\]/)
54
- if md && md[1] == ENV['AWS_PROFILE']
55
- capture_current = true
56
- next
57
- end
58
- if capture_current && line.match(/region = /)
59
- region = line.split(' = ').last.strip
60
- capture_current = false
61
- end
62
- end
63
- end
64
-
65
- region ||= default_region
66
- return region if region
44
+ # Take a hash and makes them instance variables in the current scope.
45
+ # Use this in custom helper methods to make variables accessible to ERB templates.
46
+ def instance_variables!(variables)
47
+ variables.each do |key, value|
48
+ instance_variable_set('@' + key.to_s, value)
67
49
  end
50
+ end
68
51
 
69
- 'us-east-1' # default
52
+ # add indentation
53
+ def indent(text, indentation_amount)
54
+ text.split("\n").map do |line|
55
+ " " * indentation_amount + line
56
+ end.join("\n")
70
57
  end
71
58
 
72
- private
73
- def render_path(path)
74
- RenderMePretty.result(path, context: self)
59
+ def partial_exist?(path)
60
+ path = partial_path_for(path)
61
+ path = auto_add_format(path)
62
+ path && File.exist?(path)
75
63
  end
76
64
 
77
- def user_data_path_for(path)
78
- "#{Lono.config.paths.user_data}/#{path}"
65
+ def region
66
+ AwsData.region
79
67
  end
68
+ alias_method :current_region, :region
80
69
 
70
+ private
81
71
  def auto_add_format(path)
82
72
  # Return immediately if user provided explicit extension
83
73
  extension = File.extname(path) # current extension
@@ -107,16 +97,15 @@ class Lono::Builder::Template
107
97
 
108
98
  # Bash code that is meant to included in user-data
109
99
  def extract_scripts(options={})
110
- settings = Lono.config.extract_scripts
111
- options = settings.merge(options)
112
100
  # defaults also here in case they are removed from settings
101
+ path = options[:path]
113
102
  to = options[:to] || "/opt"
114
103
  user = options[:as] || "ec2-user"
115
104
 
116
- if Dir.glob("#{Lono.config.paths.scripts}/*").empty?
105
+ if Dir.glob("#{@bluepint.root}/#{path}*").empty?
117
106
  logger.info "WARN: you are using the extract_scripts helper method but you do not have any scripts.".color(:yellow)
118
107
  calling_line = caller[0].split(':')[0..1].join(':')
119
- logger.info "Called from: #{calling_line}"
108
+ logger.info "Called from1: #{calling_line}"
120
109
  return ""
121
110
  end
122
111
 
@@ -142,8 +131,10 @@ class Lono::Builder::Template
142
131
  upload.s3_dest
143
132
  end
144
133
 
145
- def setting
146
- @setting ||= Lono::Setting.new
134
+ def indent(text, indentation_amount)
135
+ text.split("\n").map do |line|
136
+ " " * indentation_amount + line
137
+ end.join("\n")
147
138
  end
148
139
  end
149
140
  end
@@ -0,0 +1,14 @@
1
+ module Lono::Builder::Dsl::Helpers
2
+ module S3
3
+ def s3_bucket
4
+ Lono::S3::Bucket.name
5
+ end
6
+ alias_method :lono_bucket, :s3_bucket
7
+
8
+ # Edge case when bucket is created for the first time and files_bucket is
9
+ # not available yet to be use by Finalizer::Files::Replace#replacements
10
+ def files_bucket
11
+ "LONO://S3_BUCKET"
12
+ end
13
+ end
14
+ end
@@ -1,8 +1,9 @@
1
1
  require 'aws-sdk-ssm'
2
2
 
3
- class Lono::Builder::Context
4
- class SsmFetcher
3
+ module Lono::Builder::Dsl::Helpers::Ssm
4
+ class Fetcher
5
5
  extend Memoist
6
+ include Lono::Utils::Logging
6
7
 
7
8
  def get(name)
8
9
  fetch_ssm_value(name)
@@ -12,7 +13,8 @@ class Lono::Builder::Context
12
13
  resp = ssm.get_parameter(name: name, with_decryption: true)
13
14
  resp.parameter.value
14
15
  rescue Aws::SSM::Errors::ParameterNotFound
15
- 'SSM-PARAM-NOT-FOUND'
16
+ logger.warn 'WARN: SSM-PARAM-NOT-FOUND'
17
+ nil
16
18
  end
17
19
 
18
20
  def ssm
@@ -1,5 +1,5 @@
1
- class Lono::Builder::Context
2
- module Helpers
1
+ module Lono::Builder::Dsl::Helpers
2
+ module Ssm
3
3
  extend Memoist
4
4
 
5
5
  def ssm(name)
@@ -7,7 +7,7 @@ class Lono::Builder::Context
7
7
  end
8
8
 
9
9
  def ssm_fetcher
10
- SsmFetcher.new
10
+ Fetcher.new
11
11
  end
12
12
  memoize :ssm_fetcher
13
13
  end
@@ -1,5 +1,5 @@
1
- module Lono::Builder::Template::Dsl::Evaluator::Helpers
2
- module StackHelper
1
+ module Lono::Builder::Dsl::Helpers
2
+ module Stack
3
3
  extend Memoist
4
4
  include Lono::AwsServices
5
5
 
@@ -15,7 +15,8 @@ module Lono::Builder::Template::Dsl::Evaluator::Helpers
15
15
  if o
16
16
  o.output_value
17
17
  else
18
- logger.info "WARN: NOT FOUND: output #{key} for stack #{stack_name}"
18
+ logger.info "WARN: STACK OUTPUT NOT FOUND: output #{key} for stack #{stack_name}"
19
+ nil
19
20
  end
20
21
  end
21
22
 
@@ -29,14 +30,13 @@ module Lono::Builder::Template::Dsl::Evaluator::Helpers
29
30
  resource.physical_resource_id
30
31
  else
31
32
  logger.info "WARN: NOT FOUND: logical_id #{logical_id} for stack #{stack_name}"
33
+ nil
32
34
  end
33
35
  end
34
36
 
35
37
  def stack_name(blueprint)
36
- return blueprint unless Lono.config.names.output.expand
37
38
  names = Lono::Names.new(blueprint: blueprint)
38
- # explicit expansion pattern provided by user
39
- pattern = blueprint.include?(':') ? blueprint : Lono.config.names.output.stack
39
+ pattern = blueprint # blueprint can be a pattern provided by user. IE: :BLUEPRINT-:ENV
40
40
  names.expansion(pattern)
41
41
  end
42
42
 
@@ -1,5 +1,5 @@
1
- module Lono::Builder::Template::Dsl::Evaluator::Helpers
2
- module TagsHelper
1
+ module Lono::Builder::Dsl::Helpers
2
+ module Tags
3
3
  def tags(hash={})
4
4
  if hash.empty?
5
5
  tag_list(@tags) if @tags # when hash is empty, use @tags variable. If not set then return nil
@@ -0,0 +1,66 @@
1
+ module Lono::Builder::Dsl::Helpers
2
+ module TemplateFile
3
+ extend Memoist
4
+ include Lono::Utils::Pretty
5
+
6
+ def template_file(path)
7
+ path = "#{@blueprint.root}/#{path}"
8
+ if File.exist?(path)
9
+ render_file(path)
10
+ else
11
+ template_file_missing(path)
12
+ end
13
+ end
14
+ # do not memoize :template_file - it'll hide the template_file_missing error
15
+
16
+ # Caller lines are different for OSes:
17
+ #
18
+ # windows: "C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/lono-1.1.1/lib/lono/builder.rb:34:in `build'"
19
+ # linux: "/home/ec2-user/.rvm/gems/ruby-3.0.3/gems/lono-1.1.1/lib/lono/compiler/dsl/syntax/mod.rb:4:in `<module:Mod>'"
20
+ #
21
+ class TempleFileNotFoundError < StandardError; end
22
+ def template_file_missing(path)
23
+ message = "ERROR: path #{pretty_path(path)} not found"
24
+ caller_line = caller.find { |l| l =~ %r{/blueprints/} }
25
+ logger.error message.color(:red)
26
+ logger.error "Called from:"
27
+ logger.error " #{pretty_path(caller_line)}"
28
+ # Raise an error so Dsl::Evaluator#template_evaluation_error provides user friendly info
29
+ raise TempleFileNotFoundError.new
30
+ end
31
+
32
+ def render_file(path)
33
+ if File.exist?(path)
34
+ RenderMePretty.result(path, context: self)
35
+ else
36
+ lines = caller.select { |l| l.include?(Lono.root.to_s) }
37
+ caller_line = pretty_path(lines.first)
38
+ message =<<~EOL
39
+ WARN: #{pretty_path(path)} does not exist
40
+ Called from: #{caller_line}
41
+ EOL
42
+ logger.info message.color(:yellow)
43
+ message
44
+ end
45
+ end
46
+ alias_method :render_path, :render_file
47
+
48
+ def user_data_script
49
+ unless @user_data_script
50
+ script_example = pretty_path("#{@blueprint.root}/template/user_data.sh")
51
+ return <<~EOL
52
+ # @user_data_script variable not set. IE: @user_data_script = "#{script_example}"
53
+ # Also, make sure that "#{script_example}" exists.
54
+ EOL
55
+ end
56
+
57
+ if File.exist?(@user_data_script)
58
+ render_file(@user_data_script)
59
+ else
60
+ message = "WARN: #{@user_data_script} not found"
61
+ logger.info message.color(:yellow)
62
+ "# #{message}"
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,5 @@
1
+ class Lono::Builder::Dsl
2
+ module Helpers
3
+ include_modules("helpers")
4
+ end
5
+ end
@@ -1,8 +1,7 @@
1
- module Lono::Builder::Template::Dsl::Evaluator::Section
1
+ module Lono::Builder::Dsl::Syntax::Core
2
2
  class Base
3
- include Lono::Builder::Template::Dsl::Evaluator::Fn
4
- include Lono::Builder::Template::Dsl::Evaluator::Helpers
5
- include Lono::Builder::Template::Dsl::Evaluator::Stringify
3
+ include Lono::Builder::Util::Stringify
4
+ include Lono::Builder::Dsl::Syntax::Fn
6
5
 
7
6
  def initialize(blueprint, *definition)
8
7
  @blueprint = blueprint
@@ -17,7 +16,7 @@ module Lono::Builder::Template::Dsl::Evaluator::Section
17
16
 
18
17
  # Remove items with nil value automatically
19
18
  def clean(data)
20
- Lono::Builder::Template::Dsl::Evaluator::Squeezer.new(data).squeeze
19
+ Squeezer.new(data).squeeze
21
20
  end
22
21
  end
23
22
  end
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # template - uses @definition to build a CloudFormation template section
4
4
  #
5
- module Lono::Builder::Template::Dsl::Evaluator::Section
5
+ module Lono::Builder::Dsl::Syntax::Core
6
6
  class Condition < Base
7
7
  def template
8
8
  camelize(standarize(@definition))
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # template - uses @definition to build a CloudFormation template section
4
4
  #
5
- module Lono::Builder::Template::Dsl::Evaluator::Section
5
+ module Lono::Builder::Dsl::Syntax::Core
6
6
  class Mapping < Base
7
7
  def template
8
8
  camelize(standarize(@definition))
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # template - uses @definition to build a CloudFormation template section
4
4
  #
5
- module Lono::Builder::Template::Dsl::Evaluator::Section
5
+ module Lono::Builder::Dsl::Syntax::Core
6
6
  class Output < Base
7
7
  def template
8
8
  camelize(standarize(@definition))
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # template - uses @definition to build a CloudFormation template section
4
4
  #
5
- module Lono::Builder::Template::Dsl::Evaluator::Section
5
+ module Lono::Builder::Dsl::Syntax::Core
6
6
  class Parameter < Base
7
7
  attr_accessor :group_label
8
8
  attr_reader :conditional, :label
@@ -1,12 +1,22 @@
1
- class Lono::Builder::Template::Dsl::Evaluator::Section::Resource
1
+ class Lono::Builder::Dsl::Syntax::Core::Resource
2
2
  # Moves the property to the top-level attributes *destructively*
3
3
  class PropertyMover
4
4
  def initialize(resource, logical_id, properties)
5
5
  @resource, @logical_id, @properties = resource, logical_id, properties
6
6
  end
7
7
 
8
+ # AWS Docs: Resource attribute reference
9
+ # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-product-attribute-reference.html
8
10
  def move!
9
- %w[Condition DeletionPolicy DependsOn].each do |attribute_name|
11
+ %w[
12
+ Condition
13
+ CreationPolicy
14
+ DeletionPolicy
15
+ DependsOn
16
+ Metadata
17
+ UpdatePolicy
18
+ UpdateReplacePolicy
19
+ ].each do |attribute_name|
10
20
  # Account for camelize, underscore, String, and Symbol
11
21
  move(attribute_name.to_sym)
12
22
  move(attribute_name.camelize.to_sym)
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # template - uses @definition to build a CloudFormation template section
4
4
  #
5
- module Lono::Builder::Template::Dsl::Evaluator::Section
5
+ module Lono::Builder::Dsl::Syntax::Core
6
6
  class Resource < Base
7
7
  def template
8
8
  camelize(standarize(@definition))
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # template - uses @definition to build a CloudFormation template section
4
4
  #
5
- module Lono::Builder::Template::Dsl::Evaluator::Section
5
+ module Lono::Builder::Dsl::Syntax::Core
6
6
  class Section < Base
7
7
  def template
8
8
  hash, _ = @definition
@@ -0,0 +1,40 @@
1
+ module Lono::Builder::Dsl::Syntax::Core
2
+ class Squeezer
3
+ def initialize(data)
4
+ @data = data
5
+ end
6
+
7
+ def squeeze(new_data=nil, previous_key=nil)
8
+ data = new_data.nil? ? @data : new_data
9
+
10
+ case data
11
+ when Array
12
+ # .compact prevents infinite loop when data = [nil] on accident
13
+ # IE: data[:key] = [nil]
14
+ data.compact.map! { |v| squeeze(v) }
15
+ when Hash
16
+ data.each_with_object({}) do |(k,v), squeezed|
17
+ # only remove nil and empty Array values within Hash structures
18
+ squeezed[k] = squeeze(v, k) unless v.nil? # || empty_array?(v, previous_key)
19
+ squeezed
20
+ end
21
+ else
22
+ data # do not transform
23
+ end
24
+ end
25
+
26
+ # Special case do not squeeze empty Array when previous_key is "yum". Handles:
27
+ #
28
+ # Metadata:
29
+ # AWS::CloudFormation::Init:
30
+ # config:
31
+ # packages:
32
+ # yum:
33
+ # httpd: []
34
+ #
35
+ def empty_array?(v, previous_key)
36
+ return false if previous_key.to_s == "yum"
37
+ v.is_a?(Array) && v.empty?
38
+ end
39
+ end
40
+ end
@@ -1,6 +1,6 @@
1
1
  # Organize core section method syntax here
2
- module Lono::Builder::Template::Dsl::Evaluator::Section
3
- module Methods
2
+ module Lono::Builder::Dsl::Syntax
3
+ module Core
4
4
  def aws_template_format_version(version_date)
5
5
  @cfn["AWSTemplateFormatVersion"] = version_date
6
6
  end
@@ -1,4 +1,4 @@
1
- class Lono::Builder::Template::Dsl::Evaluator
1
+ module Lono::Builder::Dsl::Syntax
2
2
  module Fn
3
3
  # Also act as documentation on the method signatures
4
4
  # Also used in Coder crafting so should always list all the functions here
@@ -102,8 +102,6 @@ class Lono::Builder::Template::Dsl::Evaluator
102
102
  else
103
103
  item
104
104
  end
105
- # list.map!(&:camelize) unless options[:autoformat] == false # TODO: maybe add as an option.
106
- # feel this may be to destructive since am going with auto_camelize false for resources now.
107
105
  args = [list[0], list[1..-1].join('.')]
108
106
  { "Fn::GetAtt" => args }
109
107
  end
@@ -1,4 +1,4 @@
1
- module Lono::Builder::Template::Dsl::Evaluator::Syntax
1
+ module Lono::Builder::Dsl::Syntax
2
2
  module ParameterGroup
3
3
  def parameter_group(label)
4
4
  @group_label = label