lono 8.0.0.pre.rc2 → 8.0.0.pre.rc5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +84 -0
- data/.github/ISSUE_TEMPLATE/documentation.md +12 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +64 -0
- data/.github/ISSUE_TEMPLATE/question.md +14 -0
- data/.github/ISSUE_TEMPLATE.md +7 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +50 -0
- data/CHANGELOG.md +56 -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 +56 -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 +70 -0
- data/lib/lono/{configset/strategy/helpers/dsl → builder/configset/definition/dsl/syntax}/auth.rb +1 -1
- data/lib/lono/builder/configset/definition/dsl/syntax/content.rb +22 -0
- 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 +50 -0
- data/lib/lono/builder/dsl/finalizer/files/replace.rb +36 -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/ec2.rb +16 -3
- 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 +5 -7
- data/lib/lono/builder/dsl/helpers/ssm/fetcher.rb +3 -1
- data/lib/lono/builder/dsl/helpers/stack.rb +2 -4
- data/lib/lono/builder/dsl/helpers/template_file.rb +23 -29
- 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 +19 -3
- data/lib/lono/builder/dsl/syntax/fn.rb +0 -2
- data/lib/lono/builder/dsl.rb +2 -2
- data/lib/lono/builder/param.rb +7 -2
- data/lib/lono/builder/template/upload.rb +2 -15
- data/lib/lono/builder/template.rb +1 -3
- data/lib/lono/builder.rb +39 -0
- data/lib/lono/bundler/util/git.rb +18 -16
- data/lib/lono/cfn/base.rb +2 -2
- data/lib/lono/cfn/cancel.rb +5 -5
- data/lib/lono/cfn/concerns/build.rb +1 -1
- data/lib/lono/cfn/delete.rb +5 -2
- data/lib/lono/cfn/deploy/iam.rb +1 -1
- data/lib/lono/cfn/deploy/operable.rb +1 -1
- data/lib/lono/cfn/deploy/rollback.rb +1 -3
- data/lib/lono/cfn/deploy.rb +23 -5
- data/lib/lono/cfn/download.rb +0 -1
- data/lib/lono/cfn/plan/changeset.rb +3 -3
- 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 +26 -0
- data/lib/lono/cli/abstract.rb +0 -6
- data/lib/lono/cli/base.rb +6 -3
- data/lib/lono/cli/clean.rb +3 -2
- data/lib/lono/cli/help/new/helper.md +27 -0
- data/lib/lono/cli/help/new/hook.md +14 -0
- data/lib/lono/cli/help/new/project.md +3 -10
- data/lib/lono/cli/iam.rb +27 -0
- data/lib/lono/cli/list.rb +3 -6
- data/lib/lono/cli/new/blueprint.rb +3 -9
- data/lib/lono/cli/new/configset.rb +11 -44
- data/lib/lono/cli/new/helper.rb +19 -11
- data/lib/lono/cli/new/hook.rb +32 -0
- data/lib/lono/cli/new/sequence.rb +6 -1
- data/lib/lono/cli/new.rb +9 -9
- data/lib/lono/cli/script/build.rb +0 -5
- data/lib/lono/cli/status.rb +18 -0
- data/lib/lono/{inspector → cli}/summary.rb +23 -33
- data/lib/lono/cli.rb +15 -16
- data/lib/lono/command.rb +28 -2
- 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 +11 -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/{utils → files/builder/lambda_layer}/rsync.rb +3 -5
- data/lib/lono/{app_file/build → files/builder}/lambda_layer/ruby_packager.rb +104 -79
- data/lib/lono/files/builder/lambda_layer/ruby_version.rb +38 -0
- data/lib/lono/files/builder/lambda_layer.rb +17 -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 +52 -0
- data/lib/lono/files/concerns/registration.rb +16 -0
- data/lib/lono/files/registry.rb +6 -0
- data/lib/lono/files.rb +41 -0
- data/lib/lono/hooks/builder.rb +50 -0
- data/lib/lono/hooks/concern.rb +9 -0
- data/lib/lono/hooks/dsl.rb +20 -0
- data/lib/lono/hooks/runner.rb +46 -0
- data/lib/lono/layering/layer.rb +64 -56
- data/lib/lono/logger.rb +1 -3
- data/lib/lono/names.rb +7 -10
- data/lib/lono/s3/bucket.rb +17 -11
- data/lib/lono/s3/uploader.rb +33 -28
- data/lib/lono/script/build.rb +0 -5
- data/lib/lono/seeder.rb +19 -28
- data/lib/lono/user_data.rb +3 -1
- data/lib/lono/utils/call_line.rb +9 -0
- data/lib/lono/utils/sh.rb +32 -0
- data/lib/lono/utils.rb +5 -0
- 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/lib/templates/hook/config/hooks.rb.tt +14 -0
- data/lib/templates/project/Gemfile.tt +2 -7
- data/lono.gemspec +1 -1
- metadata +73 -62
- data/lib/lono/app_file/base.rb +0 -28
- 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/builder/template/post_processor.rb +0 -67
- data/lib/lono/cli/build.rb +0 -91
- data/lib/lono/cli/code.rb +0 -22
- data/lib/lono/cli/help/blueprint/new.md +0 -56
- data/lib/lono/cli/new/extension.rb +0 -57
- 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/core.rb +0 -18
- data/lib/lono/configset/strategy/helpers/dsl.rb +0 -8
- data/lib/lono/configset/strategy/helpers/erb.rb +0 -9
- data/lib/lono/importer/base.rb +0 -48
- data/lib/lono/importer/converter.rb +0 -19
- data/lib/lono/importer/download.rb +0 -46
- data/lib/lono/importer/dsl.rb +0 -36
- data/lib/lono/importer/params.rb +0 -56
- data/lib/lono/importer/service/coder.rb +0 -85
- data/lib/lono/inspector/base.rb +0 -32
- 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
- data/lib/templates/extension/lib/%extension_name%/autoloader.rb.tt +0 -23
- data/lib/templates/extension/lib/%extension_name%/helpers/mappings.rb.tt +0 -24
- data/lib/templates/extension/lib/%extension_name%/helpers/outputs.rb.tt +0 -7
- data/lib/templates/extension/lib/%extension_name%/helpers/parameters.rb.tt +0 -10
- data/lib/templates/extension/lib/%extension_name%/helpers/resources/resource.rb.tt +0 -4
- data/lib/templates/extension/lib/%extension_name%/helpers/variables.rb.tt +0 -6
- data/lib/templates/extension/lib/%extension_name%/version.rb.tt +0 -3
- data/lib/templates/extension/lib/%extension_name%.rb.tt +0 -8
@@ -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,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
|
@@ -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
|
@@ -2,12 +2,25 @@ module Lono::Builder::Dsl::Helpers
|
|
2
2
|
module Ec2
|
3
3
|
extend Memoist
|
4
4
|
|
5
|
+
# Returns vpc object
|
6
|
+
def vpc(name)
|
7
|
+
filters = name == "default" ?
|
8
|
+
[name: "isDefault", values: ["true"]] :
|
9
|
+
[name: "tag:Name", values: [name]]
|
10
|
+
resp = ec2.describe_vpcs(filters: filters)
|
11
|
+
resp.vpcs.first
|
12
|
+
end
|
13
|
+
memoize :vpc
|
14
|
+
|
5
15
|
def default_vpc
|
6
|
-
|
7
|
-
vpc = resp.vpcs.first
|
16
|
+
vpc = vpc("default")
|
8
17
|
vpc ? vpc.vpc_id : "no default vpc found"
|
9
18
|
end
|
10
|
-
|
19
|
+
|
20
|
+
def default_vpc_cidr
|
21
|
+
vpc = vpc("default")
|
22
|
+
vpc.cidr_block
|
23
|
+
end
|
11
24
|
|
12
25
|
def default_subnets
|
13
26
|
return "no default subnets because no default vpc found" if default_vpc == "no default vpc found"
|
@@ -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
|
@@ -3,14 +3,12 @@ module Lono::Builder::Dsl::Helpers
|
|
3
3
|
def s3_bucket
|
4
4
|
Lono::S3::Bucket.name
|
5
5
|
end
|
6
|
-
alias_method :
|
6
|
+
alias_method :lono_bucket, :s3_bucket
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
"file://app/files/#{options[:type]}/#{name}" # placeholder for post processing
|
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"
|
13
12
|
end
|
14
|
-
alias_method :file_s3_key, :s3_key
|
15
13
|
end
|
16
14
|
end
|
@@ -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
|
@@ -15,7 +15,7 @@ module Lono::Builder::Dsl::Helpers
|
|
15
15
|
if o
|
16
16
|
o.output_value
|
17
17
|
else
|
18
|
-
logger.info "
|
18
|
+
logger.info "WARN: STACK OUTPUT NOT FOUND: output #{key} for stack #{stack_name}"
|
19
19
|
nil
|
20
20
|
end
|
21
21
|
end
|
@@ -35,10 +35,8 @@ module Lono::Builder::Dsl::Helpers
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def stack_name(blueprint)
|
38
|
-
return blueprint unless Lono.config.names.output.expand
|
39
38
|
names = Lono::Names.new(blueprint: blueprint)
|
40
|
-
#
|
41
|
-
pattern = blueprint.include?(':') ? blueprint : Lono.config.names.output.stack
|
39
|
+
pattern = blueprint # blueprint can be a pattern provided by user. IE: :BLUEPRINT-:ENV
|
42
40
|
names.expansion(pattern)
|
43
41
|
end
|
44
42
|
|
@@ -1,54 +1,48 @@
|
|
1
1
|
module Lono::Builder::Dsl::Helpers
|
2
2
|
module TemplateFile
|
3
3
|
extend Memoist
|
4
|
+
include Lono::Utils::CallLine
|
4
5
|
include Lono::Utils::Pretty
|
5
6
|
|
7
|
+
# Do not memoize :template_file - it'll hide the template_file_missing error
|
6
8
|
def template_file(path)
|
7
|
-
path = "#{@blueprint.root}/#{path}"
|
9
|
+
path = "#{@blueprint.root}/#{path}" unless path.starts_with?('/')
|
8
10
|
if File.exist?(path)
|
9
|
-
|
11
|
+
RenderMePretty.result(path, context: self)
|
10
12
|
else
|
11
13
|
template_file_missing(path)
|
12
14
|
end
|
13
15
|
end
|
14
|
-
|
16
|
+
alias_method :render_file, :template_file
|
17
|
+
alias_method :render_path, :template_file
|
18
|
+
alias_method :user_data, :template_file
|
19
|
+
alias_method :content, :template_file
|
20
|
+
|
15
21
|
|
16
22
|
# Caller lines are different for OSes:
|
17
23
|
#
|
18
|
-
# windows: "C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/
|
19
|
-
# linux: "/home/ec2-user/.rvm/gems/ruby-3.0.3/gems/
|
24
|
+
# windows: "C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/lono-1.1.1/lib/lono/builder.rb:34:in `build'"
|
25
|
+
# 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
26
|
#
|
21
|
-
class TempleFileNotFoundError < StandardError; end
|
22
27
|
def template_file_missing(path)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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)
|
28
|
+
logger.warn "WARN: File path not found: #{pretty_path(path)}".color(:yellow)
|
29
|
+
call_line = lono_call_line
|
30
|
+
DslEvaluator.print_code(call_line) # returns true right now
|
31
|
+
""
|
34
32
|
end
|
35
|
-
memoize :render_file
|
36
33
|
|
37
34
|
def user_data_script
|
38
|
-
|
35
|
+
path = @user_data_script || @user_data_script_path
|
36
|
+
unless path
|
37
|
+
# script_example = pretty_path("#{@blueprint.root}/template/bootstrap.sh")
|
38
|
+
script_example = "bootstrap.sh"
|
39
39
|
return <<~EOL
|
40
|
-
# @
|
41
|
-
# Also, make sure that "
|
40
|
+
# @user_data_script_path variable not set. IE: @user_data_script_path = "#{script_example}"
|
41
|
+
# Also, make sure that "#{script_example}" exists.
|
42
42
|
EOL
|
43
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
|
44
|
+
user_data(path)
|
52
45
|
end
|
46
|
+
alias_method :user_data_script_path, :user_data_script
|
53
47
|
end
|
54
48
|
end
|
@@ -1,15 +1,5 @@
|
|
1
|
-
# Built-in helpers for the DSL form
|
2
1
|
class Lono::Builder::Dsl
|
3
2
|
module Helpers
|
4
|
-
|
5
|
-
|
6
|
-
# Auto include all modules in helpers folder
|
7
|
-
# only load one level deep. IE: ssm/fetcher is a class
|
8
|
-
helpers_dir = File.expand_path("helpers", __dir__)
|
9
|
-
Dir.glob("#{helpers_dir}/*.rb").each do |path|
|
10
|
-
next unless File.file?(path)
|
11
|
-
klass = path.gsub(%r{.*/lib/},'').sub(".rb",'').camelize
|
12
|
-
include klass.constantize
|
13
|
-
end
|
3
|
+
include_modules("helpers")
|
14
4
|
end
|
15
5
|
end
|
@@ -5,8 +5,18 @@ class Lono::Builder::Dsl::Syntax::Core::Resource
|
|
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[
|
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)
|
@@ -4,21 +4,37 @@ module Lono::Builder::Dsl::Syntax::Core
|
|
4
4
|
@data = data
|
5
5
|
end
|
6
6
|
|
7
|
-
def squeeze(new_data=nil)
|
7
|
+
def squeeze(new_data=nil, previous_key=nil)
|
8
8
|
data = new_data.nil? ? @data : new_data
|
9
9
|
|
10
10
|
case data
|
11
11
|
when Array
|
12
|
-
|
12
|
+
# .compact prevents infinite loop when data = [nil] on accident
|
13
|
+
# IE: data[:key] = [nil]
|
14
|
+
data.compact.map! { |v| squeeze(v) }
|
13
15
|
when Hash
|
14
16
|
data.each_with_object({}) do |(k,v), squeezed|
|
15
17
|
# only remove nil and empty Array values within Hash structures
|
16
|
-
squeezed[k] = squeeze(v) unless v.nil? ||
|
18
|
+
squeezed[k] = squeeze(v, k) unless v.nil? # || empty_array?(v, previous_key)
|
17
19
|
squeezed
|
18
20
|
end
|
19
21
|
else
|
20
22
|
data # do not transform
|
21
23
|
end
|
22
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
|
23
39
|
end
|
24
40
|
end
|
@@ -102,8 +102,6 @@ module Lono::Builder::Dsl::Syntax
|
|
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
|
data/lib/lono/builder/dsl.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
class Lono::Builder
|
2
2
|
class Dsl < Lono::CLI::Base
|
3
3
|
attr_reader :results
|
4
4
|
def run
|
@@ -8,7 +8,7 @@ module Lono::Builder
|
|
8
8
|
|
9
9
|
def build_template
|
10
10
|
evaluator = Evaluator.new(@options)
|
11
|
-
evaluator.
|
11
|
+
evaluator.evaluate
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/lono/builder/param.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
-
|
1
|
+
class Lono::Builder
|
2
2
|
class Param < Lono::CLI::Base
|
3
3
|
attr_reader :env_path, :base_path # set when build is called
|
4
|
+
include Lono::Builder::Dsl::Syntax
|
5
|
+
include Lono::Builder::Context
|
6
|
+
# Overriding output resource DSL method
|
7
|
+
alias_method :output, :stack_output
|
4
8
|
|
5
9
|
def build
|
10
|
+
load_context
|
6
11
|
logger.info "Building parameters"
|
7
12
|
|
8
13
|
contents = []
|
@@ -36,7 +41,7 @@ module Lono::Builder
|
|
36
41
|
def render_erb(path)
|
37
42
|
return unless path
|
38
43
|
if File.exist?(path)
|
39
|
-
RenderMePretty.result(path, context:
|
44
|
+
RenderMePretty.result(path, context: self)
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
@@ -1,21 +1,8 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require 'json'
|
3
|
-
require 'base64'
|
4
|
-
require 'digest'
|
5
|
-
|
6
1
|
class Lono::Builder::Template
|
7
2
|
class Upload < Lono::CLI::Base
|
8
|
-
def initialize(options={})
|
9
|
-
super
|
10
|
-
@checksums = {}
|
11
|
-
@prefix = Lono.env # s3://s3-bucket/development
|
12
|
-
end
|
13
|
-
|
14
3
|
def run
|
15
|
-
|
16
|
-
|
17
|
-
Lono::S3::Uploader.new(path).upload
|
18
|
-
end
|
4
|
+
path = "#{Lono.root}/output/#{@blueprint.name}/template.yml"
|
5
|
+
Lono::S3::Uploader.new(path).upload
|
19
6
|
end
|
20
7
|
end
|
21
8
|
end
|