lono 8.0.0.pre.rc2 → 8.0.0.pre.rc3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -2
  3. data/Gemfile +1 -3
  4. data/lib/lono/app/callable_option/concern.rb +12 -0
  5. data/lib/lono/app/callable_option.rb +56 -0
  6. data/lib/lono/app.rb +22 -23
  7. data/lib/lono/autoloader.rb +1 -0
  8. data/lib/lono/aws_services/helper.rb +0 -2
  9. data/lib/lono/blueprint.rb +1 -18
  10. data/lib/lono/builder/allow/base.rb +54 -0
  11. data/lib/lono/builder/allow/env.rb +17 -0
  12. data/lib/lono/builder/allow/region.rb +20 -0
  13. data/lib/lono/builder/allow.rb +8 -0
  14. data/lib/lono/builder/configset/combiner.rb +145 -0
  15. data/lib/lono/builder/configset/definition/base.rb +47 -0
  16. data/lib/lono/builder/configset/definition/context.rb +29 -0
  17. data/lib/lono/{configset/strategy/helpers/dsl → builder/configset/definition/dsl/syntax}/auth.rb +1 -1
  18. data/lib/lono/{configset/strategy/helpers/dsl/core.rb → builder/configset/definition/dsl/syntax/content.rb} +12 -4
  19. data/lib/lono/{configset/strategy/helpers/dsl/syntax.rb → builder/configset/definition/dsl/syntax/core.rb} +15 -9
  20. data/lib/lono/{configset/strategy/helpers/dsl → builder/configset/definition/dsl/syntax}/package.rb +1 -1
  21. data/lib/lono/builder/configset/definition/dsl/syntax.rb +5 -0
  22. data/lib/lono/{configset/strategy → builder/configset/definition}/dsl.rb +10 -14
  23. data/lib/lono/{configset/strategy → builder/configset/definition}/erb.rb +13 -16
  24. data/lib/lono/builder/configset/definition.rb +18 -0
  25. data/lib/lono/builder/configset/evaluator.rb +10 -0
  26. data/lib/lono/builder/configset/registration.rb +35 -0
  27. data/lib/lono/builder/context.rb +40 -0
  28. data/lib/lono/builder/dsl/evaluator.rb +6 -55
  29. data/lib/lono/builder/dsl/finalizer/base.rb +8 -0
  30. data/lib/lono/builder/dsl/finalizer/configsets.rb +7 -28
  31. data/lib/lono/builder/dsl/finalizer/files/base.rb +4 -0
  32. data/lib/lono/builder/dsl/finalizer/files/build.rb +58 -0
  33. data/lib/lono/builder/dsl/finalizer/files/replace.rb +31 -0
  34. data/lib/lono/builder/dsl/finalizer/files.rb +9 -0
  35. data/lib/lono/builder/dsl/finalizer/parameter_groups.rb +4 -3
  36. data/lib/lono/builder/dsl/finalizer.rb +4 -2
  37. data/lib/lono/builder/dsl/helpers/files.rb +7 -0
  38. data/lib/lono/builder/dsl/helpers/partials.rb +48 -53
  39. data/lib/lono/builder/dsl/helpers/s3.rb +1 -1
  40. data/lib/lono/builder/dsl/helpers/ssm/fetcher.rb +3 -1
  41. data/lib/lono/builder/dsl/helpers/template_file.rb +18 -6
  42. data/lib/lono/builder/dsl/helpers.rb +1 -11
  43. data/lib/lono/builder/dsl/syntax/core/resource/property_mover.rb +11 -1
  44. data/lib/lono/builder/dsl/syntax/core/squeezer.rb +16 -2
  45. data/lib/lono/builder/dsl.rb +1 -1
  46. data/lib/lono/builder/param.rb +4 -1
  47. data/lib/lono/builder/template/upload.rb +2 -15
  48. data/lib/lono/cfn/cancel.rb +5 -5
  49. data/lib/lono/cfn/deploy/iam.rb +1 -1
  50. data/lib/lono/cfn/deploy.rb +32 -3
  51. data/lib/lono/cfn/download.rb +0 -1
  52. data/lib/lono/cfn/plan/changeset.rb +2 -2
  53. data/lib/lono/cfn/plan/diff/data.rb +11 -1
  54. data/lib/lono/cfn/plan/param.rb +1 -1
  55. data/lib/lono/cfn/plan/template.rb +2 -2
  56. data/lib/lono/cfn/plan.rb +1 -0
  57. data/lib/lono/cli/abstract.rb +0 -6
  58. data/lib/lono/cli/base.rb +5 -3
  59. data/lib/lono/cli/build.rb +16 -60
  60. data/lib/lono/cli/clean.rb +3 -2
  61. data/lib/lono/cli/code.rb +12 -12
  62. data/lib/lono/cli/help/new/helper/blueprint.md +17 -0
  63. data/lib/lono/cli/help/new/helper/project.md +16 -0
  64. data/lib/lono/cli/list.rb +3 -6
  65. data/lib/lono/cli/new/blueprint.rb +3 -7
  66. data/lib/lono/cli/new/configset.rb +11 -44
  67. data/lib/lono/cli/new/helper/blueprint.rb +26 -0
  68. data/lib/lono/cli/new/helper/project.rb +24 -0
  69. data/lib/lono/cli/new/helper.rb +8 -27
  70. data/lib/lono/cli/new/sequence.rb +6 -1
  71. data/lib/lono/cli/new.rb +8 -12
  72. data/lib/lono/cli/status.rb +18 -0
  73. data/lib/lono/cli.rb +6 -9
  74. data/lib/lono/command.rb +0 -1
  75. data/lib/lono/component.rb +29 -0
  76. data/lib/lono/concerns/aws_info.rb +14 -0
  77. data/lib/lono/concerns/names.rb +9 -0
  78. data/lib/lono/configset.rb +17 -0
  79. data/lib/lono/core.rb +1 -1
  80. data/lib/lono/ext/bundler.rb +7 -0
  81. data/lib/lono/ext/core/module.rb +31 -0
  82. data/lib/lono/ext/core/object.rb +32 -0
  83. data/lib/lono/ext/core/string.rb +9 -0
  84. data/lib/lono/ext.rb +4 -0
  85. data/lib/lono/files/base.rb +12 -0
  86. data/lib/lono/files/builder.rb +37 -0
  87. data/lib/lono/files/compressor.rb +53 -0
  88. data/lib/lono/files/concerns/post_processing.rb +35 -0
  89. data/lib/lono/files/concerns/registration.rb +13 -0
  90. data/lib/lono/files/registry.rb +6 -0
  91. data/lib/lono/files.rb +37 -0
  92. data/lib/lono/importer/base.rb +1 -1
  93. data/lib/lono/inspector/summary.rb +0 -3
  94. data/lib/lono/layering/layer.rb +3 -17
  95. data/lib/lono/logger.rb +1 -3
  96. data/lib/lono/names.rb +1 -1
  97. data/lib/lono/s3/uploader.rb +29 -28
  98. data/lib/lono/seeder.rb +18 -27
  99. data/lib/lono/user_data.rb +3 -1
  100. data/lib/lono/version.rb +1 -1
  101. data/lib/lono/yamler/validator.rb +7 -22
  102. data/lib/lono.rb +8 -0
  103. data/lib/templates/configset/configset.rb +2 -16
  104. data/lib/templates/examples/configset/configset.rb +16 -0
  105. data/lib/templates/helper/%underscore_name%_helper.rb.tt +1 -1
  106. data/lono.gemspec +1 -1
  107. metadata +52 -39
  108. data/lib/lono/app_file/base.rb +0 -28
  109. data/lib/lono/app_file/build/lambda_layer/ruby_packager.rb +0 -153
  110. data/lib/lono/app_file/build/lambda_layer.rb +0 -20
  111. data/lib/lono/app_file/build.rb +0 -79
  112. data/lib/lono/app_file/registry/item.rb +0 -24
  113. data/lib/lono/app_file/registry.rb +0 -16
  114. data/lib/lono/app_file/upload.rb +0 -12
  115. data/lib/lono/builder/context/generic.rb +0 -11
  116. data/lib/lono/builder/context/loaders/load_files.rb +0 -23
  117. data/lib/lono/builder/context/loaders.rb +0 -35
  118. data/lib/lono/builder/context/params.rb +0 -6
  119. data/lib/lono/builder/context/template.rb +0 -4
  120. data/lib/lono/configset/builder.rb +0 -59
  121. data/lib/lono/configset/combiner.rb +0 -164
  122. data/lib/lono/configset/evaluate_file.rb +0 -8
  123. data/lib/lono/configset/meta/dsl.rb +0 -12
  124. data/lib/lono/configset/meta.rb +0 -19
  125. data/lib/lono/configset/s3_file/build.rb +0 -34
  126. data/lib/lono/configset/s3_file/item.rb +0 -38
  127. data/lib/lono/configset/s3_file/registry.rb +0 -12
  128. data/lib/lono/configset/s3_file/upload.rb +0 -12
  129. data/lib/lono/configset/strategy/base.rb +0 -83
  130. data/lib/lono/configset/strategy/helpers/dsl.rb +0 -8
  131. data/lib/lono/configset/strategy/helpers/erb.rb +0 -9
  132. data/lib/lono/lookup.rb +0 -12
  133. data/lib/lono/seeder/service_role.rb +0 -11
  134. data/lib/lono/utils/contexts.rb +0 -15
  135. data/lib/lono/utils/item/file_methods.rb +0 -29
  136. data/lib/lono/utils/item/zip.rb +0 -42
