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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -2
- data/Gemfile +1 -3
- data/lib/lono/app/callable_option/concern.rb +12 -0
- data/lib/lono/app/callable_option.rb +56 -0
- data/lib/lono/app.rb +22 -23
- data/lib/lono/autoloader.rb +1 -0
- data/lib/lono/aws_services/helper.rb +0 -2
- data/lib/lono/blueprint.rb +1 -18
- data/lib/lono/builder/allow/base.rb +54 -0
- data/lib/lono/builder/allow/env.rb +17 -0
- data/lib/lono/builder/allow/region.rb +20 -0
- data/lib/lono/builder/allow.rb +8 -0
- data/lib/lono/builder/configset/combiner.rb +145 -0
- data/lib/lono/builder/configset/definition/base.rb +47 -0
- data/lib/lono/builder/configset/definition/context.rb +29 -0
- data/lib/lono/{configset/strategy/helpers/dsl → builder/configset/definition/dsl/syntax}/auth.rb +1 -1
- data/lib/lono/{configset/strategy/helpers/dsl/core.rb → builder/configset/definition/dsl/syntax/content.rb} +12 -4
- data/lib/lono/{configset/strategy/helpers/dsl/syntax.rb → builder/configset/definition/dsl/syntax/core.rb} +15 -9
- data/lib/lono/{configset/strategy/helpers/dsl → builder/configset/definition/dsl/syntax}/package.rb +1 -1
- data/lib/lono/builder/configset/definition/dsl/syntax.rb +5 -0
- data/lib/lono/{configset/strategy → builder/configset/definition}/dsl.rb +10 -14
- data/lib/lono/{configset/strategy → builder/configset/definition}/erb.rb +13 -16
- data/lib/lono/builder/configset/definition.rb +18 -0
- data/lib/lono/builder/configset/evaluator.rb +10 -0
- data/lib/lono/builder/configset/registration.rb +35 -0
- data/lib/lono/builder/context.rb +40 -0
- data/lib/lono/builder/dsl/evaluator.rb +6 -55
- data/lib/lono/builder/dsl/finalizer/base.rb +8 -0
- data/lib/lono/builder/dsl/finalizer/configsets.rb +7 -28
- data/lib/lono/builder/dsl/finalizer/files/base.rb +4 -0
- data/lib/lono/builder/dsl/finalizer/files/build.rb +58 -0
- data/lib/lono/builder/dsl/finalizer/files/replace.rb +31 -0
- data/lib/lono/builder/dsl/finalizer/files.rb +9 -0
- data/lib/lono/builder/dsl/finalizer/parameter_groups.rb +4 -3
- data/lib/lono/builder/dsl/finalizer.rb +4 -2
- data/lib/lono/builder/dsl/helpers/files.rb +7 -0
- data/lib/lono/builder/dsl/helpers/partials.rb +48 -53
- data/lib/lono/builder/dsl/helpers/s3.rb +1 -1
- data/lib/lono/builder/dsl/helpers/ssm/fetcher.rb +3 -1
- data/lib/lono/builder/dsl/helpers/template_file.rb +18 -6
- data/lib/lono/builder/dsl/helpers.rb +1 -11
- data/lib/lono/builder/dsl/syntax/core/resource/property_mover.rb +11 -1
- data/lib/lono/builder/dsl/syntax/core/squeezer.rb +16 -2
- data/lib/lono/builder/dsl.rb +1 -1
- data/lib/lono/builder/param.rb +4 -1
- data/lib/lono/builder/template/upload.rb +2 -15
- data/lib/lono/cfn/cancel.rb +5 -5
- data/lib/lono/cfn/deploy/iam.rb +1 -1
- data/lib/lono/cfn/deploy.rb +32 -3
- data/lib/lono/cfn/download.rb +0 -1
- data/lib/lono/cfn/plan/changeset.rb +2 -2
- data/lib/lono/cfn/plan/diff/data.rb +11 -1
- data/lib/lono/cfn/plan/param.rb +1 -1
- data/lib/lono/cfn/plan/template.rb +2 -2
- data/lib/lono/cfn/plan.rb +1 -0
- data/lib/lono/cli/abstract.rb +0 -6
- data/lib/lono/cli/base.rb +5 -3
- data/lib/lono/cli/build.rb +16 -60
- data/lib/lono/cli/clean.rb +3 -2
- data/lib/lono/cli/code.rb +12 -12
- data/lib/lono/cli/help/new/helper/blueprint.md +17 -0
- data/lib/lono/cli/help/new/helper/project.md +16 -0
- data/lib/lono/cli/list.rb +3 -6
- data/lib/lono/cli/new/blueprint.rb +3 -7
- data/lib/lono/cli/new/configset.rb +11 -44
- data/lib/lono/cli/new/helper/blueprint.rb +26 -0
- data/lib/lono/cli/new/helper/project.rb +24 -0
- data/lib/lono/cli/new/helper.rb +8 -27
- data/lib/lono/cli/new/sequence.rb +6 -1
- data/lib/lono/cli/new.rb +8 -12
- data/lib/lono/cli/status.rb +18 -0
- data/lib/lono/cli.rb +6 -9
- data/lib/lono/command.rb +0 -1
- data/lib/lono/component.rb +29 -0
- data/lib/lono/concerns/aws_info.rb +14 -0
- data/lib/lono/concerns/names.rb +9 -0
- data/lib/lono/configset.rb +17 -0
- data/lib/lono/core.rb +1 -1
- data/lib/lono/ext/bundler.rb +7 -0
- data/lib/lono/ext/core/module.rb +31 -0
- data/lib/lono/ext/core/object.rb +32 -0
- data/lib/lono/ext/core/string.rb +9 -0
- data/lib/lono/ext.rb +4 -0
- data/lib/lono/files/base.rb +12 -0
- data/lib/lono/files/builder.rb +37 -0
- data/lib/lono/files/compressor.rb +53 -0
- data/lib/lono/files/concerns/post_processing.rb +35 -0
- data/lib/lono/files/concerns/registration.rb +13 -0
- data/lib/lono/files/registry.rb +6 -0
- data/lib/lono/files.rb +37 -0
- data/lib/lono/importer/base.rb +1 -1
- data/lib/lono/inspector/summary.rb +0 -3
- data/lib/lono/layering/layer.rb +3 -17
- data/lib/lono/logger.rb +1 -3
- data/lib/lono/names.rb +1 -1
- data/lib/lono/s3/uploader.rb +29 -28
- data/lib/lono/seeder.rb +18 -27
- data/lib/lono/user_data.rb +3 -1
- data/lib/lono/version.rb +1 -1
- data/lib/lono/yamler/validator.rb +7 -22
- data/lib/lono.rb +8 -0
- data/lib/templates/configset/configset.rb +2 -16
- data/lib/templates/examples/configset/configset.rb +16 -0
- data/lib/templates/helper/%underscore_name%_helper.rb.tt +1 -1
- data/lono.gemspec +1 -1
- metadata +52 -39
- data/lib/lono/app_file/base.rb +0 -28
- data/lib/lono/app_file/build/lambda_layer/ruby_packager.rb +0 -153
- data/lib/lono/app_file/build/lambda_layer.rb +0 -20
- data/lib/lono/app_file/build.rb +0 -79
- data/lib/lono/app_file/registry/item.rb +0 -24
- data/lib/lono/app_file/registry.rb +0 -16
- data/lib/lono/app_file/upload.rb +0 -12
- data/lib/lono/builder/context/generic.rb +0 -11
- data/lib/lono/builder/context/loaders/load_files.rb +0 -23
- data/lib/lono/builder/context/loaders.rb +0 -35
- data/lib/lono/builder/context/params.rb +0 -6
- data/lib/lono/builder/context/template.rb +0 -4
- data/lib/lono/configset/builder.rb +0 -59
- data/lib/lono/configset/combiner.rb +0 -164
- data/lib/lono/configset/evaluate_file.rb +0 -8
- data/lib/lono/configset/meta/dsl.rb +0 -12
- data/lib/lono/configset/meta.rb +0 -19
- data/lib/lono/configset/s3_file/build.rb +0 -34
- data/lib/lono/configset/s3_file/item.rb +0 -38
- data/lib/lono/configset/s3_file/registry.rb +0 -12
- data/lib/lono/configset/s3_file/upload.rb +0 -12
- data/lib/lono/configset/strategy/base.rb +0 -83
- data/lib/lono/configset/strategy/helpers/dsl.rb +0 -8
- data/lib/lono/configset/strategy/helpers/erb.rb +0 -9
- data/lib/lono/lookup.rb +0 -12
- data/lib/lono/seeder/service_role.rb +0 -11
- data/lib/lono/utils/contexts.rb +0 -15
- data/lib/lono/utils/item/file_methods.rb +0 -29
- data/lib/lono/utils/item/zip.rb +0 -42
@@ -1,29 +1,25 @@
|
|
1
|
-
|
1
|
+
class Lono::Builder::Configset::Definition
|
2
2
|
class Dsl < Base
|
3
|
-
|
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
|
17
|
-
|
18
|
-
|
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
|
-
|
26
|
-
|
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
|
-
|
2
|
-
|
3
|
-
module Lono::Configset::Strategy
|
1
|
+
class Lono::Builder::Configset::Definition
|
4
2
|
class Erb < Base
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
13
|
-
content = RenderMePretty.result(@
|
14
|
-
|
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,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
|
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
|
15
|
-
|
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
|
-
|
39
|
+
evaluate_file(path) # process top-level template.rb first
|
47
40
|
Dir.glob(expr).each do |path|
|
48
|
-
|
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
|
@@ -1,41 +1,20 @@
|
|
1
1
|
class Lono::Builder::Dsl::Finalizer
|
2
|
-
class Configsets
|
3
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
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"]
|
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,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
|
@@ -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(
|
7
|
-
|
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
|
-
|
9
|
-
@cfn =
|
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
|
@@ -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
|
-
#
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
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
|
78
|
-
|
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("#{
|
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
|
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
|