lono 8.0.0.pre.rc1 → 8.0.0.pre.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.cody/acceptance/bin/build.sh +5 -5
  3. data/CHANGELOG.md +11 -0
  4. data/README.md +2 -7
  5. data/lib/lono/app.rb +3 -0
  6. data/lib/lono/app_file/build.rb +1 -1
  7. data/lib/lono/builder/context/generic.rb +11 -0
  8. data/lib/lono/builder/context/{loader → loaders}/load_files.rb +1 -1
  9. data/lib/lono/builder/context/{loader.rb → loaders.rb} +2 -2
  10. data/lib/lono/builder/context/params.rb +2 -3
  11. data/lib/lono/builder/context/template.rb +4 -0
  12. data/lib/lono/builder/dsl/evaluator.rb +94 -0
  13. data/lib/lono/builder/{template/configset_injector.rb → dsl/finalizer/configsets.rb} +11 -22
  14. data/lib/lono/builder/{template/dsl → dsl}/finalizer/parameter_groups.rb +2 -2
  15. data/lib/lono/builder/{template/dsl → dsl}/finalizer.rb +2 -1
  16. data/lib/lono/builder/{template/dsl/evaluator/helpers/ec2_helper.rb → dsl/helpers/ec2.rb} +3 -3
  17. data/lib/lono/builder/{template/helpers.rb → dsl/helpers/partials.rb} +2 -6
  18. data/lib/lono/builder/{template/dsl/evaluator/helpers/s3_helper.rb → dsl/helpers/s3.rb} +2 -2
  19. data/lib/lono/builder/{context/ssm_fetcher.rb → dsl/helpers/ssm/fetcher.rb} +2 -2
  20. data/lib/lono/builder/{context/helpers.rb → dsl/helpers/ssm.rb} +3 -3
  21. data/lib/lono/builder/{template/dsl/evaluator/helpers/stack_helper.rb → dsl/helpers/stack.rb} +5 -3
  22. data/lib/lono/builder/{template/dsl/evaluator/helpers/tags_helper.rb → dsl/helpers/tags.rb} +2 -2
  23. data/lib/lono/builder/dsl/helpers/template_file.rb +54 -0
  24. data/lib/lono/builder/{template/dsl/evaluator → dsl}/helpers.rb +3 -4
  25. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/base.rb +4 -5
  26. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/condition.rb +1 -1
  27. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/mapping.rb +1 -1
  28. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/output.rb +1 -1
  29. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/parameter.rb +1 -1
  30. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/resource/property_mover.rb +1 -1
  31. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/resource.rb +1 -1
  32. data/lib/lono/builder/{template/dsl/evaluator/section → dsl/syntax/core}/section.rb +1 -1
  33. data/lib/lono/builder/{template/dsl/evaluator → dsl/syntax/core}/squeezer.rb +1 -1
  34. data/lib/lono/builder/{template/dsl/evaluator/section/methods.rb → dsl/syntax/core.rb} +2 -2
  35. data/lib/lono/builder/{template/dsl/evaluator → dsl/syntax}/fn.rb +1 -1
  36. data/lib/lono/builder/{template/dsl/evaluator → dsl}/syntax/parameter_group.rb +1 -1
  37. data/lib/lono/builder/dsl/syntax.rb +9 -0
  38. data/lib/lono/builder/{template/dsl.rb → dsl.rb} +1 -1
  39. data/lib/lono/builder/{template/dsl/evaluator → util}/stringify.rb +1 -1
  40. data/lib/lono/bundler/component/props/extension.rb +0 -1
  41. data/lib/lono/bundler/extract/tar.rb +0 -1
  42. data/lib/lono/cfn/deploy/iam.rb +0 -1
  43. data/lib/lono/cfn/plan/diff/file.rb +2 -1
  44. data/lib/lono/cli/abstract.rb +1 -1
  45. data/lib/lono/cli/build.rb +1 -11
  46. data/lib/lono/cli/help/cfn/status.md +0 -1
  47. data/lib/lono/cli/help/seed.md +22 -21
  48. data/lib/lono/cli/s3.rb +3 -3
  49. data/lib/lono/cli.rb +1 -0
  50. data/lib/lono/importer/service/coder.rb +67 -63
  51. data/lib/lono/logger.rb +1 -0
  52. data/lib/lono/s3/bucket.rb +26 -26
  53. data/lib/lono/s3/rollback.rb +8 -0
  54. data/lib/lono/seeder.rb +20 -2
  55. data/lib/lono/user_data.rb +1 -1
  56. data/lib/lono/utils/{context.rb → contexts.rb} +4 -4
  57. data/lib/lono/version.rb +1 -1
  58. metadata +36 -40
  59. data/lib/lono/builder/context.rb +0 -25
  60. data/lib/lono/builder/template/dsl/evaluator/helpers/core_helper.rb +0 -14
  61. data/lib/lono/builder/template/dsl/evaluator/helpers/file_helper.rb +0 -44
  62. data/lib/lono/builder/template/dsl/evaluator/syntax/extend_with.rb +0 -9
  63. data/lib/lono/builder/template/dsl/evaluator/syntax.rb +0 -11
  64. data/lib/lono/builder/template/dsl/evaluator.rb +0 -45
  65. data/lib/lono/builder/template/evaluate.rb +0 -52
  66. data/lib/lono/extensions/dsl.rb +0 -8
  67. data/lib/lono/extensions/loader.rb +0 -19
  68. data/lib/lono/extensions.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93888f3a1dc76f9c5e21f98c0edf5d03ee7ba4cdcf9e5a4115b0ee1ce0f3b518