@@ -1,29 +1,25 @@
1
- module Lono::Configset::Strategy
1
+ class Lono::Builder::Configset::Definition
2
2
  class Dsl < Base
3
- # Configset helpers take higher precedence than Lono DSL Helpers. IE: s3_key is overwritten but s3_bucket is the same
4
- include Helpers::Dsl
3
+ include Syntax
5
4
 
6
5
  def initialize(options={})
7
6
  super
8
- @structure = {} # holds in memory the configset hash structure to build AWS::CloudFormation::Init
9
7
  @current = "main" # current configset
10
- @command_counts = Hash.new(0)
11
8
  @tracked = []
9
+ @structure = {} # holds in memory the configset hash structure to build AWS::CloudFormation::Init
10
+ @command_counts = Hash.new(0)
12
11
  # Also support ability to add AWS::CloudFormation::Authentication
13
12
  @authentication = nil # holds IAM policy info to build AWS::CloudFormation::Authentication
14
13
  end
15
14
 
16
- def find_evaluation_path
17
- "#{@root}/lib/configset.rb"
18
- end
19
-
20
- def load
21
- evaluate_file(@evaluation_path)
22
- configsets = @configsets || @tracked.uniq
15
+ def evaluate
16
+ load_context
17
+ evaluate_file(@configset.path)
18
+ configsets = configsets || @tracked.uniq
23
19
  configsets = ["main"] if configsets.empty?
