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
data/lib/lono/cli/build.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
class Lono::CLI
|
2
|
-
class Build < Base
|
3
|
-
delegate :param_path, to: :param_builder
|
4
|
-
|
5
|
-
# Use class variable to cache this only runs once across all classes. base.rb, diff.rb, preview.rb
|
6
|
-
def all
|
7
|
-
ensure_s3_bucket_exist unless build_only?
|
8
|
-
pre_build
|
9
|
-
template_builder.run # build with some placeholders for build_files IE: file://app/files/my.rb
|
10
|
-
post_build
|
11
|
-
upload unless build_only?
|
12
|
-
|
13
|
-
parameters = param_builder.build # Writes the json file in CamelCase keys format
|
14
|
-
logger.info "" # newline
|
15
|
-
parameters
|
16
|
-
end
|
17
|
-
memoize :all
|
18
|
-
|
19
|
-
def parameters
|
20
|
-
all
|
21
|
-
end
|
22
|
-
|
23
|
-
def build_only?
|
24
|
-
ENV['LONO_BUILD_ONLY'] || @options[:build_only]
|
25
|
-
end
|
26
|
-
|
27
|
-
def pre_build
|
28
|
-
build_scripts
|
29
|
-
end
|
30
|
-
|
31
|
-
def post_build
|
32
|
-
return if @options[:source]
|
33
|
-
build_files # builds app/files to output/BLUEPRINT/files
|
34
|
-
post_process_template
|
35
|
-
end
|
36
|
-
|
37
|
-
def ensure_s3_bucket_exist
|
38
|
-
bucket = Lono::S3::Bucket.new
|
39
|
-
return if bucket.exist?
|
40
|
-
bucket.deploy
|
41
|
-
end
|
42
|
-
|
43
|
-
def build_scripts
|
44
|
-
Lono::Script::Build.new(@options).run
|
45
|
-
end
|
46
|
-
|
47
|
-
def build_files
|
48
|
-
Lono::AppFile::Build.new(@options).run
|
49
|
-
Lono::Configset::S3File::Build.new(@options).run # copies files to the output folder
|
50
|
-
end
|
51
|
-
|
52
|
-
def post_process_template
|
53
|
-
# support for file://app/files/lambda_layer replacement
|
54
|
-
# TODO: Lono::Builder::Template::PostProcessor.new(@options).run
|
55
|
-
end
|
56
|
-
|
57
|
-
def upload
|
58
|
-
upload_files
|
59
|
-
upload_scripts
|
60
|
-
upload_templates
|
61
|
-
end
|
62
|
-
|
63
|
-
def upload_templates
|
64
|
-
Lono::Builder::Template::Upload.new(@options).run
|
65
|
-
end
|
66
|
-
|
67
|
-
def upload_scripts
|
68
|
-
Lono::Script::Upload.new(@options).run
|
69
|
-
end
|
70
|
-
|
71
|
-
def upload_files
|
72
|
-
Lono::AppFile::Upload.new(@options).upload
|
73
|
-
Lono::Configset::S3File::Upload.new(@options).upload
|
74
|
-
end
|
75
|
-
|
76
|
-
def param_builder
|
77
|
-
o = {
|
78
|
-
regenerate: true,
|
79
|
-
allow_not_exists: true,
|
80
|
-
}.merge(@options)
|
81
|
-
o = HashWithIndifferentAccess.new(o)
|
82
|
-
Lono::Builder::Param.new(o)
|
83
|
-
end
|
84
|
-
memoize :param_builder
|
85
|
-
|
86
|
-
def template_builder
|
87
|
-
Lono::Builder::Template.new(@options) # write templates to disk
|
88
|
-
end
|
89
|
-
memoize :template_builder
|
90
|
-
end
|
91
|
-
end
|
data/lib/lono/cli/code.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
class Lono::CLI
|
2
|
-
class Code < Lono::Command
|
3
|
-
desc "import SOURCE", "Imports CloudFormation template and converts it to Ruby code."
|
4
|
-
long_desc Help.text("code/import")
|
5
|
-
option :blueprint, default: nil, desc: "final blueprint name"
|
6
|
-
option :casing, default: "as-is", desc: "Controls casing of logical ids. IE: as-is, camelcase or underscore"
|
7
|
-
option :summary, default: true, type: :boolean, desc: "provide template summary after import"
|
8
|
-
option :template, default: nil, desc: "final template name of downloaded template without extension"
|
9
|
-
option :template_name_casing, default: "dasherize", desc: "camelcase or dasherize the template name"
|
10
|
-
option :type, default: "dsl", desc: "import as a DSL or ERB template"
|
11
|
-
def import(source)
|
12
|
-
Importer.new(options.merge(source: source)).run
|
13
|
-
end
|
14
|
-
|
15
|
-
desc "convert SOURCE", "Converts snippet of JSON or YAML CloudFormation template to Ruby code."
|
16
|
-
long_desc Help.text("code/convert")
|
17
|
-
option :casing, default: "as-is", desc: "Controls casing of logical ids. IE: as-is, camelcase or underscore"
|
18
|
-
def convert(source)
|
19
|
-
Importer::Converter.new(options.merge(source: source)).run
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
## Examples
|
2
|
-
|
3
|
-
lono blueprint new demo # skeleton blueprint with barebones structure
|
4
|
-
|
5
|
-
## Example Output
|
6
|
-
|
7
|
-
$ lono blueprint new demo
|
8
|
-
=> Creating new blueprint called demo.
|
9
|
-
create blueprints/demo
|
10
|
-
create blueprints/demo/demo.gemspec
|
11
|
-
create blueprints/demo/.gitignore
|
12
|
-
create blueprints/demo/CHANGELOG.md
|
13
|
-
create blueprints/demo/Gemfile
|
14
|
-
create blueprints/demo/README.md
|
15
|
-
create blueprints/demo/Rakefile
|
16
|
-
create blueprints/demo/seed/configs.rb
|
17
|
-
exist blueprints/demo
|
18
|
-
create blueprints/demo/app/templates/demo.rb
|
19
|
-
create blueprints/demo/app/user_data/bootstrap.sh
|
20
|
-
exist blueprints/demo/app/templates
|
21
|
-
exist
|
22
|
-
create config/demo/params/development.txt
|
23
|
-
create config/demo/params/production.txt
|
24
|
-
create config/demo/variables/development.rb
|
25
|
-
create config/demo/variables/production.rb
|
26
|
-
=> Installing dependencies with: bundle install
|
27
|
-
Fetching gem metadata from https://rubygems.org/..........
|
28
|
-
...
|
29
|
-
Bundle complete! 4 Gemfile dependencies, 9 gems now installed.
|
30
|
-
Use `bundle info [gemname]` to see where a bundled gem is installed.
|
31
|
-
================================================================
|
32
|
-
Congrats You have successfully created a lono blueprint.
|
33
|
-
|
34
|
-
Cd into your blueprint and check things out.
|
35
|
-
|
36
|
-
cd demo
|
37
|
-
|
38
|
-
More info: https://lono.cloud/docs/core/blueprints
|
39
|
-
|
40
|
-
Here is the structure of your blueprint:
|
41
|
-
|
42
|
-
.
|
43
|
-
├── app
|
44
|
-
│ ├── templates
|
45
|
-
│ │ └── demo.rb
|
46
|
-
│ └── user_data
|
47
|
-
│ └── bootstrap.sh
|
48
|
-
├── CHANGELOG.md
|
49
|
-
├── demo.gemspec
|
50
|
-
├── Gemfile
|
51
|
-
├── Gemfile.lock
|
52
|
-
├── Rakefile
|
53
|
-
├── README.md
|
54
|
-
└── seed
|
55
|
-
└── configs.rb
|
56
|
-
$
|
@@ -1,57 +0,0 @@
|
|
1
|
-
class Lono::CLI::New
|
2
|
-
class Extension < Sequence
|
3
|
-
argument :extension_name
|
4
|
-
|
5
|
-
def self.source_root
|
6
|
-
templates = File.expand_path("../../templates", File.dirname(__FILE__))
|
7
|
-
"#{templates}/extension"
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.cli_options
|
11
|
-
[
|
12
|
-
[:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
|
13
|
-
]
|
14
|
-
end
|
15
|
-
|
16
|
-
cli_options.each do |args|
|
17
|
-
class_option(*args)
|
18
|
-
end
|
19
|
-
|
20
|
-
# for specs
|
21
|
-
def set_cwd
|
22
|
-
@cwd = ENV['LONO_TEST'] ? File.dirname(Lono.root) : "#{Dir.pwd}/app/extensions"
|
23
|
-
end
|
24
|
-
|
25
|
-
def create_project
|
26
|
-
puts "=> Creating new extension called #{extension_name}."
|
27
|
-
directory ".", "#{@cwd}/#{extension_name}", options
|
28
|
-
end
|
29
|
-
|
30
|
-
def create_license
|
31
|
-
return unless ENV['LONO_LICENSE_FILE']
|
32
|
-
copy_file ENV['LONO_LICENSE_FILE'], "#{@cwd}/#{extension_name}/LICENSE.txt"
|
33
|
-
end
|
34
|
-
|
35
|
-
# After this commands are executed with the newly created project
|
36
|
-
def set_destination_root
|
37
|
-
destination_root = "#{@cwd}/#{extension_name}"
|
38
|
-
self.destination_root = destination_root
|
39
|
-
@old_dir = Dir.pwd # for reset_current_dir
|
40
|
-
FileUtils.cd(self.destination_root)
|
41
|
-
end
|
42
|
-
|
43
|
-
def welcome_message
|
44
|
-
puts <<~EOL
|
45
|
-
#{"="*64}
|
46
|
-
Congrats 🎉 You have successfully created a lono extension.
|
47
|
-
|
48
|
-
Cd into your extension and check things out.
|
49
|
-
|
50
|
-
cd #{extension_name}
|
51
|
-
|
52
|
-
More info: https://lono.cloud/docs/extensions
|
53
|
-
|
54
|
-
EOL
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
module Lono::Configset
|
2
|
-
class Builder
|
3
|
-
include Lono::Utils::Logging
|
4
|
-
|
5
|
-
def initialize(options)
|
6
|
-
@options = options
|
7
|
-
@configset = options[:configset]
|
8
|
-
@type = options[:type] || "project"
|
9
|
-
end
|
10
|
-
|
11
|
-
def run
|
12
|
-
check_configset_exist!
|
13
|
-
structure = build
|
14
|
-
logger.info YAML.dump(structure)
|
15
|
-
end
|
16
|
-
|
17
|
-
def check_configset_exist!
|
18
|
-
exist = !!Lono::Finder::Configset.find(@configset)
|
19
|
-
unless exist
|
20
|
-
logger.info "configset #{@configset.color(:green)} not found."
|
21
|
-
exit 1
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def build
|
26
|
-
# Examples:
|
27
|
-
# Erb.new(options).build
|
28
|
-
# Dsl.new(options).build
|
29
|
-
builder_class = "Lono::Configset::Strategy::#{strategy.camelize}"
|
30
|
-
builder_class = Object.const_get(builder_class)
|
31
|
-
full = builder_class.new(@options.merge(root: configset_root)).build
|
32
|
-
if @options[:cli]
|
33
|
-
full["Metadata"] # contains AWS::CloudFormation::Init and optional AWS::CloudFormation::Authentication
|
34
|
-
else
|
35
|
-
full # Combiner uses full metadata structure
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def strategy
|
40
|
-
jadespec = Lono::Jadespec.new(configset_root, "unknown") # abusing Jadespec to get strategy
|
41
|
-
jadespec.lono_strategy
|
42
|
-
end
|
43
|
-
|
44
|
-
def configset_root
|
45
|
-
finder = finder_class.new
|
46
|
-
found = finder.find(@configset, local_only: false)
|
47
|
-
found.root if found
|
48
|
-
end
|
49
|
-
|
50
|
-
def finder_class
|
51
|
-
case @type
|
52
|
-
when "project"
|
53
|
-
Lono::Finder::Configset
|
54
|
-
when "blueprint"
|
55
|
-
Lono::Finder::Blueprint::Configset
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,164 +0,0 @@
|
|
1
|
-
require "yaml"
|
2
|
-
|
3
|
-
module Lono::Configset
|
4
|
-
class Combiner
|
5
|
-
include Lono::Utils::Logging
|
6
|
-
|
7
|
-
def initialize(cfn, options={})
|
8
|
-
@cfn, @options = cfn, options
|
9
|
-
|
10
|
-
@sets = []
|
11
|
-
@map = {} # stores resource logical id => metadata cfn-init
|
12
|
-
end
|
13
|
-
|
14
|
-
def generator_options(registry, options={})
|
15
|
-
o = @options.merge(configset: registry.name, resource: registry.resource)
|
16
|
-
o.merge(options)
|
17
|
-
end
|
18
|
-
|
19
|
-
def metadata_map
|
20
|
-
return {} unless additional_configsets?
|
21
|
-
|
22
|
-
existing_configsets.each do |data|
|
23
|
-
add(data[:registry], data[:metdata_configset])
|
24
|
-
end
|
25
|
-
|
26
|
-
Register::Blueprint.configsets.each do |registry|
|
27
|
-
generator = Lono::Configset::Generator.new(generator_options(registry, type: "blueprint"))
|
28
|
-
cloudformation_init = generator.build
|
29
|
-
add(registry, cloudformation_init)
|
30
|
-
end
|
31
|
-
Register::Project.configsets.each do |registry|
|
32
|
-
generator = Lono::Configset::Generator.new(generator_options(registry, type: "project"))
|
33
|
-
cloudformation_init = generator.build
|
34
|
-
add(registry, cloudformation_init)
|
35
|
-
end
|
36
|
-
|
37
|
-
combine
|
38
|
-
Register::Blueprint.clear! # in case of lono build for all templates
|
39
|
-
Register::Project.clear! # in case of lono build for all templates
|
40
|
-
@map
|
41
|
-
end
|
42
|
-
|
43
|
-
def add(registry, metadata)
|
44
|
-
@sets << [registry, metadata.dup]
|
45
|
-
end
|
46
|
-
|
47
|
-
def additional_configsets?
|
48
|
-
!Register::Blueprint.configsets.empty? || !Register::Project.configsets.empty?
|
49
|
-
end
|
50
|
-
|
51
|
-
# Normalized/convert cfn template to mimic the registry format
|
52
|
-
def existing_configsets
|
53
|
-
configsets = []
|
54
|
-
@cfn["Resources"].each do |logical_id, attributes|
|
55
|
-
init = attributes.dig("Metadata", "AWS::CloudFormation::Init")
|
56
|
-
|
57
|
-
next unless init
|
58
|
-
|
59
|
-
data = {
|
60
|
-
registry: Lono::Jade::Registry.new(["#{logical_id}OriginalConfigset"], resource: logical_id),
|
61
|
-
metdata_configset: {"Metadata" => attributes["Metadata"]} # # wrap metadata to create right structure
|
62
|
-
}
|
63
|
-
configsets << data
|
64
|
-
end
|
65
|
-
configsets
|
66
|
-
end
|
67
|
-
|
68
|
-
def combine
|
69
|
-
# Remove duplicate configsets. Can happen if same configset is in blueprint and project.
|
70
|
-
# Ugly because of the sets structure.
|
71
|
-
@sets.uniq! do |array|
|
72
|
-
registry, _ = array
|
73
|
-
registry.name
|
74
|
-
end
|
75
|
-
|
76
|
-
metadata_map = {}
|
77
|
-
configsets_map = {}
|
78
|
-
|
79
|
-
@sets.each_with_index do |array, i|
|
80
|
-
padded_i = "%03d" % i
|
81
|
-
registry, metadata = array
|
82
|
-
|
83
|
-
# metadata example (full structure):
|
84
|
-
#
|
85
|
-
# {"Metadata"=>
|
86
|
-
# {"AWS::CloudFormation::Init"=>
|
87
|
-
# {"configSets"=>{"default"=>["aaa1", "aaa2"]},
|
88
|
-
# "aaa1"=>{"commands"=>{"test"=>{"command"=>"echo from-aaa1 > test1.txt"}}},
|
89
|
-
# "aaa2"=>
|
90
|
-
# {"commands"=>{"test"=>{"command"=>"echo from-aaa2 > test1.txt"}}}}}}
|
91
|
-
|
92
|
-
name, resource = registry.name, registry.resource
|
93
|
-
configsets = configsets_map[resource] ||= {}
|
94
|
-
|
95
|
-
validate_structure!(name, metadata)
|
96
|
-
|
97
|
-
new_metadata = metadata["Metadata"].dup
|
98
|
-
init = new_metadata["AWS::CloudFormation::Init"] # important: adjust data by reference
|
99
|
-
|
100
|
-
if init.key?("configSets")
|
101
|
-
validate_simple!(registry, new_metadata["AWS::CloudFormation::Init"]["configSets"]) # validate original configset for only simple elements
|
102
|
-
|
103
|
-
# 1. expand each config as its own config, flattening to top-level
|
104
|
-
cs = init.delete("configSets") # Only support configSets with simple Array of Strings
|
105
|
-
new_config_set = {}
|
106
|
-
new_config_set[name] = cs["default"].map {|c| "#{padded_i}_#{c}" }
|
107
|
-
init.transform_keys! { |c| "#{padded_i}_#{c}" }
|
108
|
-
|
109
|
-
# Rebuild default configSet, append the new complex ConfigSet structure with each iteration
|
110
|
-
configsets["default"] ||= []
|
111
|
-
configsets["default"] << {"ConfigSet" => name}
|
112
|
-
configsets.merge!(new_config_set) # add each config from #1 to the top-level
|
113
|
-
|
114
|
-
init["configSets"] = configsets # replace new configset
|
115
|
-
else # simple config
|
116
|
-
init["configSets"] = configsets # adjust data by reference
|
117
|
-
configsets["default"] ||= []
|
118
|
-
configsets["default"] << {"ConfigSet" => name}
|
119
|
-
|
120
|
-
# build new config
|
121
|
-
config_key = "#{padded_i}_single_generated"
|
122
|
-
configsets[name] = [config_key]
|
123
|
-
new_config = {config_key => init["config"]}
|
124
|
-
# replace old config with new one
|
125
|
-
init.delete("config") # delete original simple config
|
126
|
-
init.merge!(new_config)
|
127
|
-
end
|
128
|
-
|
129
|
-
metadata_map[resource] ||= {"Metadata" => {}}
|
130
|
-
metadata_map[resource]["Metadata"].deep_merge!(new_metadata)
|
131
|
-
@map[resource] = metadata_map[resource]
|
132
|
-
end
|
133
|
-
@map
|
134
|
-
end
|
135
|
-
|
136
|
-
def validate_structure!(name, metadata)
|
137
|
-
return if metadata.is_a?(Hash) && metadata.dig("Metadata", "AWS::CloudFormation::Init")
|
138
|
-
|
139
|
-
logger.info "ERROR: The #{name} configset does not appear to have a AWS::CloudFormation::Init key".color(:red)
|
140
|
-
logger.info "Please double check the #{name} configset.yml structure"
|
141
|
-
exit 1
|
142
|
-
end
|
143
|
-
|
144
|
-
def validate_simple!(registry, cs)
|
145
|
-
has_complex_type = cs["default"].detect { |s| !s.is_a?(String) }
|
146
|
-
if has_complex_type
|
147
|
-
message =<<~EOL
|
148
|
-
ERROR: The configset #{registry.name} has a configSets property with a complex type.
|
149
|
-
configSets:
|
150
|
-
|
151
|
-
#{cs}
|
152
|
-
|
153
|
-
lono configsets only supports combining configSets with an Array of Strings.
|
154
|
-
EOL
|
155
|
-
if ENV['LONO_TEST']
|
156
|
-
raise message
|
157
|
-
else
|
158
|
-
logger.info message.color(:red)
|
159
|
-
exit 1
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
class Lono::Configset::Meta
|
2
|
-
module Dsl
|
3
|
-
def depends_on(*args)
|
4
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
5
|
-
registry = Lono::Jade::Registry.new(args, options)
|
6
|
-
registry.depends_on = args.first
|
7
|
-
registry.parent = @jade
|
8
|
-
already_has = @jade.depends_ons.detect { |d| d.name == registry.name && d.args == registry.args }
|
9
|
-
@jade.depends_ons << registry unless already_has
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
data/lib/lono/configset/meta.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Lono::Configset
|
2
|
-
class Meta
|
3
|
-
extend Memoist
|
4
|
-
include EvaluateFile
|
5
|
-
include Dsl
|
6
|
-
|
7
|
-
class_attribute :registries
|
8
|
-
self.registries = []
|
9
|
-
|
10
|
-
def initialize(jade)
|
11
|
-
@jade = jade
|
12
|
-
end
|
13
|
-
|
14
|
-
def evaluate
|
15
|
-
path = "#{@jade.root}/lib/meta.rb"
|
16
|
-
evaluate_file(path) # DSL depends_on sets @jade.depends_on decorated options
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Lono::Configset::S3File
|
2
|
-
class Build < Lono::CLI::Base
|
3
|
-
include Lono::Utils::Item::Zip
|
4
|
-
include Lono::Utils::Logging
|
5
|
-
include Lono::Utils::Rsync
|
6
|
-
|
7
|
-
def run
|
8
|
-
Lono::Configset::S3File::Registry.items.each do |item|
|
9
|
-
build(item)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def build(item)
|
14
|
-
copy_to_output(item)
|
15
|
-
compress_output
|
16
|
-
end
|
17
|
-
|
18
|
-
def copy_to_output(item)
|
19
|
-
src = "#{item.root}/lib/files/#{item.name}"
|
20
|
-
dest = "#{Lono.root}/output/#{@blueprint.name}/configsets/#{item.configset}/files/#{item.name}"
|
21
|
-
rsync(src, dest)
|
22
|
-
end
|
23
|
-
|
24
|
-
def compress_output
|
25
|
-
Registry.items.each do |item|
|
26
|
-
if item.exist?
|
27
|
-
zip(item)
|
28
|
-
else
|
29
|
-
logger.info "WARN: #{item.src_path} does not exist. Double check that the path is correct in the s3_key call.".color(:yellow)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module Lono::Configset::S3File
|
2
|
-
# Holds metadata about the item in the regsitry.
|
3
|
-
class Item
|
4
|
-
include Lono::Utils::Item::FileMethods
|
5
|
-
|
6
|
-
attr_reader :name, :configset, :root
|
7
|
-
def initialize(name, options={})
|
8
|
-
@name, @options = name, options
|
9
|
-
@blueprint = options[:blueprint]
|
10
|
-
@configset = options[:configset]
|
11
|
-
@root = options[:root]
|
12
|
-
@type = options[:type] || 'file'
|
13
|
-
end
|
14
|
-
|
15
|
-
def src_path
|
16
|
-
"#{@root}/lib/files"
|
17
|
-
end
|
18
|
-
|
19
|
-
def output_path
|
20
|
-
"#{Lono.root}/output/#{@blueprint.name}/configsets/#{@configset}/files/#{@name}"
|
21
|
-
end
|
22
|
-
|
23
|
-
def replacement_value
|
24
|
-
aws_data = AwsData.new
|
25
|
-
#
|
26
|
-
# "https://s3.amazonaws.com/#{Lono::S3::Bucket.name}/#{s3_path}"
|
27
|
-
# "https://lono-bucket-12di8xz5sy72z.s3-us-west-2.amazonaws.com/stuff/s3-antivirus.tgz"
|
28
|
-
#
|
29
|
-
# us-east-1 is special case:
|
30
|
-
#
|
31
|
-
# "https://lono-bucket-12di8xz5sy72z.s3.amazonaws.com/stuff/s3-antivirus.tgz"
|
32
|
-
#
|
33
|
-
region = ""
|
34
|
-
region = "-#{aws_data.region}" unless aws_data.region == "us-east-1"
|
35
|
-
"https://#{Lono::S3::Bucket.name}.s3#{region}.amazonaws.com/#{s3_path}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module Lono::Configset::S3File
|
2
|
-
class Upload < Lono::CLI::Base
|
3
|
-
def upload
|
4
|
-
return unless Registry.items.size > 0
|
5
|
-
logger.info "Uploading configset files..."
|
6
|
-
|
7
|
-
Registry.items.each do |item|
|
8
|
-
Lono::S3::Uploader.new(item.zip_file_path).upload
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# Subclasses must implement:
|
2
|
-
#
|
3
|
-
# find_evaluation_path - use to set @evaluation_path
|
4
|
-
# load
|
5
|
-
#
|
6
|
-
# Notable instance variables:
|
7
|
-
#
|
8
|
-
# @evaluation_path - IE: lib/configset.rb or lib/configset.yml
|
9
|
-
# @root - IE: /path/to/root/of/configset
|
10
|
-
#
|
11
|
-
module Lono::Configset::Strategy
|
12
|
-
class Base
|
13
|
-
extend Memoist
|
14
|
-
include Lono::Configset::EvaluateFile
|
15
|
-
|
16
|
-
# All Lono DSL Helpers and Fn - so configsets have access to instrinic functions like ref
|
17
|
-
# Not including the Lono::Builder::Template::Strategy::Dsl::Evaluator::Syntax since dont need those methods
|
18
|
-
#
|
19
|
-
# Interesting note: must include these modules here so load_project_predefined_variables works.
|
20
|
-
# Since load_project_predefined_variables calls evaluate_file / instance eval which seems to only be
|
21
|
-
# able to access methods from the direct class, not inherited classes like Dsl.
|
22
|
-
#
|
23
|
-
# This allows methods like ref and sub to work in variables files.
|
24
|
-
#
|
25
|
-
include Lono::Builder::Template::Strategy::Dsl::Evaluator::Helpers
|
26
|
-
include Lono::Builder::Template::Strategy::Dsl::Evaluator::Fn
|
27
|
-
|
28
|
-
def initialize(options={})
|
29
|
-
@options = options
|
30
|
-
@configset = options[:configset]
|
31
|
-
@root = options[:root]
|
32
|
-
@resource = options[:resource] || "FakeResource"
|
33
|
-
@blueprin = options[:blueprint]
|
34
|
-
end
|
35
|
-
|
36
|
-
def build
|
37
|
-
@evaluation_path = find_evaluation_path # implemented by subclass
|
38
|
-
copy_instance_variables
|
39
|
-
load_configset_helpers
|
40
|
-
init = load # implemented by subclass
|
41
|
-
finish_full_structure(init)
|
42
|
-
end
|
43
|
-
memoize :build
|
44
|
-
|
45
|
-
def finish_full_structure(init)
|
46
|
-
full = {"Metadata" => {}}
|
47
|
-
full["Metadata"]["AWS::CloudFormation::Init"] = init["AWS::CloudFormation::Init"]
|
48
|
-
full["Metadata"]["AWS::CloudFormation::Authentication"] = authentication if authentication # only on dsl
|
49
|
-
full.deep_stringify_keys!
|
50
|
-
end
|
51
|
-
|
52
|
-
def copy_instance_variables
|
53
|
-
load_blueprint_predefined_variables
|
54
|
-
load_project_predefined_variables
|
55
|
-
end
|
56
|
-
|
57
|
-
def load_blueprint_predefined_variables
|
58
|
-
evaluate_file("#{@root}/lib/variables.rb")
|
59
|
-
end
|
60
|
-
|
61
|
-
def load_project_predefined_variables
|
62
|
-
paths = [
|
63
|
-
"#{Lono.root}/config/#{@blueprint.name}/configsets/variables.rb", # global
|
64
|
-
"#{Lono.root}/config/#{@blueprint.name}/configsets/variables/#{@configset}.rb", # configset specific
|
65
|
-
]
|
66
|
-
paths.each do |path|
|
67
|
-
evaluate_file(path)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def load_configset_helpers
|
72
|
-
paths = Dir.glob("#{@root}/lib/helpers/**/*.rb")
|
73
|
-
paths.sort_by! { |p| p.size } # load possible namespaces first
|
74
|
-
paths.each do |path|
|
75
|
-
filename = path.sub(%r{.*/lib/helpers/},'').sub('.rb','')
|
76
|
-
module_name = filename.camelize
|
77
|
-
|
78
|
-
require path
|
79
|
-
self.class.send :include, module_name.constantize
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|