lono 6.1.11 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.cody/acceptance.sh +19 -3
- data/.gitignore +2 -2
- data/CHANGELOG.md +16 -1
- data/README.md +18 -20
- data/Rakefile +1 -0
- data/lib/lono.rb +7 -5
- data/lib/lono/abstract_base.rb +25 -0
- data/lib/lono/api/client.rb +30 -0
- data/lib/lono/api/proxy.rb +58 -0
- data/lib/lono/api/repos.rb +8 -0
- data/lib/lono/api/verify.rb +13 -0
- data/lib/lono/app_file/base.rb +4 -11
- data/lib/lono/app_file/build.rb +1 -1
- data/lib/lono/app_file/upload.rb +1 -4
- data/lib/lono/autoloader.rb +3 -1
- data/lib/lono/aws_services.rb +9 -9
- data/lib/lono/aws_services/helper.rb +14 -0
- data/lib/lono/aws_services/{util.rb → stack.rb} +1 -9
- data/lib/lono/aws_services/stack_set.rb +41 -0
- data/lib/lono/blueprint.rb +2 -2
- data/lib/lono/blueprint/configset/loader.rb +7 -0
- data/lib/lono/blueprint/helper.rb +8 -2
- data/lib/lono/blueprint/meta.rb +4 -12
- data/lib/lono/blueprint/new.rb +3 -3
- data/lib/lono/blueprint/root.rb +6 -26
- data/lib/lono/bundle.rb +54 -0
- data/lib/lono/cfn.rb +31 -75
- data/lib/lono/cfn/base.rb +39 -136
- data/lib/lono/cfn/cancel.rb +14 -9
- data/lib/lono/cfn/create.rb +15 -19
- data/lib/lono/cfn/delete.rb +9 -9
- data/lib/lono/cfn/deploy.rb +4 -4
- data/lib/lono/cfn/download.rb +27 -9
- data/lib/lono/cfn/opts.rb +80 -0
- data/lib/lono/cfn/preview/changeset.rb +23 -23
- data/lib/lono/cfn/preview/codediff.rb +5 -6
- data/lib/lono/cfn/preview/param.rb +10 -10
- data/lib/lono/cfn/rollback.rb +5 -5
- data/lib/lono/cfn/status.rb +0 -10
- data/lib/lono/cfn/update.rb +22 -27
- data/lib/lono/clean.rb +3 -3
- data/lib/lono/cli.rb +69 -34
- data/lib/lono/code.rb +22 -0
- data/lib/lono/command.rb +7 -0
- data/lib/lono/config_location.rb +6 -13
- data/lib/lono/configset.rb +9 -0
- data/lib/lono/configset/combiner.rb +128 -0
- data/lib/lono/configset/evaluate_file.rb +8 -0
- data/lib/lono/configset/list.rb +67 -0
- data/lib/lono/configset/loader.rb +98 -0
- data/lib/lono/configset/loader/dsl.rb +9 -0
- data/lib/lono/configset/materializer/final.rb +10 -0
- data/lib/lono/configset/materializer/gems_builder.rb +81 -0
- data/lib/lono/configset/materializer/jade.rb +15 -0
- data/lib/lono/configset/materializer/source.rb +54 -0
- data/lib/lono/configset/meta.rb +19 -0
- data/lib/lono/configset/meta/dsl.rb +12 -0
- data/lib/lono/configset/new.rb +84 -0
- data/lib/lono/configset/preparer.rb +44 -0
- data/lib/lono/configset/register/base.rb +121 -0
- data/lib/lono/configset/register/blueprint.rb +16 -0
- data/lib/lono/configset/register/dsl.rb +15 -0
- data/lib/lono/configset/register/project.rb +12 -0
- data/lib/lono/configset/registry.rb +34 -0
- data/lib/lono/configset/resolver.rb +42 -0
- data/lib/lono/conventions.rb +18 -7
- data/lib/lono/core.rb +16 -20
- data/lib/lono/default/settings.yml +2 -3
- data/lib/lono/ext/bundler.rb +7 -0
- data/lib/lono/file_uploader.rb +8 -5
- data/lib/lono/finder/base.rb +140 -0
- data/lib/lono/finder/blueprint.rb +11 -0
- data/lib/lono/finder/blueprint/configset.rb +17 -0
- data/lib/lono/finder/configset.rb +11 -0
- data/lib/lono/generate.rb +93 -0
- data/lib/lono/help/blueprint/new.md +0 -1
- data/lib/lono/help/cfn/delete.md +1 -1
- data/lib/lono/help/cfn/deploy.md +5 -76
- data/lib/lono/help/cfn/status.md +0 -4
- data/lib/lono/help/cfn/update.md +1 -1
- data/lib/lono/help/code/convert.md +51 -0
- data/lib/lono/help/code/import.md +30 -0
- data/lib/lono/help/configsets.md +24 -0
- data/lib/lono/help/generate.md +4 -4
- data/lib/lono/help/new.md +1 -2
- data/lib/lono/help/sets/delete.md +8 -0
- data/lib/lono/help/sets/deploy.md +76 -0
- data/lib/lono/help/sets/instances/delete.md +21 -0
- data/lib/lono/help/sets/instances/list.md +14 -0
- data/lib/lono/help/sets/instances/status.md +15 -0
- data/lib/lono/help/sets/instances/sync.md +88 -0
- data/lib/lono/help/sets/status.md +23 -0
- data/lib/lono/help/upgrade.md +1 -0
- data/lib/lono/importer.rb +22 -0
- data/lib/lono/importer/base.rb +59 -0
- data/lib/lono/importer/converter.rb +19 -0
- data/lib/lono/importer/download.rb +46 -0
- data/lib/lono/importer/dsl.rb +36 -0
- data/lib/lono/importer/erb.rb +31 -0
- data/lib/lono/importer/params.rb +56 -0
- data/lib/lono/importer/service/coder.rb +81 -0
- data/lib/lono/inspector/base.rb +12 -22
- data/lib/lono/inspector/graph.rb +1 -1
- data/lib/lono/inspector/summary.rb +41 -17
- data/lib/lono/jade.rb +103 -0
- data/lib/lono/jade/circular.rb +26 -0
- data/lib/lono/jadespec.rb +41 -0
- data/lib/lono/new.rb +2 -2
- data/lib/lono/opts.rb +43 -0
- data/lib/lono/output/template.rb +48 -0
- data/lib/lono/param.rb +3 -5
- data/lib/lono/param/generator.rb +13 -33
- data/lib/lono/pro.rb +15 -0
- data/lib/lono/pro/base.rb +16 -0
- data/lib/lono/pro/repo.rb +27 -0
- data/lib/lono/project_checker.rb +4 -29
- data/lib/lono/registration.rb +15 -0
- data/lib/lono/registration/base.rb +37 -0
- data/lib/lono/registration/check.rb +15 -0
- data/lib/lono/registration/temp.rb +60 -0
- data/lib/lono/registration/user.rb +54 -0
- data/lib/lono/script/base.rb +1 -10
- data/lib/lono/script/upload.rb +2 -12
- data/lib/lono/seed.rb +2 -11
- data/lib/lono/seed/base.rb +55 -110
- data/lib/lono/sets.rb +38 -0
- data/lib/lono/sets/base.rb +45 -0
- data/lib/lono/sets/create.rb +30 -0
- data/lib/lono/sets/delete.rb +47 -0
- data/lib/lono/sets/deploy.rb +11 -0
- data/lib/lono/sets/instances.rb +33 -0
- data/lib/lono/sets/instances/base.rb +30 -0
- data/lib/lono/sets/instances/delete.rb +69 -0
- data/lib/lono/sets/instances/list.rb +13 -0
- data/lib/lono/sets/instances/opts.rb +29 -0
- data/lib/lono/sets/instances/status.rb +12 -0
- data/lib/lono/sets/instances/sync.rb +182 -0
- data/lib/lono/sets/list.rb +35 -0
- data/lib/lono/sets/opts.rb +18 -0
- data/lib/lono/sets/preview/codediff.rb +35 -0
- data/lib/lono/sets/preview/param.rb +32 -0
- data/lib/lono/sets/status.rb +116 -0
- data/lib/lono/sets/status/instance.rb +20 -0
- data/lib/lono/sets/status/instance/base.rb +120 -0
- data/lib/lono/sets/status/instance/completed.rb +35 -0
- data/lib/lono/sets/status/instance/deleted.rb +32 -0
- data/lib/lono/sets/status/instance/show.rb +7 -0
- data/lib/lono/sets/status/instances.rb +111 -0
- data/lib/lono/sets/summarize.rb +20 -0
- data/lib/lono/sets/time_spent.rb +11 -0
- data/lib/lono/sets/update.rb +81 -0
- data/lib/lono/template.rb +5 -7
- data/lib/lono/template/configset_injector.rb +50 -0
- data/lib/lono/template/context.rb +4 -4
- data/lib/lono/template/context/loader.rb +4 -16
- data/lib/lono/template/evaluate.rb +2 -1
- data/lib/lono/template/generator.rb +17 -15
- data/lib/lono/template/helper.rb +7 -7
- data/lib/lono/template/post_processor.rb +2 -12
- data/lib/lono/template/strategy/base.rb +4 -0
- data/lib/lono/template/{dsl.rb → strategy/dsl.rb} +4 -6
- data/lib/lono/template/{dsl → strategy/dsl}/builder.rb +11 -15
- data/lib/lono/template/{dsl → strategy/dsl}/builder/fn.rb +1 -1
- data/lib/lono/template/strategy/dsl/builder/helpers.rb +11 -0
- data/lib/lono/template/strategy/dsl/builder/helpers/core_helper.rb +14 -0
- data/lib/lono/template/strategy/dsl/builder/helpers/file_helper.rb +48 -0
- data/lib/lono/template/strategy/dsl/builder/helpers/lookup_helper.rb +27 -0
- data/lib/lono/template/strategy/dsl/builder/helpers/s3_helper.rb +13 -0
- data/lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb +39 -0
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/base.rb +6 -17
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/condition.rb +1 -1
- data/lib/lono/template/strategy/dsl/builder/section/extensions.rb +9 -0
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/mapping.rb +1 -1
- data/lib/lono/template/{dsl/builder/section_methods.rb → strategy/dsl/builder/section/methods.rb} +9 -2
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/output.rb +1 -1
- data/lib/lono/template/strategy/dsl/builder/section/parameter.rb +69 -0
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource.rb +1 -1
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource/property_mover.rb +1 -1
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/section.rb +1 -1
- data/lib/lono/template/{dsl → strategy/dsl}/builder/squeezer.rb +1 -1
- data/lib/lono/template/strategy/dsl/builder/stringify.rb +15 -0
- data/lib/lono/template/{dsl → strategy/dsl}/builder/syntax.rb +3 -2
- data/lib/lono/template/strategy/dsl/finalizer.rb +12 -0
- data/lib/lono/template/strategy/dsl/finalizer/parameter_groups.rb +56 -0
- data/lib/lono/template/{erb.rb → strategy/erb.rb} +5 -5
- data/lib/lono/template/strategy/source.rb +8 -0
- data/lib/lono/template/template.rb +1 -1
- data/lib/lono/template/upload.rb +4 -9
- data/lib/lono/template/util.rb +0 -40
- data/lib/lono/upgrade.rb +12 -10
- data/lib/lono/user_data.rb +4 -4
- data/lib/lono/utils/pretty_time.rb +14 -0
- data/lib/lono/utils/sure.rb +23 -0
- data/lib/lono/version.rb +1 -1
- data/lib/lono/yamler/loader.rb +52 -0
- data/lib/lono/yamler/validator.rb +51 -0
- data/lib/templates/blueprint/%blueprint_name%.gemspec.tt +4 -0
- data/lib/templates/blueprint/README.md.tt +1 -1
- data/lib/templates/blueprint/seed/configs.rb +2 -2
- data/lib/templates/blueprint_types/dsl/app/templates/%blueprint_name%.rb +17 -18
- data/lib/templates/blueprint_types/erb/app/templates/%blueprint_name%.yml +63 -4
- data/lib/templates/configset/%configset_name%.gemspec.tt +41 -0
- data/lib/templates/configset/.gitignore +11 -0
- data/lib/templates/configset/CHANGELOG.md +7 -0
- data/lib/templates/configset/Gemfile +4 -0
- data/lib/templates/configset/README.md.tt +3 -0
- data/lib/templates/configset/Rakefile.tt +9 -0
- data/lib/templates/configset/lib/configset.yml +20 -0
- data/lib/templates/skeleton/.gitignore +1 -0
- data/lib/templates/skeleton/Gemfile +0 -1
- data/lib/templates/skeleton/README.md +4 -4
- data/lib/templates/skeleton/configs/settings.yml +1 -1
- data/lono.gemspec +1 -4
- metadata +146 -79
- data/Guardfile +0 -19
- data/lib/lono/app_file.rb +0 -5
- data/lib/lono/blueprint/find.rb +0 -90
- data/lib/lono/blueprint/info.rb +0 -10
- data/lib/lono/blueprint/list.rb +0 -14
- data/lib/lono/cfn/current.rb +0 -95
- data/lib/lono/cfn/preview.rb +0 -4
- data/lib/lono/cfn/suffix.rb +0 -67
- data/lib/lono/cfn/util.rb +0 -27
- data/lib/lono/help/cfn/current.md +0 -18
- data/lib/lono/help/upgrade4.md +0 -25
- data/lib/lono/inspector.rb +0 -4
- data/lib/lono/output_template.rb +0 -35
- data/lib/lono/template/base.rb +0 -13
- data/lib/lono/template/dsl/builder/helpers.rb +0 -8
- data/lib/lono/template/dsl/builder/helpers/core_helper.rb +0 -107
- data/lib/lono/template/dsl/builder/helpers/param_helper.rb +0 -61
- data/lib/lono/template/dsl/builder/parameter.rb +0 -39
- data/lib/lono/upgrade/upgrade4.rb +0 -175
- data/lib/lono/upgrade/upgrade42.rb +0 -36
- data/lib/lono/upgrade/upgrade5.rb +0 -55
- data/lib/templates/blueprint/.meta/config.yml.tt +0 -4
- data/lib/templates/skeleton/Guardfile +0 -12
- data/lib/templates/upgrade5/blueprints/main/.lono/config.yml +0 -3
- data/lib/templates/upgrade5/blueprints/main/.meta/config.yml +0 -3
@@ -0,0 +1,20 @@
|
|
1
|
+
class Lono::Sets
|
2
|
+
module Summarize
|
3
|
+
def summarize(operation_id)
|
4
|
+
puts "Stack Set Operation Summary:"
|
5
|
+
resp = cfn.list_stack_set_operation_results(stack_set_name: @stack, operation_id: operation_id)
|
6
|
+
resp.summaries.each do |s|
|
7
|
+
data = {
|
8
|
+
account: s.account,
|
9
|
+
region: s.region,
|
10
|
+
status: s.status,
|
11
|
+
}
|
12
|
+
data["status reason"] = s.status_reason if s.status_reason
|
13
|
+
message = data.inject("") do |text, (k,v)|
|
14
|
+
text += [k.to_s.color(:purple), v].join(" ") + " "
|
15
|
+
end
|
16
|
+
puts message
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Lono::Sets
|
2
|
+
module TimeSpent
|
3
|
+
include Lono::Utils::PrettyTime
|
4
|
+
|
5
|
+
def show_time_spent(stack_set_operation)
|
6
|
+
seconds = stack_set_operation.end_timestamp - stack_set_operation.creation_timestamp
|
7
|
+
time_took = pretty_time(seconds).color(:green)
|
8
|
+
puts "Time took to complete stack set operation: #{time_took}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
class Lono::Sets
|
2
|
+
class Update < Base
|
3
|
+
include Summarize
|
4
|
+
|
5
|
+
def save
|
6
|
+
message = "Updating #{@stack} stack set"
|
7
|
+
if @options[:noop]
|
8
|
+
puts "NOOP #{message}"
|
9
|
+
return
|
10
|
+
end
|
11
|
+
|
12
|
+
unless stack_set_exists?(@stack)
|
13
|
+
puts "ERROR: Cannot update a stack set because #{@stack} does not exists.".color(:red)
|
14
|
+
return
|
15
|
+
end
|
16
|
+
exit_unless_updatable!
|
17
|
+
|
18
|
+
param_preview.run if @options[:param_preview]
|
19
|
+
codediff_preview.run if @options[:codediff_preview]
|
20
|
+
# changeset preview not supported for stack sets
|
21
|
+
|
22
|
+
options = build_options
|
23
|
+
show_options(options, "cfn.update_stack_set")
|
24
|
+
|
25
|
+
if stack_instances.empty?
|
26
|
+
puts <<~EOL
|
27
|
+
NOTE: There are 0 stack instances associated with the #{@stack} stack set.
|
28
|
+
Will update the stack set template but there no instances to be updated.
|
29
|
+
Add `configs/#{@blueprint}/accounts` and `configs/#{@blueprint}/regions` settings
|
30
|
+
and use `lono sets instances sync` to add stack instances.
|
31
|
+
EOL
|
32
|
+
else
|
33
|
+
sure?("Are you sure you want to update the #{@stack} stack set?", long_desc)
|
34
|
+
end
|
35
|
+
|
36
|
+
resp = cfn.update_stack_set(options)
|
37
|
+
operation_id = resp[:operation_id]
|
38
|
+
puts message unless @options[:mute]
|
39
|
+
|
40
|
+
return true if @options[:noop] || !@options[:wait]
|
41
|
+
|
42
|
+
Lono::Sets::Status::Instance::Base.show_time_progress = true
|
43
|
+
Lono::Sets::Status::Instance::Base.delay_factor = stack_instances.size
|
44
|
+
status = Status.new(@options.merge(operation_id: operation_id))
|
45
|
+
success = status.wait
|
46
|
+
summarize(operation_id)
|
47
|
+
exit 1 unless success
|
48
|
+
success
|
49
|
+
end
|
50
|
+
|
51
|
+
def stack_instances
|
52
|
+
Lono::Sets::Status::Instances.new(@options).stack_instances
|
53
|
+
end
|
54
|
+
memoize :stack_instances
|
55
|
+
|
56
|
+
def long_desc
|
57
|
+
info = stack_instances.inject({}) do |result, instance|
|
58
|
+
result[instance.account] ||= []
|
59
|
+
result[instance.account] << instance.region
|
60
|
+
result
|
61
|
+
end
|
62
|
+
message = "Will deploy to:\n"
|
63
|
+
info.each do |account, regions|
|
64
|
+
message << " account: #{account}\n"
|
65
|
+
message << " regions: #{regions.join(",")}\n"
|
66
|
+
end
|
67
|
+
message << "\nNumber of stack instances to be updated: #{stack_instances.size}"
|
68
|
+
message
|
69
|
+
end
|
70
|
+
|
71
|
+
def codediff_preview
|
72
|
+
Lono::Sets::Preview::Codediff.new(@options.merge(mute_params: true, mute_using: true))
|
73
|
+
end
|
74
|
+
memoize :codediff_preview
|
75
|
+
|
76
|
+
def param_preview
|
77
|
+
Lono::Sets::Preview::Param.new(@options)
|
78
|
+
end
|
79
|
+
memoize :param_preview
|
80
|
+
end
|
81
|
+
end
|
data/lib/lono/template.rb
CHANGED
@@ -3,24 +3,22 @@ module Lono
|
|
3
3
|
class_option :quiet, type: :boolean, desc: "silence the output"
|
4
4
|
class_option :noop, type: :boolean, desc: "noop mode, do nothing destructive"
|
5
5
|
|
6
|
-
desc "generate", "Generate the CloudFormation templates"
|
6
|
+
desc "generate BLUEPRINT", "Generate the CloudFormation templates"
|
7
7
|
long_desc Lono::Help.text("template/generate")
|
8
8
|
option :clean, type: :boolean, desc: "remove all output files before generating"
|
9
|
-
def generate(blueprint
|
10
|
-
|
11
|
-
Generator.new(b, options).run
|
12
|
-
end
|
9
|
+
def generate(blueprint)
|
10
|
+
Generator.new(options.merge(blueprint: blueprint)).run
|
13
11
|
end
|
14
12
|
|
15
13
|
desc "upload", "Uploads templates to configured s3 folder"
|
16
14
|
def upload(blueprint)
|
17
|
-
Upload.new(blueprint
|
15
|
+
Upload.new(options.merge(blueprint: blueprint)).run
|
18
16
|
end
|
19
17
|
|
20
18
|
desc "bashify URL-OR-PATH", "Convert the UserData section of an existing CloudFormation Template to a starter bash script that is compatiable with lono"
|
21
19
|
long_desc Lono::Help.text("template/bashify")
|
22
20
|
def bashify(path)
|
23
|
-
Bashify.new(path: path).run
|
21
|
+
Bashify.new(options.merge(path: path)).run
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class Lono::Template
|
2
|
+
class ConfigsetInjector < Lono::AbstractBase
|
3
|
+
def initialize(options={})
|
4
|
+
super
|
5
|
+
end
|
6
|
+
|
7
|
+
def run
|
8
|
+
@cfn = load_template # initial
|
9
|
+
@cfn = inject # overwrite
|
10
|
+
write(@cfn)
|
11
|
+
@cfn
|
12
|
+
end
|
13
|
+
|
14
|
+
def inject
|
15
|
+
metadata_map.each do |logical_id, metadata_configset|
|
16
|
+
resource = @cfn["Resources"][logical_id]
|
17
|
+
|
18
|
+
unless resource
|
19
|
+
puts "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)
|
20
|
+
next
|
21
|
+
end
|
22
|
+
|
23
|
+
metdata = resource["Metadata"] ||= {}
|
24
|
+
metdata["AWS::CloudFormation::Init"] ||= {}
|
25
|
+
# The metadata_configset has been combined with the original AWS::CloudFormation::Init if it exists
|
26
|
+
metdata["AWS::CloudFormation::Init"] = metadata_configset["AWS::CloudFormation::Init"]
|
27
|
+
end
|
28
|
+
|
29
|
+
@cfn
|
30
|
+
end
|
31
|
+
|
32
|
+
def metadata_map
|
33
|
+
combiner = Lono::Configset::Combiner.new(@cfn, @options)
|
34
|
+
combiner.metadata_map
|
35
|
+
end
|
36
|
+
memoize :metadata_map
|
37
|
+
|
38
|
+
def write(cfn)
|
39
|
+
IO.write(template_path, YAML.dump(cfn))
|
40
|
+
end
|
41
|
+
|
42
|
+
def load_template
|
43
|
+
YAML.load_file(template_path)
|
44
|
+
end
|
45
|
+
|
46
|
+
def template_path
|
47
|
+
"#{Lono.config.output_path}/#{@blueprint}/templates/#{@template}.yml"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# Encapsulates helper methods and instance variables to be rendered in the ERB templates.
|
2
2
|
class Lono::Template
|
3
|
-
class Context
|
3
|
+
class Context < Lono::AbstractBase
|
4
4
|
extend Memoist
|
5
5
|
include Lono::Template::Helper
|
6
6
|
include Loader
|
7
7
|
include Helpers # ERB
|
8
|
-
include Dsl::Builder::Syntax # DSL
|
8
|
+
include Strategy::Dsl::Builder::Syntax # DSL
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
|
10
|
+
def initialize(options={})
|
11
|
+
super
|
12
12
|
load_variables
|
13
13
|
load_project_helpers
|
14
14
|
end
|
@@ -16,22 +16,10 @@ class Lono::Template::Context
|
|
16
16
|
evaluate_variables_file(location.lookup) if location.lookup # config file
|
17
17
|
end
|
18
18
|
|
19
|
-
# Load the variables defined in config/variables/* to make available in
|
20
|
-
# template blocks in config/templates/*.
|
19
|
+
# Load the variables defined in config/variables/* to make available in lono scope.
|
21
20
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# `config/variables/base.rb`:
|
25
|
-
# @foo = 123
|
26
|
-
#
|
27
|
-
# `app/definitions/base.rb`:
|
28
|
-
# template "mytemplate.yml" do
|
29
|
-
# source "mytemplate.yml.erb"
|
30
|
-
# variables(foo: @foo)
|
31
|
-
# end
|
32
|
-
#
|
33
|
-
# NOTE: Only able to make instance variables avaialble with instance_eval,
|
34
|
-
# wasnt able to make local variables available.
|
21
|
+
# NOTE: Was only able to make instance variables avaialble with instance_eval, wasnt able to make local variables
|
22
|
+
# available.
|
35
23
|
def evaluate_variables_file(path)
|
36
24
|
return unless File.exist?(path)
|
37
25
|
instance_eval(IO.read(path), path)
|
@@ -54,4 +42,4 @@ class Lono::Template::Context
|
|
54
42
|
end
|
55
43
|
end
|
56
44
|
end
|
57
|
-
end
|
45
|
+
end
|
@@ -14,7 +14,8 @@ class Lono::Template
|
|
14
14
|
|
15
15
|
# Prints out a user friendly task_definition error message
|
16
16
|
def template_evaluation_error(e)
|
17
|
-
|
17
|
+
lines = e.backtrace.reject { |l| l.include?("/lib/lono/") }
|
18
|
+
error_info = lines.first
|
18
19
|
path, line_no, _ = error_info.split(':')
|
19
20
|
line_no = line_no.to_i
|
20
21
|
puts "Error evaluating #{path}:".color(:red)
|
@@ -1,29 +1,31 @@
|
|
1
1
|
require "yaml"
|
2
2
|
|
3
3
|
class Lono::Template
|
4
|
-
class Generator
|
5
|
-
include Lono::Blueprint::Root
|
6
|
-
|
7
|
-
def initialize(blueprint, options={})
|
8
|
-
@blueprint, @options = blueprint, ActiveSupport::HashWithIndifferentAccess.new(options.dup)
|
9
|
-
@template = @options[:template] || @blueprint
|
10
|
-
Lono::ProjectChecker.check
|
11
|
-
set_blueprint_root(@blueprint)
|
12
|
-
end
|
13
|
-
|
4
|
+
class Generator < Lono::AbstractBase
|
14
5
|
def run
|
15
6
|
# Examples:
|
16
7
|
# Erb.new(b, options.dup).run
|
17
8
|
# Dsl.new(b, options.dup).run
|
18
|
-
generator_class = "Lono::Template::#{template_type.
|
9
|
+
generator_class = "Lono::Template::Strategy::#{template_type.camelize}"
|
19
10
|
generator_class = Object.const_get(generator_class)
|
20
|
-
generator_class.new(@
|
11
|
+
generator_class.new(@options).run
|
12
|
+
# The generator strategy class writes template to disk. The inject_configsets reads it back from disk.
|
13
|
+
# Leaving as-is instead of reading all in memory in case there's a reason.
|
14
|
+
inject_configsets
|
21
15
|
end
|
22
16
|
|
23
17
|
def template_type
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
if @options[:source]
|
19
|
+
"source"
|
20
|
+
else
|
21
|
+
jadespec = Lono::Jadespec.new(Lono.blueprint_root, "unknown") # abusing Jadespec to get template_type
|
22
|
+
jadespec.template_type
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def inject_configsets
|
27
|
+
Lono::Configset::Preparer.new(@options).run # register and materialize gems
|
28
|
+
ConfigsetInjector.new(@options).run
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
data/lib/lono/template/helper.rb
CHANGED
@@ -41,27 +41,27 @@ BASH_CODE
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def scripts_s3_path
|
44
|
-
upload = Lono::Script::Upload.new(@
|
44
|
+
upload = Lono::Script::Upload.new(@options)
|
45
45
|
upload.s3_dest
|
46
46
|
end
|
47
47
|
|
48
48
|
def template_s3_path(template_name)
|
49
49
|
# high jacking Upload for useful s3_https_url method
|
50
50
|
template_path = "output/#{@blueprint}/templates/#{template_name}.yml"
|
51
|
-
upload = Lono::Template::Upload.new(@
|
51
|
+
upload = Lono::Template::Upload.new(@options)
|
52
52
|
upload.s3_https_url(template_path)
|
53
53
|
end
|
54
54
|
|
55
55
|
def template_params(param_name)
|
56
|
-
|
56
|
+
o = {
|
57
57
|
allow_not_exists: true
|
58
58
|
}.merge(@options)
|
59
|
-
|
60
|
-
generator = Lono::Param::Generator.new(
|
59
|
+
o["param"] = param_name
|
60
|
+
generator = Lono::Param::Generator.new(o)
|
61
61
|
# do not generate because lono cfn calling logic already generated it we only need the values
|
62
|
-
|
62
|
+
parameters = generator.parameters # Returns Array in underscore keys format
|
63
63
|
# convert Array to simplified hash structure
|
64
|
-
|
64
|
+
parameters.inject({}) do |h, param|
|
65
65
|
h.merge(param[:parameter_key] => param[:parameter_value])
|
66
66
|
end
|
67
67
|
end
|
@@ -1,15 +1,5 @@
|
|
1
1
|
class Lono::Template
|
2
|
-
class PostProcessor
|
3
|
-
include Lono::Blueprint::Root
|
4
|
-
extend Memoist
|
5
|
-
|
6
|
-
def initialize(blueprint, options={})
|
7
|
-
@blueprint, @options = blueprint, options
|
8
|
-
@template = @options[:template] || @blueprint
|
9
|
-
Lono::ProjectChecker.check
|
10
|
-
set_blueprint_root(@blueprint)
|
11
|
-
end
|
12
|
-
|
2
|
+
class PostProcessor < Lono::AbstractBase
|
13
3
|
def run
|
14
4
|
replacements.each do |placeholder, replacement|
|
15
5
|
update_template!(template)
|
@@ -18,7 +8,7 @@ class Lono::Template
|
|
18
8
|
end
|
19
9
|
|
20
10
|
def write_template!
|
21
|
-
IO.write(template_path, YAML.dump(template)) # unless ENV['
|
11
|
+
IO.write(template_path, YAML.dump(template)) # unless ENV['LONO_TEST'] # additional safeguard for testing
|
22
12
|
end
|
23
13
|
|
24
14
|
def replacements
|
@@ -1,16 +1,14 @@
|
|
1
|
-
|
1
|
+
module Lono::Template::Strategy
|
2
2
|
class Dsl < Base
|
3
3
|
attr_reader :results
|
4
|
-
def initialize(
|
4
|
+
def initialize(options={})
|
5
5
|
super
|
6
6
|
end
|
7
7
|
|
8
8
|
def run
|
9
9
|
puts "Generating CloudFormation templates for blueprint #{@blueprint.color(:green)}:" unless @options[:quiet]
|
10
|
-
|
11
|
-
|
12
|
-
build_template(path)
|
13
|
-
end
|
10
|
+
template_path = "#{Lono.config.templates_path}/#{@template}.rb"
|
11
|
+
build_template(template_path)
|
14
12
|
end
|
15
13
|
|
16
14
|
def build_template(path)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Lono::Template::Dsl
|
1
|
+
class Lono::Template::Strategy::Dsl
|
2
2
|
class Builder
|
3
3
|
include Lono::Template::Util
|
4
4
|
include Lono::Template::Context::Loader
|
@@ -9,38 +9,34 @@ class Lono::Template::Dsl
|
|
9
9
|
def initialize(path, blueprint, options={})
|
10
10
|
@path, @blueprint, @options = path, blueprint, options
|
11
11
|
@template = @path.sub("#{Lono.config.templates_path}/",'').sub(/\.rb$/,'')
|
12
|
+
@parameters = [] # registry
|
12
13
|
@cfn = {}
|
13
14
|
end
|
14
15
|
|
15
16
|
def build
|
16
17
|
load_context
|
17
18
|
evaluate_template_path(@path) # modifies @cfn
|
18
|
-
|
19
|
+
finalize
|
20
|
+
to_yaml
|
19
21
|
write_output
|
20
|
-
|
22
|
+
@cfn
|
21
23
|
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
evaluate_template_path(@path) # modifies @cfn
|
27
|
-
@cfn
|
25
|
+
def finalize
|
26
|
+
o = @options.merge(parameters: @parameters)
|
27
|
+
@cfn = Finalizer.new(@cfn, o).run
|
28
28
|
end
|
29
|
-
memoize :template
|
30
29
|
|
31
|
-
def
|
30
|
+
def to_yaml
|
32
31
|
@results = YAML.dump(@cfn)
|
33
32
|
end
|
34
33
|
|
35
34
|
def write_output
|
36
|
-
|
37
|
-
FileUtils.mkdir_p(output_path)
|
38
|
-
|
39
|
-
path = "#{output_path}/#{@template}.yml"
|
35
|
+
path = "#{Lono.config.output_path}/#{@blueprint}/templates/#{@template}.yml"
|
40
36
|
ensure_parent_dir(path)
|
41
37
|
IO.write(path, @results)
|
42
38
|
|
43
|
-
|
39
|
+
Lono::Yamler::Validator.new(path).validate!
|
44
40
|
|
45
41
|
unless @options[:quiet]
|
46
42
|
pretty_path = path.sub("#{Lono.root}/",'')
|