24
20
  configsets_structure = {"configSets" => {"default" => configsets}}.merge(@structure)
25
- full = { "AWS::CloudFormation::Init" => configsets_structure }
26
- full.deep_stringify_keys!
21
+ cloudformation_init = { "AWS::CloudFormation::Init" => configsets_structure }
22
+ wrap_with_metadata(cloudformation_init)
27
23
  end
28
24
  end
29
25
  end
@@ -1,29 +1,22 @@
1
- require "json"
2
-
3
- module Lono::Configset::Strategy
1
+ class Lono::Builder::Configset::Definition
4
2
  class Erb < Base
5
- include Helpers::Erb
6
-
7
- def find_evaluation_path
8
- paths = %w[configset.yml configset.json].map { |p| "#{@root}/lib/#{p}" }
9
- paths.find { |p| File.exist?(p) }
3
+ def evaluate
4
+ load_context
5
+ cloudformation_init = build
6
+ wrap_with_metadata(cloudformation_init)
10
7
  end
11
8
 
12
- def load
13
- content = RenderMePretty.result(@evaluation_path, context: self)
14
- # init structure
15
- if File.extname(@evaluation_path) == ".yml"
9
+ def build
10
+ content = RenderMePretty.result(@configset.path, context: self)
11
+ if File.extname(@configset.path) == ".yml"
16
12
  load_yaml(content)
17
13
  else
18
14
  JSON.load(content)