4
- data.tar.gz: 22b18e2ccc2e98a41c57903aef1e67677f40dd48a953359447ef5546942f7ccb
3
+ metadata.gz: df8edbab23041858e8bea192749b440727066aeff707fa03edf5caf4dd529df9
4
+ data.tar.gz: 22f1143dd996e18bd6801080128605db30957c324136ce277c493497adb1f3bb
5
5
  SHA512:
6
- metadata.gz: 67562f7b0059f63f0cd33c93157f4bc0d7182125305b9602f67cb6d3a13094c1d6c1f84f0fe493800ba917cb2404b0f31c789744ff6ef2232b1629b7b51ef34f
7
- data.tar.gz: 7f9c0b5998e36e2acf9cef7dacdfd115ce8bcb49fde35c6664008fe31820e0ed4ce14c36897fc733c93ac93a5033770d1cdf4bf29d170420cc8335b0432cb35d
6
+ metadata.gz: 866583abf80bbf971b345e23e1b54a430542ad4f5b0578e7973761c88065ba8875c3ef6f724a4291e8c16ff35163e461db0ee563eda438b11539b5f7d7fa2409
7
+ data.tar.gz: 68e43613edfaa724c954541b4788a2365a0faa8e32d726ae84610255ad214b0d40c2ff84c830e8f44c73bbb9e00c9ab06708f614796f13738fcb7d2ca5f24056
@@ -1,7 +1,7 @@
1
1
  #!/bin/bash
2
2
 
3
3
  final_status=0