19
15
  end
20
16
  end
21
17
 
22
- def authentication
23
- # noop
24
- end
25
-
26
18
  def load_yaml(content)
19
+ # init structure
27
20
  # Write to file so can use Yamler::Validator
28
21
  path = "/tmp/lono/configset.yml"
29
22
  FileUtils.mkdir_p(File.dirname(path))
@@ -31,5 +24,9 @@ module Lono::Configset::Strategy
31
24
  Lono::Yamler::Validator.new(path).validate!
32
25
  Lono::Yamler::Loader.new(content).load
33
26
  end
27
+
28
+ def authentication
29
+ # noop
30
+ end
34
31
  end
35
32
  end
@@ -0,0 +1,18 @@
1
+ module Lono::Builder::Configset
2
+ class Definition < Lono::CLI::Base
3
+ attr_reader :configset
4
+ def initialize(options={})
5
+ super
6
+ @meta = options[:meta]
7
+ @configset = Lono::Configset.new(@meta)
8
+ end
9
+
10
+ def evaluate
11
+ strategy_class = configset.path.include?('.rb') ? Dsl : Erb
12
+ strategy = strategy_class.new(@options.merge(path: configset.path))
13
+ metadata = strategy.evaluate
14
+ @configset.metadata = metadata
15
+ @configset
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ # Dsl or Erb
2
+ module Lono::Builder::Configset
3
+ class Evaluator < Lono::CLI::Base
4
+ def evaluate
5
+ Registration.new(@blueprint).evaluate
6
+ combiner = Combiner.new(@options.merge(metas: Registration.metas))
7
+ combiner.combine
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,35 @@
1
+ module Lono::Builder::Configset
2
+ class Registration
3
+ include DslEvaluator
4
+
5
+ def initialize(blueprint)
6
+ @blueprint = blueprint
7
+ end
8
+
9
+ cattr_accessor :metas, default: []
10
+ def metas
11
+ self.class.metas
12
+ end
13
+
14
+ def evaluate
15
+ path = "#{@blueprint.root}/configsets.rb" # plural
16
+ evaluate_file(path)
17
+ end
18
+
19
+ # Only one syntax method so not in separate module.
20
+ #
21
+ # Register configset for later processing.
22
+ # By registering them all up front, can aggregate errors and show them together
23
+ # for a user-friendly experience.
24
+ #
25
+ # The configset method is different with configset registration vs configset definition
26
+ #
27
+ # definition: app/configsets/httpd/configset.rb
28
+ # registration: app/blueprints/demo/configsets.rb
29
+ #
30
+ def configset(name, options={})
31
+ found = metas.detect { |i| i[:name] == name && i[:resource] == options[:resource] }
32
+ metas << options.merge(name: name) unless found
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,40 @@
1
+ module Lono::Builder
2
+ module Context
3
+ include DslEvaluator
4
+
5
+ def load_context
6
+ load_variables
7
+ load_helpers
8
+ end
9
+
10
+ # Variables in base.rb are overridden by their environment specific variables
11
+ # file. Example, file LONO_ENV=dev:
12
+ #
13
+ # config/vars/base.rb
14
+ # config/vars/dev.rb - will override any variables in base.rb
15
+ # config/vars/base.rb
16
+ # config/vars/dev.rb - will override any variables in base.rb
17
+ #
18
+ def load_variables
19
+ return if seed?
20
+ layers = Lono::Layering::Layer.new(@blueprint, "vars").paths
21
+ layers.each do |layer|
22
+ evaluate_file(layer)
23
+ end
24
+ end
25
+
26
+ # Load blueprint helpers
27
+ # blueprint helpers override extension helpers
28
+ def load_helpers
29
+ load_helper_files("#{Lono.root}/vendor/helpers", type: :project)
30
+ load_helper_files("#{Lono.root}/app/helpers", type: :project)
31
+ load_helper_files("#{@blueprint.root}/helpers", type: :blueprint) # takes higher precedence
32
+ end
33
+
34
+ # Dont want any existing files to prevent building the blueprint.
35
+ # This means that parameters cannot be based on vars. It's a trade-off.
36
+ def seed?
37
+ ARGV[0] == "seed"
38
+ end
39
+ end
40
+ end
@@ -1,6 +1,7 @@
1
1
  class Lono::Builder::Dsl
2
2
  class Evaluator < Lono::CLI::Base
3
- include Lono::Builder::Context::Loaders
3
+ include DslEvaluator
4
+ include Lono::Builder::Context
4
5
  include Lono::Builder::Dsl::Syntax
5
6
  include Lono::Utils::Pretty
6
7
 
@@ -11,10 +12,8 @@ class Lono::Builder::Dsl
11
12
  @cfn = {}
12
13
  end
13
14
 
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
15
+ def evaluate
16
+ load_context
18
17
  evaluate_template_paths(@template_path) # modifies @cfn
19
18
  finalize
20
19
  to_yaml
@@ -32,62 +31,14 @@ class Lono::Builder::Dsl
32
31
  @cfn = YAML.load(@cfn.to_json)
33
32
  end
34
33
 
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
34
  # Example path: /full/path/to/project/app/blueprints/demo/template.rb
42
35
  def evaluate_template_paths(path)
43
36
  ext = File.extname(path)
44
37
  folder = path.sub(ext, '')
45
38
  expr = "#{folder}/**/*.rb"
46
- evaluate_template_path(path) # process top-level template.rb first
39
+ evaluate_file(path) # process top-level template.rb first
47
40
  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
41
+ evaluate_file(path)
91
42
  end
92
43
  end
93
44
  end
@@ -0,0 +1,8 @@
1
+ class Lono::Builder::Dsl::Finalizer
2
+ class Base < Lono::CLI::Base
3
+ def initialize(options={})
4
+ super
5
+ @cfn = options[:cfn]
6
+ end
7
+ end
8
+ end
@@ -1,41 +1,20 @@
1
1
  class Lono::Builder::Dsl::Finalizer
2
- class Configsets
3
- extend Memoist
4
-
5
- def initialize(cfn)
6
- @cfn = cfn
7
- end
8
-
2
+ class Configsets < Base
3
+ # Replaces metadata under each logical id resource.
9
4
  def run
10
- @cfn = add # overwrite
11
- @cfn
12
- end
13
-
14
- def add
15
- metadata_map.each do |logical_id, metadata_configset|
5
+ dsl = Lono::Builder::Configset::Evaluator.new(@options.merge(cfn: @cfn))
6
+ metadata_map = dsl.evaluate
7
+ metadata_map.each do |logical_id, cs|
16
8
  resource = @cfn["Resources"][logical_id]
17
-
18
9
  unless resource
19
- logger.info "WARN: Resources.#{logical_id} not found in the template. Are you sure you are specifying the correct resource id in your configsets configs?".color(:yellow)
10
+ puts "WARN: Resources.#{logical_id} not found in the template. Are you sure you specified the correct resource logical id in your configsets.rb?".color(:yellow)
20
11
  next
21
12
  end
22
13
 
23
- resource["Metadata"] ||= metadata_configset["Metadata"]
24
-
25
- # metdata = resource["Metadata"] ||= {}
26
- # metdata["AWS::CloudFormation::Init"] ||= {}
27
- # # The metadata_configset has been combined with the original AWS::CloudFormation::Init if it exists
28
- # metdata["AWS::CloudFormation::Init"] = metadata_configset["AWS::CloudFormation::Init"]
14
+ resource["Metadata"] = cs["Metadata"]
29
15
  end
30
16
 
31
17
  @cfn
32
18
  end
33
-
34
- def metadata_map
35
- []
36
- # combiner = Lono::Configset::Combiner.new(@cfn, @options)
37
- # combiner.metadata_map
38
- end
39
- memoize :metadata_map
40
19
  end
41
20
  end