4
- function final_status {
4
+ function capture_status {
5
5
  if [ "$?" -ne "0" ] && [ $final_status -ne 1 ] ; then
6
6
  final_status=1
7
7
  fi
@@ -32,21 +32,21 @@ lono new blueprint demo --examples
32
32
  set +e
33
33
  # Test new stack creation
34
34
  lono up demo -y
35
- final_status
35
+ capture_status
36
36
 
37
37
  lono seed demo # just to test it. will overwrite file
38
- final_status
38
+ capture_status
39
39
 
40
40
  # Test stack update
41
41
  cat << EOF > config/blueprints/demo/params/$LONO_ENV.txt
42
42
  AccessControl=PublicRead
43
43
  EOF
44
44
  lono up demo -y
45
- final_status
45
+ capture_status
46
46
 
47
47
  # Clean up resources
48
48
  lono down demo -y
49
- final_status
49
+ capture_status
50
50
  set -e
51
51
 
52
52
  exit $final_status
data/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
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/).
5
5
 
6
+ ## [8.0.0.rc2] - 2022-02-23
7
+
8
+ * restructure builder and helpers
9
+ * improve template_evaluation_error
10
+ * lono seed --where option and config.seed.where
11
+ * return nil when output not found
12
+ * setup configsets finalizer
13
+ * template_file helper
14
+ * fix coder
15
+ * lono s3 bucket auto-creation
16
+
6
17
  ## [8.0.0.rc1] - 2022-02-21
7
18
 
8
19
  * v8 cleaner and simplier interface
data/README.md CHANGED
@@ -27,18 +27,13 @@ Lono is a CloudFormation framework. It builds, manages, and deploys CloudFormati
27
27
 
28
28
  See [lono.cloud](http://lono.cloud) for full lono documentation.
29
29
 
30
- ## Upgrading
31
-
32
- If you are on version 6 and upgrading to 7. You can run [lono upgrade](https://lono.cloud/reference/lono-upgrade/) within your project. Refer to the [Upgrading Guide](https://lono.cloud/docs/extras/upgrading/).
33
-
34
30
  ## Quick Usage
35
31
 
36
32
  It only takes a couple of commands to start using lono.
37
33
 
38
- gem install lono
39
- lono new infra
34
+ gem install lono --prerelease
35
+ lono new project infra --examples
40
36
  cd infra
41
- lono blueprint new demo
42
37
  lono up demo
43
38
 
44
39
  ![Lono flowchart](https://lono.cloud/img/tutorial/lono-flowchart.png "Lono flowchart")
data/lib/lono/app.rb CHANGED
@@ -50,6 +50,9 @@ module Lono
50
50
  config.layering = ActiveSupport::OrderedOptions.new
51
51
  config.layering.names = {}
52
52
 
53
+ config.seed = ActiveSupport::OrderedOptions.new
54
+ config.seed.where = "config"
55
+
53
56
  config
54
57
  end
55
58
 
@@ -59,7 +59,7 @@ module Lono::AppFile
59
59
  def copy_to_output
60
60
  override_source_paths("#{@blueprint.root}/app/files")
61
61
  self.destination_root = @output_files_path
62
- directory(".", verbose: false, context: context.get_binding) # Thor::Action
62
+ directory(".", verbose: false, context: template_context.get_binding) # Thor::Action
63
63
  end
64
64
 
65
65
  def clean_output
@@ -0,0 +1,11 @@
1
+ module Lono::Builder::Context
2
+ class Generic < Lono::CLI::Base
3
+ include Lono::Builder::Dsl::Syntax
4
+
5
+ # For Lono::AppFile::Build usage of Thor::Action directory
6
+ # For some reason a send(:binding) doesnt work but get_binding like this works.
7
+ def get_binding
8
+ binding
9
+ end
10
+ end
11
+ end
@@ -1,4 +1,4 @@
1
- module Lono::Builder::Context::Loader
1
+ module Lono::Builder::Context::Loaders
2
2
  module LoadFiles
3
3
  # Load custom helper methods from project
4
4
  def load_files(dir)
@@ -1,5 +1,5 @@
1
- class Lono::Builder::Context
2
- module Loader
1
+ module Lono::Builder::Context
2
+ module Loaders
3
3
  include LoadFiles
4
4
 
5
5
  # Variables in base.rb are overridden by their environment specific variables
@@ -1,6 +1,5 @@
1
- class Lono::Builder::Context
2
- class Params < Lono::Builder::Context
3
- # These helpers are only defined in the params context.
1
+ module Lono::Builder::Context
2
+ class Params < Generic
4
3
  # Overriding output resource DSL method
5
4
  alias_method :output, :stack_output
6
5
  end
@@ -0,0 +1,4 @@
1
+ module Lono::Builder::Context
2
+ class Template < Generic
3
+ end
4
+ end
@@ -0,0 +1,94 @@
1
+ class Lono::Builder::Dsl
2
+ class Evaluator < Lono::CLI::Base
3
+ include Lono::Builder::Context::Loaders
4
+ include Lono::Builder::Dsl::Syntax
5
+ include Lono::Utils::Pretty
6
+
7
+ def initialize(options={})
8
+ super
9
+ @template_path = "#{@blueprint.root}/template.rb"
10
+ @parameters = [] # built by parameter_groups.rb
11
+ @cfn = {}
12
+ end
13
+
14
+ def build
15
+ # TODO: load_all_extension_helpers # after Extensions::Preparer#run
16
+ load_variables unless seed? # both blueprint and project variables
17
+ load_blueprint_helpers
18
+ evaluate_template_paths(@template_path) # modifies @cfn
19
+ finalize
20
+ to_yaml
21
+ @cfn
22
+ end
23
+
24
+ def finalize
25
+ o = @options.merge(parameters: @parameters)
26
+ @cfn = Finalizer.new(@cfn, o).run
27
+ end
28
+
29
+ def to_yaml
30
+ # https://stackoverflow.com/questions/24508364/how-to-emit-yaml-in-ruby-expanding-aliases
31
+ # Trick to prevent YAML from emitting aliases
32
+ @cfn = YAML.load(@cfn.to_json)
33
+ end
34
+
35
+ # Dont want any existing files to prevent building the blueprint.
36
+ # This means that parameters cannot be based on vars. It's a trade-off.
37
+ def seed?
38
+ ARGV[0] == "seed"
39
+ end
40
+
41
+ # Example path: /full/path/to/project/app/blueprints/demo/template.rb
42
+ def evaluate_template_paths(path)
43
+ ext = File.extname(path)
44
+ folder = path.sub(ext, '')
45
+ expr = "#{folder}/**/*.rb"
46
+ evaluate_template_path(path) # process top-level template.rb first
47
+ Dir.glob(expr).each do |path|
48
+ evaluate_template_path(path)
49
+ end
50
+ end
51
+
52
+ def evaluate_template_path(path)
53
+ return unless File.exist?(path)
54
+ instance_eval(File.read(path), path)
55
+ rescue Exception => e
56
+ template_evaluation_error(e)
57
+ exit 1
58
+ end
59
+
60
+ # Prints out a user friendly task_definition error message
61
+ #
62
+ # Backtrace lines are different for OSes:
63
+ #
64
+ # windows: "C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/terraspace-1.1.1/lib/terraspace/builder.rb:34:in `build'"
65
+ # linux: "/home/ec2-user/.rvm/gems/ruby-3.0.3/gems/terraspace-1.1.1/lib/terraspace/compiler/dsl/syntax/mod.rb:4:in `<module:Mod>'"
66
+ #
67
+ def template_evaluation_error(e)
68
+ lines = e.backtrace.reject { |l| l.include?("/lib/lono/") }
69
+ error_info = lines.first
70
+ parts = error_info.split(':')
71
+ windows = error_info.match(/^[a-zA-Z]:/)
72
+ path = windows ? parts[1] : parts[0]
73
+ line_no = windows ? parts[2] : parts[1]
74
+ line_no = line_no.to_i
75
+ logger.debug e.message
76
+ logger.error "Error evaluating #{pretty_path(path)}".color(:red)
77
+ logger.error "Here's the line with the error:\n\n"
78
+
79
+ contents = IO.read(path)
80
+ content_lines = contents.split("\n")
81
+ context = 5 # lines of context
82
+ top, bottom = [line_no-context-1, 0].max, line_no+context-1
83
+ spacing = content_lines.size.to_s.size
84
+ content_lines[top..bottom].each_with_index do |line_content, index|
85
+ line_number = top+index+1
86
+ if line_number == line_no
87
+ logger.printf("%#{spacing}d %s\n".color(:red), line_number, line_content)
88
+ else
89
+ logger.printf("%#{spacing}d %s\n", line_number, line_content)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -1,17 +1,17 @@
1
- class Lono::Builder::Template
2
- class ConfigsetInjector < Lono::CLI::Base
3
- def initialize(options={})
4
- super
1
+ class Lono::Builder::Dsl::Finalizer
2
+ class Configsets
3
+ extend Memoist
4
+
5
+ def initialize(cfn)
6
+ @cfn = cfn
5
7
  end
6
8
 
7
9
  def run
8
- @cfn = load_template # initial
9
- @cfn = inject # overwrite
10
- write(@cfn)
10
+ @cfn = add # overwrite
11
11
  @cfn
12
12
  end
13
13
 
14
- def inject
14
+ def add
15
15
  metadata_map.each do |logical_id, metadata_configset|
16
16
  resource = @cfn["Resources"][logical_id]
17
17
 
@@ -32,21 +32,10 @@ class Lono::Builder::Template
32
32
  end
33
33
 
34
34
  def metadata_map
35
- combiner = Lono::Configset::Combiner.new(@cfn, @options)
36
- combiner.metadata_map
35
+ []
36
+ # combiner = Lono::Configset::Combiner.new(@cfn, @options)
37
+ # combiner.metadata_map
37
38
  end
38
39
  memoize :metadata_map
39
-
40
- def write(cfn)
41
- IO.write(template_path, YAML.dump(cfn))
42
- end
43
-
44
- def load_template
45
- YAML.load_file(template_path)
46
- end
47
-
48
- def template_path
49
- "#{Lono.root}/output/#{@blueprint.name}/templates/#{@template}.yml"
50
- end
51
40
  end
52
41
  end
@@ -1,7 +1,7 @@
1
- class Lono::Builder::Template::Dsl::Finalizer
1
+ class Lono::Builder::Dsl::Finalizer
2
2
  class ParameterGroups
3
3
  extend Memoist
4
- include Lono::Builder::Template::Dsl::Evaluator::Stringify
4
+ include Lono::Builder::Util::Stringify
5
5
 
6
6
  def initialize(cfn, parameters)
7
7
  @cfn, @parameters = cfn, parameters
@@ -1,4 +1,4 @@
1
- class Lono::Builder::Template::Dsl
1
+ class Lono::Builder::Dsl
2
2
  class Finalizer
3
3
  def initialize(cfn, options={})
4
4
  @cfn, @options = cfn, options
@@ -6,6 +6,7 @@ class Lono::Builder::Template::Dsl
6
6
 
7
7
  def run
8
8
  @cfn = ParameterGroups.new(@cfn, @options[:parameters]).run
9
+ @cfn = Configsets.new(@cfn).run
9
10
  @cfn
10
11
  end
11
12
  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
@@ -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"
@@ -141,9 +141,5 @@ class Lono::Builder::Template
141
141
  upload = Lono::Script::Upload.new(@options)
142
142
  upload.s3_dest
143
143
  end
144
-
145
- def setting
146
- @setting ||= Lono::Setting.new
147
- end
148
144
  end
149
145
  end
@@ -1,5 +1,5 @@
1
- module Lono::Builder::Template::Dsl::Evaluator::Helpers
2
- module S3Helper
1
+ module Lono::Builder::Dsl::Helpers
2
+ module S3
3
3
  def s3_bucket
4
4
  Lono::S3::Bucket.name
5
5
  end
@@ -1,7 +1,7 @@
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
6
 
7
7
  def get(name)
@@ -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 "WARN2: NOT FOUND: output #{key} for stack #{stack_name}"
19
+ nil
19
20
  end
20
21
  end
21
22
 
@@ -29,6 +30,7 @@ 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
 
@@ -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,54 @@
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/terraspace-1.1.1/lib/terraspace/builder.rb:34:in `build'"
19
+ # linux: "/home/ec2-user/.rvm/gems/ruby-3.0.3/gems/terraspace-1.1.1/lib/terraspace/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/} } # TODO: show code itself
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
+ RenderMePretty.result(path, context: template_context)
34
+ end
35
+ memoize :render_file
36
+
37
+ def user_data_script
38
+ unless @user_data_script
39
+ return <<~EOL
40
+ # @user_data_script variable not set. IE: @user_data_script = "#{pretty_path(@blueprint.root)}/template/user_data.sh"
41
+ # Also, make sure that "config/#{@blueprint.name}/user_data/boostrap.sh" path you're using exists.
42
+ EOL
43
+ end
44
+
45
+ if File.exist?(@user_data_script)
46
+ render_file(@user_data_script)
47
+ else
48
+ message = "WARN: #{@user_data_script} not found"
49
+ logger.info message.color(:yellow)
50
+ "# #{message}"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,16 +1,15 @@
1
1
  # Built-in helpers for the DSL form
2
- class Lono::Builder::Template::Dsl::Evaluator
2
+ class Lono::Builder::Dsl
3
3
  module Helpers
4
4
  extend Memoist
5
5
 
6
6
  # Auto include all modules in helpers folder
7
+ # only load one level deep. IE: ssm/fetcher is a class
7
8
  helpers_dir = File.expand_path("helpers", __dir__)
8
- Dir.glob("#{helpers_dir}/**/*").each do |path|
9
+ Dir.glob("#{helpers_dir}/*.rb").each do |path|
9
10
  next unless File.file?(path)
10
11
  klass = path.gsub(%r{.*/lib/},'').sub(".rb",'').camelize
11
12
  include klass.constantize
12
13
  end
13
-
14
- include Lono::Builder::Template::Helpers
15
14
  end
16
15
  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,4 +1,4 @@
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)
@@ -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
@@ -1,4 +1,4 @@
1
- class Lono::Builder::Template::Dsl::Evaluator
1
+ module Lono::Builder::Dsl::Syntax::Core
2
2
  class Squeezer
3
3
  def initialize(data)
4
4
  @data = data
@@ -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
@@ -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
@@ -0,0 +1,9 @@
1
+ # Encapsulates syntax methods so they can be included in both the Evaluator and Context scope
2
+ class Lono::Builder::Dsl
3
+ module Syntax
4
+ include Fn
5
+ include Core
6
+ include ParameterGroup
7
+ include Helpers
8
+ end
9
+ end
@@ -1,4 +1,4 @@
1
- class Lono::Builder::Template
1
+ module Lono::Builder
2
2
  class Dsl < Lono::CLI::Base
3
3
  attr_reader :results
4
4
  def run
@@ -1,4 +1,4 @@
1
- class Lono::Builder::Template::Dsl::Evaluator
1
+ module Lono::Builder::Util
2
2
  module Stringify
3
3
  # Accounts for Arrays also. ActiveSupport only works for Hashes.
4
4
  def stringify!(data)