@@ -0,0 +1,4 @@
1
+ class Lono::Builder::Dsl::Finalizer::Files
2
+ class Base < Lono::Builder::Dsl::Finalizer::Base
3
+ end
4
+ end
@@ -0,0 +1,58 @@
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
+ # build_layers
15
+ end
16
+
17
+ def build_files
18
+ Lono::Files.files.each do |file| # using singular file, but is like a "file_list"
19
+ file.build
20
+ file.compress
21
+ # Note: Uploading files happen right before create_stack or execute_change_set
22
+ # after user confirms action, instead of part of the build process
23
+ end
24
+ end
25
+
26
+ # TODO: LambdaLayer support
27
+ # def build_layers
28
+ # layer_items = Registry.layers
29
+ # layer_items.each do |item|
30
+ # LambdaLayer.new(@blueprint, item).build
31
+ # end
32
+ # end
33
+ #
34
+
35
+ def clean
36
+ FileUtils.rm_rf(@output_path)
37
+ end
38
+
39
+ def validate!
40
+ missing = Lono::Files.files.select do |file|
41
+ !File.exist?(file.full_path)
42
+ end
43
+ return if missing.empty?
44
+
45
+ logger.info "ERROR: These files are missing".color(:red)
46
+ logger.info <<~EOL
47
+ The file helper is calling them.
48
+ They need to exist to be uploaded to s3.
49
+ EOL
50
+ missing.each do |file|
51
+ logger.info " #{pretty_path(file.full_path)}"
52
+ logger.info " Called at #{file.call_line}"
53
+ end
54
+ logger.info "Please double check that they exist."
55
+ exit 1
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,31 @@
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
+ Lono::Files.files.inject({}) do |result, file|
12
+ result.merge(file.marker => file.s3_key)
13
+ end
14
+ end
15
+
16
+ def update_template!(hash)
17
+ hash.each do |k, v|
18
+ if v.is_a?(String)
19
+ if v =~ %r{^LONO://}
20
+ v.replace(replacements[v]) # replace the placeholder
21
+ end
22
+ elsif v.is_a?(Hash)
23
+ update_template!(v) # recurse
24
+ elsif v.is_a?(Array)
25
+ v.each { |x| update_template!(x) if x.is_a?(Hash) }
26
+ end
27
+ end
28
+ hash
29
+ end
30
+ end
31
+ 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
1
  class Lono::Builder::Dsl::Finalizer
2
- class ParameterGroups
2
+ class ParameterGroups < Base
3
3
  extend Memoist
4
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
@@ -5,8 +5,10 @@ class Lono::Builder::Dsl
5
5
  end
6
6
 
7
7
  def run
8
- @cfn = ParameterGroups.new(@cfn, @options[:parameters]).run
9
- @cfn = Configsets.new(@cfn).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
10
12
  @cfn
11
13
  end
12
14
  end
@@ -0,0 +1,7 @@
1
+ module Lono::Builder::Dsl::Helpers
2
+ module Files
3
+ def files(path)
4
+ Lono::Files.register(@options.merge(path: path))
5
+ end
6
+ end
7
+ end
@@ -9,9 +9,7 @@ module Lono::Builder::Dsl::Helpers
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 @@ module Lono::Builder::Dsl::Helpers
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 @@ module Lono::Builder::Dsl::Helpers
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
 
@@ -141,5 +130,11 @@ module Lono::Builder::Dsl::Helpers
141
130
  upload = Lono::Script::Upload.new(@options)
142
131
  upload.s3_dest
143
132
  end
133
+
134
+ def indent(text, indentation_amount)
135
+ text.split("\n").map do |line|
136
+ " " * indentation_amount + line
137
+ end.join("\n")
138
+ end
144
139
  end
145
140
  end
@@ -4,11 +4,11 @@ module Lono::Builder::Dsl::Helpers
4
4
  Lono::S3::Bucket.name
5
5
  end
6
6
  alias_method :lono_bucket_name, :s3_bucket
7
+ alias_method :files_bucket, :s3_bucket
7
8
 
8
9
  def s3_key(name, options={})
9
10
  default = {type: "file"}
10
11
  options.reverse_merge!(default)
11
- Lono::AppFile::Registry.register(name, @blueprint.name, options)
12
12
  "file://app/files/#{options[:type]}/#{name}" # placeholder for post processing
13
13
  end
14
14
  alias_method :file_s3_key, :s3_key
@@ -3,6 +3,7 @@ require 'aws-sdk-ssm'
3
3
  module Lono::Builder::Dsl::Helpers::Ssm
4
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 @@ module Lono::Builder::Dsl::Helpers::Ssm
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