lono 4.2.7 → 5.0.1
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/.cody/README.md +6 -0
- data/.cody/acceptance.sh +30 -0
- data/.cody/buildspec.yml +21 -0
- data/.cody/demo.rb +38 -0
- data/.cody/project.rb +12 -0
- data/.cody/role.rb +1 -0
- data/.gitignore +2 -0
- data/.gitmodules +6 -3
- data/.travis.yml +7 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +0 -1
- data/LICENSE.txt +1 -22
- data/README.md +46 -55
- data/lib/lono.rb +20 -27
- data/lib/lono/app_file.rb +5 -0
- data/lib/lono/app_file/base.rb +19 -0
- data/lib/lono/app_file/build.rb +78 -0
- data/lib/lono/app_file/registry.rb +14 -0
- data/lib/lono/app_file/registry/item.rb +46 -0
- data/lib/lono/app_file/upload.rb +39 -0
- data/lib/lono/autoloader.rb +22 -0
- data/lib/lono/aws_services.rb +46 -0
- data/lib/lono/aws_services/util.rb +49 -0
- data/lib/lono/blueprint.rb +113 -0
- data/lib/lono/blueprint/find.rb +90 -0
- data/lib/lono/blueprint/helper.rb +18 -0
- data/lib/lono/blueprint/info.rb +10 -0
- data/lib/lono/blueprint/list.rb +14 -0
- data/lib/lono/blueprint/root.rb +43 -0
- data/lib/lono/cfn.rb +31 -19
- data/lib/lono/cfn/aws_service.rb +16 -0
- data/lib/lono/cfn/base.rb +244 -261
- data/lib/lono/cfn/create.rb +36 -32
- data/lib/lono/cfn/current.rb +1 -1
- data/lib/lono/cfn/delete.rb +2 -2
- data/lib/lono/cfn/deploy.rb +11 -0
- data/lib/lono/cfn/diff.rb +1 -1
- data/lib/lono/cfn/preview.rb +3 -3
- data/lib/lono/cfn/rollback.rb +26 -0
- data/lib/lono/cfn/status.rb +2 -203
- data/lib/lono/cfn/suffix.rb +67 -0
- data/lib/lono/cfn/update.rb +61 -53
- data/lib/lono/cli.rb +42 -23
- data/lib/lono/completer.rb +0 -2
- data/lib/lono/configure.rb +37 -0
- data/lib/lono/configure/aws_services.rb +18 -0
- data/lib/lono/configure/base.rb +94 -0
- data/lib/lono/configure/helpers.rb +128 -0
- data/lib/lono/conventions.rb +11 -0
- data/lib/lono/core.rb +42 -12
- data/lib/lono/core/config.rb +5 -4
- data/lib/lono/default/settings.yml +0 -11
- data/lib/lono/file_uploader.rb +9 -4
- data/lib/lono/help.rb +1 -2
- data/lib/lono/help/blueprint.md +46 -0
- data/lib/lono/help/cfn.md +5 -4
- data/lib/lono/help/cfn/create.md +14 -9
- data/lib/lono/help/cfn/deploy.md +92 -0
- data/lib/lono/help/cfn/diff.md +0 -1
- data/lib/lono/help/cfn/update.md +16 -15
- data/lib/lono/help/completion.md +3 -3
- data/lib/lono/help/generate.md +0 -1
- data/lib/lono/help/new.md +40 -34
- data/lib/lono/help/param.md +1 -1
- data/lib/lono/help/param/generate.md +1 -1
- data/lib/lono/help/template.md +2 -2
- data/lib/lono/help/xgraph.md +1 -1
- data/lib/lono/inspector.rb +1 -1
- data/lib/lono/inspector/base.rb +26 -10
- data/lib/lono/inspector/graph.rb +7 -3
- data/lib/lono/inspector/summary.rb +15 -3
- data/lib/lono/md5.rb +46 -0
- data/lib/lono/new.rb +40 -28
- data/lib/lono/new/helper.rb +2 -3
- data/lib/lono/param.rb +12 -11
- data/lib/lono/param/generator.rb +96 -42
- data/lib/lono/project_checker.rb +27 -8
- data/lib/lono/s3.rb +23 -0
- data/lib/lono/s3/bucket.rb +123 -0
- data/lib/lono/script.rb +4 -8
- data/lib/lono/script/base.rb +7 -2
- data/lib/lono/script/build.rb +7 -8
- data/lib/lono/script/upload.rb +4 -20
- data/lib/lono/sequence.rb +19 -16
- data/lib/lono/setting.rb +19 -27
- data/lib/lono/template.rb +22 -26
- data/lib/lono/template/base.rb +13 -0
- data/lib/lono/template/context.rb +4 -56
- data/lib/lono/template/context/loader.rb +70 -0
- data/lib/lono/template/dsl.rb +15 -151
- data/lib/lono/template/dsl/builder.rb +60 -0
- data/lib/lono/template/dsl/builder/base.rb +14 -0
- data/lib/lono/template/dsl/builder/condition.rb +26 -0
- data/lib/lono/template/dsl/builder/fn.rb +114 -0
- data/lib/lono/template/dsl/builder/helper.rb +64 -0
- data/lib/lono/template/dsl/builder/mapping.rb +24 -0
- data/lib/lono/template/dsl/builder/output.rb +37 -0
- data/lib/lono/template/dsl/builder/parameter.rb +39 -0
- data/lib/lono/template/dsl/builder/resource.rb +38 -0
- data/lib/lono/template/dsl/builder/section.rb +12 -0
- data/lib/lono/template/dsl/builder/syntax.rb +58 -0
- data/lib/lono/template/erb.rb +82 -0
- data/lib/lono/template/evaluate.rb +39 -0
- data/lib/lono/template/generator.rb +29 -0
- data/lib/lono/template/helper.rb +7 -29
- data/lib/lono/template/post_processor.rb +69 -0
- data/lib/lono/template/template.rb +4 -9
- data/lib/lono/template/upload.rb +103 -133
- data/lib/lono/template/util.rb +48 -0
- data/lib/lono/upgrade.rb +5 -3
- data/lib/lono/upgrade/upgrade5.rb +55 -0
- data/lib/lono/user_data.rb +4 -4
- data/lib/lono/version.rb +1 -1
- data/lib/templates/blueprint/%blueprint_name%.gemspec.tt +44 -0
- data/lib/templates/blueprint/.gitignore +14 -0
- data/lib/templates/blueprint/.lono/config.yml.tt +3 -0
- data/lib/templates/blueprint/.meta/config.yml.tt +3 -0
- data/lib/templates/blueprint/CHANGELOG.md +7 -0
- data/lib/templates/blueprint/Gemfile +4 -0
- data/lib/templates/blueprint/README.md +37 -0
- data/lib/templates/blueprint/Rakefile +6 -0
- data/lib/templates/blueprint/setup/configs.rb +54 -0
- data/lib/templates/blueprint_configs/configs/%blueprint_name%/params/base.txt +2 -0
- data/lib/{starter_projects/skeleton/app/definitions/base.rb → templates/blueprint_configs/configs/%blueprint_name%/params/development.txt} +0 -0
- data/lib/templates/blueprint_configs/configs/%blueprint_name%/variables/base.rb +2 -0
- data/lib/templates/blueprint_configs/configs/%blueprint_name%/variables/development.rb +0 -0
- data/lib/templates/blueprint_types/dsl/app/templates/%blueprint_name%.rb +37 -0
- data/lib/templates/blueprint_types/dsl/app/user_data/bootstrap.sh +2 -0
- data/lib/templates/blueprint_types/erb/app/definitions/base.rb.tt +1 -0
- data/lib/templates/blueprint_types/erb/app/templates/%blueprint_name%.yml +8 -0
- data/lib/{starter_projects/autoscaling → templates/skeleton}/.gitignore +1 -0
- data/lib/templates/skeleton/Gemfile +3 -0
- data/lib/{starter_projects/autoscaling → templates/skeleton}/Guardfile +2 -2
- data/lib/templates/skeleton/README.md +58 -0
- data/lib/templates/skeleton/configs/settings.yml +17 -0
- data/lib/templates/upgrade5/blueprints/main/.lono/config.yml +3 -0
- data/lib/templates/upgrade5/blueprints/main/.meta/config.yml +3 -0
- data/lono.gemspec +12 -8
- data/vendor/cfn-status/CHANGELOG.md +10 -0
- data/vendor/cfn-status/Gemfile +4 -0
- data/vendor/cfn-status/LICENSE.txt +21 -0
- data/vendor/cfn-status/README.md +56 -0
- data/vendor/cfn-status/Rakefile +6 -0
- data/vendor/cfn-status/bin/console +14 -0
- data/vendor/cfn-status/bin/setup +8 -0
- data/vendor/cfn-status/cfn-status.gemspec +30 -0
- data/vendor/cfn-status/lib/cfn-status.rb +1 -0
- data/vendor/cfn-status/lib/cfn/aws_service.rb +51 -0
- data/vendor/cfn-status/lib/cfn/status.rb +219 -0
- data/vendor/cfn-status/lib/cfn/status/version.rb +5 -0
- data/vendor/cfn-status/spec/cfn/status_spec.rb +81 -0
- data/vendor/cfn-status/spec/fixtures/cfn/stack-events-complete.json +1080 -0
- data/vendor/cfn-status/spec/fixtures/cfn/stack-events-in-progress.json +1080 -0
- data/vendor/cfn-status/spec/fixtures/cfn/stack-events-update-rollback-complete.json +1086 -0
- data/vendor/cfn-status/spec/spec_helper.rb +14 -0
- data/vendor/cfn_camelizer/CHANGELOG.md +20 -0
- data/vendor/cfn_camelizer/Gemfile +4 -0
- data/vendor/cfn_camelizer/LICENSE.txt +21 -0
- data/vendor/cfn_camelizer/README.md +40 -0
- data/vendor/cfn_camelizer/Rakefile +6 -0
- data/vendor/cfn_camelizer/bin/console +14 -0
- data/vendor/cfn_camelizer/bin/setup +8 -0
- data/vendor/cfn_camelizer/cfn_camelizer.gemspec +32 -0
- data/vendor/cfn_camelizer/lib/camelizer.yml +37 -0
- data/vendor/cfn_camelizer/lib/cfn_camelizer.rb +94 -0
- data/vendor/cfn_camelizer/lib/cfn_camelizer/version.rb +3 -0
- data/vendor/cfn_camelizer/spec/cfn_camelizer_spec.rb +86 -0
- data/vendor/cfn_camelizer/spec/spec_helper.rb +14 -0
- metadata +189 -62
- data/.circleci/bin/commit_docs.sh +0 -26
- data/.circleci/config.yml +0 -72
- data/bin/release +0 -9
- data/lib/lono/help/import.md +0 -54
- data/lib/lono/importer.rb +0 -134
- data/lib/lono/new/message.rb +0 -35
- data/lib/starter_projects/autoscaling/Gemfile +0 -3
- data/lib/starter_projects/autoscaling/README.md +0 -118
- data/lib/starter_projects/autoscaling/app/definitions/base.rb +0 -2
- data/lib/starter_projects/autoscaling/app/templates/autoscaling.yml +0 -682
- data/lib/starter_projects/autoscaling/config/params/base/autoscaling.txt +0 -6
- data/lib/starter_projects/autoscaling/config/settings.yml +0 -33
- data/lib/starter_projects/ec2/.gitignore +0 -2
- data/lib/starter_projects/ec2/Gemfile +0 -3
- data/lib/starter_projects/ec2/Guardfile +0 -12
- data/lib/starter_projects/ec2/README.md +0 -86
- data/lib/starter_projects/ec2/app/definitions/base.rb +0 -2
- data/lib/starter_projects/ec2/app/definitions/development.rb +0 -1
- data/lib/starter_projects/ec2/app/definitions/production.rb +0 -1
- data/lib/starter_projects/ec2/app/helpers/my_custom_helper.rb +0 -17
- data/lib/starter_projects/ec2/app/partials/user_data/bootstrap.sh +0 -4
- data/lib/starter_projects/ec2/app/templates/example.yml +0 -430
- data/lib/starter_projects/ec2/config/params/base/example.txt +0 -2
- data/lib/starter_projects/ec2/config/params/development/example.txt +0 -3
- data/lib/starter_projects/ec2/config/params/production/example.txt +0 -2
- data/lib/starter_projects/ec2/config/settings.yml +0 -33
- data/lib/starter_projects/ec2/config/variables/base.rb +0 -3
- data/lib/starter_projects/ec2/config/variables/development.rb +0 -2
- data/lib/starter_projects/ec2/config/variables/production.rb +0 -2
- data/lib/starter_projects/ec2/welcome.txt +0 -8
- data/lib/starter_projects/skeleton/.gitignore +0 -2
- data/lib/starter_projects/skeleton/Gemfile +0 -3
- data/lib/starter_projects/skeleton/Guardfile +0 -12
- data/lib/starter_projects/skeleton/README.md +0 -53
- data/lib/starter_projects/skeleton/config/settings.yml +0 -33
- data/lib/starter_projects/skeleton/welcome.txt +0 -7
- data/vendor/plissken/Gemfile +0 -14
- data/vendor/plissken/LICENSE.txt +0 -20
- data/vendor/plissken/README.md +0 -46
- data/vendor/plissken/Rakefile +0 -56
- data/vendor/plissken/VERSION +0 -1
- data/vendor/plissken/lib/plissken.rb +0 -1
- data/vendor/plissken/lib/plissken/ext/hash/to_snake_keys.rb +0 -45
- data/vendor/plissken/plissken.gemspec +0 -61
- data/vendor/plissken/spec/lib/to_snake_keys_spec.rb +0 -177
- data/vendor/plissken/spec/spec_helper.rb +0 -90
- data/vendor/plissken/test/helper.rb +0 -20
- data/vendor/plissken/test/plissken/ext/hash/to_snake_keys_test.rb +0 -184
- data/vendor/plissken/test/test_plissken.rb +0 -2
data/lib/lono/script/upload.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
require "aws-sdk-s3"
|
|
2
1
|
require "filesize"
|
|
3
2
|
|
|
4
3
|
class Lono::Script
|
|
5
4
|
class Upload < Base
|
|
5
|
+
include Lono::AwsServices
|
|
6
|
+
|
|
6
7
|
def run
|
|
7
8
|
Lono::ProjectChecker.check
|
|
8
9
|
return unless scripts_built?
|
|
@@ -33,19 +34,12 @@ class Lono::Script
|
|
|
33
34
|
"#{dest_folder}/#{File.basename(tarball_path)}"
|
|
34
35
|
end
|
|
35
36
|
|
|
36
|
-
# Example:
|
|
37
|
-
# s3_folder: s3://infra-bucket/cloudformation
|
|
38
|
-
# bucket_name: infra-bucket
|
|
39
37
|
def bucket_name
|
|
40
|
-
|
|
38
|
+
Lono::S3::Bucket.name
|
|
41
39
|
end
|
|
42
40
|
|
|
43
|
-
# Removes s3://bucket-name and adds Lono.env. Example:
|
|
44
|
-
# s3_folder: s3://infra-bucket/cloudformation
|
|
45
|
-
# bucket_name: cloudformation/development/scripts
|
|
46
41
|
def dest_folder
|
|
47
|
-
|
|
48
|
-
"#{folder}/#{Lono.env}/scripts"
|
|
42
|
+
"#{Lono.env}/scripts"
|
|
49
43
|
end
|
|
50
44
|
|
|
51
45
|
# Scripts are only built if the app/scripts folder is non empty
|
|
@@ -57,16 +51,6 @@ class Lono::Script
|
|
|
57
51
|
IO.read(SCRIPTS_INFO_PATH).strip
|
|
58
52
|
end
|
|
59
53
|
|
|
60
|
-
# s3_folder example:
|
|
61
|
-
def s3_folder
|
|
62
|
-
setting = Lono::Setting.new
|
|
63
|
-
setting.s3_folder
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def s3_resource
|
|
67
|
-
@s3_resource ||= Aws::S3::Resource.new
|
|
68
|
-
end
|
|
69
|
-
|
|
70
54
|
# http://stackoverflow.com/questions/4175733/convert-duration-to-hoursminutesseconds-or-similar-in-rails-3-or-ruby
|
|
71
55
|
def pretty_time(total_seconds)
|
|
72
56
|
minutes = (total_seconds / 60) % 60
|
data/lib/lono/sequence.rb
CHANGED
|
@@ -6,27 +6,30 @@ require 'bundler'
|
|
|
6
6
|
class Lono::Sequence < Thor::Group
|
|
7
7
|
include Thor::Actions
|
|
8
8
|
|
|
9
|
-
def self.template_name
|
|
10
|
-
ENV['TEMPLATE'] || 'skeleton'
|
|
11
|
-
end
|
|
12
|
-
|
|
13
9
|
def self.source_root
|
|
14
|
-
|
|
15
|
-
template_folder = "#{starter_projects}/#{template_name}"
|
|
16
|
-
unless File.exist?(template_folder)
|
|
17
|
-
templates = Dir.glob("#{starter_projects}/*")
|
|
18
|
-
.select { |f| File.directory?(f) }
|
|
19
|
-
.map { |f| " #{File.basename(f)}" }
|
|
20
|
-
.sort
|
|
21
|
-
puts "The TEMPLATE=#{ENV['TEMPLATE']} you specified does not exist.".color(:red)
|
|
22
|
-
puts "The available templates are:\n#{templates.join("\n")}"
|
|
23
|
-
exit
|
|
24
|
-
end
|
|
25
|
-
template_folder
|
|
10
|
+
File.expand_path("../templates/skeleton", File.dirname(__FILE__))
|
|
26
11
|
end
|
|
27
12
|
|
|
28
13
|
private
|
|
29
14
|
def git_installed?
|
|
30
15
|
system("type git > /dev/null")
|
|
31
16
|
end
|
|
17
|
+
|
|
18
|
+
def run_git?
|
|
19
|
+
options[:git] && git_installed?
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def run_git_init
|
|
23
|
+
return unless run_git?
|
|
24
|
+
puts "=> Initialize git repo"
|
|
25
|
+
run("git init")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def run_git_commit
|
|
29
|
+
return unless run_git?
|
|
30
|
+
|
|
31
|
+
puts "=> Commit git repo"
|
|
32
|
+
run("git add .")
|
|
33
|
+
run("git commit -m 'first commit'")
|
|
34
|
+
end
|
|
32
35
|
end
|
data/lib/lono/setting.rb
CHANGED
|
@@ -12,10 +12,7 @@ module Lono
|
|
|
12
12
|
def data
|
|
13
13
|
return @@data if @@data
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
puts "ERROR: No settings file at #{project_settings_path}. Are you sure you are in a project with lono setup?".color(:red)
|
|
17
|
-
exit 1
|
|
18
|
-
end
|
|
15
|
+
project_settings_path = lookup_project_settings_path
|
|
19
16
|
|
|
20
17
|
# project based settings files
|
|
21
18
|
project = load_file(project_settings_path)
|
|
@@ -31,26 +28,25 @@ module Lono
|
|
|
31
28
|
@@data = all_envs[Lono.env] || all_envs["base"] || {}
|
|
32
29
|
end
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
31
|
+
def lookup_project_settings_path
|
|
32
|
+
standalone_path = "#{Lono.root}/config/settings.yml"
|
|
33
|
+
multimode_path = "#{Lono.root}/configs/settings.yml"
|
|
34
|
+
parent_multimode_path = "#{Lono.root}/../../configs/settings.yml"
|
|
35
|
+
|
|
36
|
+
settings_path = if File.exist?(standalone_path)
|
|
37
|
+
standalone_path
|
|
38
|
+
elsif File.exist?(multimode_path)
|
|
39
|
+
multimode_path
|
|
40
|
+
elsif File.exist?(parent_multimode_path)
|
|
41
|
+
parent_multimode_path
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
if @check_lono_project && !settings_path
|
|
45
|
+
puts "ERROR: No lono settings file found. Are you sure you are in a project with lono setup?".color(:red)
|
|
46
|
+
exit 1
|
|
47
|
+
end
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
s3_folder[ENV['AWS_PROFILE']] || s3_folder["default"]
|
|
49
|
+
settings_path
|
|
54
50
|
end
|
|
55
51
|
|
|
56
52
|
private
|
|
@@ -75,9 +71,5 @@ module Lono
|
|
|
75
71
|
end
|
|
76
72
|
all_envs
|
|
77
73
|
end
|
|
78
|
-
|
|
79
|
-
def project_settings_path
|
|
80
|
-
"#{Lono.root}/config/settings.yml"
|
|
81
|
-
end
|
|
82
74
|
end
|
|
83
75
|
end
|
data/lib/lono/template.rb
CHANGED
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
require "thor"
|
|
2
2
|
require_relative "command"
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
autoload :DSL, 'lono/template/dsl'
|
|
9
|
-
autoload :Template, 'lono/template/template'
|
|
10
|
-
autoload :Upload, 'lono/template/upload'
|
|
11
|
-
autoload :AwsService, 'lono/template/aws_service'
|
|
4
|
+
module Lono
|
|
5
|
+
class Template < Lono::Command
|
|
6
|
+
class_option :quiet, type: :boolean, desc: "silence the output"
|
|
7
|
+
class_option :noop, type: :boolean, desc: "noop mode, do nothing destructive"
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
desc "generate", "Generate the CloudFormation templates"
|
|
10
|
+
long_desc Lono::Help.text("template/generate")
|
|
11
|
+
option :clean, type: :boolean, desc: "remove all output files before generating"
|
|
12
|
+
def generate(blueprint=nil)
|
|
13
|
+
Blueprint::Find.one_or_all(blueprint).each do |b|
|
|
14
|
+
Generator.new(b, options).run
|
|
15
|
+
end
|
|
16
|
+
end
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
DSL.new(options.clone).run
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
desc "upload", "Uploads templates to configured s3 folder"
|
|
24
|
-
def upload
|
|
25
|
-
Upload.new(options.clone).run
|
|
26
|
-
end
|
|
18
|
+
desc "upload", "Uploads templates to configured s3 folder"
|
|
19
|
+
def upload(blueprint)
|
|
20
|
+
Upload.new(blueprint, options.clone).run
|
|
21
|
+
end
|
|
27
22
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
desc "bashify URL-OR-PATH", "Convert the UserData section of an existing CloudFormation Template to a starter bash script that is compatiable with lono"
|
|
24
|
+
long_desc Lono::Help.text("template/bashify")
|
|
25
|
+
def bashify(path)
|
|
26
|
+
Bashify.new(path: path).run
|
|
27
|
+
end
|
|
32
28
|
end
|
|
33
|
-
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class Lono::Template
|
|
2
|
+
class Base
|
|
3
|
+
include Lono::Blueprint::Root
|
|
4
|
+
|
|
5
|
+
def initialize(blueprint, options={})
|
|
6
|
+
@blueprint, @options = blueprint, options
|
|
7
|
+
@template = @options[:template] || @blueprint
|
|
8
|
+
Lono::ProjectChecker.check
|
|
9
|
+
set_blueprint_root(@blueprint)
|
|
10
|
+
Lono::ProjectChecker.empty_templates
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# Encapsulates helper methods and instance variables to be rendered in the ERB
|
|
2
|
-
# templates.
|
|
1
|
+
# Encapsulates helper methods and instance variables to be rendered in the ERB templates.
|
|
3
2
|
class Lono::Template
|
|
4
3
|
class Context
|
|
5
4
|
include Lono::Template::Helper
|
|
5
|
+
include Loader
|
|
6
6
|
|
|
7
|
-
def initialize(options={})
|
|
8
|
-
@options = options
|
|
7
|
+
def initialize(blueprint, options={})
|
|
8
|
+
@blueprint, @options = blueprint, options
|
|
9
9
|
load_variables
|
|
10
10
|
load_project_helpers
|
|
11
11
|
end
|
|
@@ -17,57 +17,5 @@ class Lono::Template
|
|
|
17
17
|
instance_variable_set('@' + key.to_s, value)
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
|
-
|
|
21
|
-
private
|
|
22
|
-
# Variables in base.rb are overridden by their environment specific variables
|
|
23
|
-
# file. Example, file LONO_ENV=development:
|
|
24
|
-
#
|
|
25
|
-
# config/variables/base.rb
|
|
26
|
-
# config/variables/development.rb - will override any variables in base.rb
|
|
27
|
-
#
|
|
28
|
-
def load_variables
|
|
29
|
-
load_variables_file("base")
|
|
30
|
-
load_variables_file(Lono.env)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Load custom helper methods from project
|
|
34
|
-
def load_project_helpers
|
|
35
|
-
Dir.glob("#{Lono.config.helpers_path}/**/*_helper.rb").each do |path|
|
|
36
|
-
filename = path.sub(%r{.*/},'').sub('.rb','')
|
|
37
|
-
module_name = filename.classify
|
|
38
|
-
|
|
39
|
-
# Prepend a period so require works LONO_ROOT is set to a relative path
|
|
40
|
-
# without a period.
|
|
41
|
-
#
|
|
42
|
-
# Example: LONO_ROOT=tmp/lono_project
|
|
43
|
-
first_char = path[0..0]
|
|
44
|
-
path = "./#{path}" unless %w[. /].include?(first_char)
|
|
45
|
-
require path
|
|
46
|
-
self.class.send :include, module_name.constantize
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Load the variables defined in config/variables/* to make available in the
|
|
51
|
-
# template blocks in config/templates/*.
|
|
52
|
-
#
|
|
53
|
-
# Example:
|
|
54
|
-
#
|
|
55
|
-
# `config/variables/base.rb`:
|
|
56
|
-
# @foo = 123
|
|
57
|
-
#
|
|
58
|
-
# `app/definitions/base.rb`:
|
|
59
|
-
# template "mytemplate.yml" do
|
|
60
|
-
# source "mytemplate.yml.erb"
|
|
61
|
-
# variables(foo: @foo)
|
|
62
|
-
# end
|
|
63
|
-
#
|
|
64
|
-
# NOTE: Only able to make instance variables avaialble with instance_eval,
|
|
65
|
-
# wasnt able to make local variables available.
|
|
66
|
-
def load_variables_file(name)
|
|
67
|
-
path = "#{Lono.config.variables_path}/#{name}.rb"
|
|
68
|
-
return unless File.exist?(path)
|
|
69
|
-
|
|
70
|
-
instance_eval(IO.read(path))
|
|
71
|
-
end
|
|
72
20
|
end
|
|
73
21
|
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
class Lono::Template::Context
|
|
2
|
+
module Loader
|
|
3
|
+
private
|
|
4
|
+
# Variables in base.rb are overridden by their environment specific variables
|
|
5
|
+
# file. Example, file LONO_ENV=development:
|
|
6
|
+
#
|
|
7
|
+
# config/variables/base.rb
|
|
8
|
+
# config/variables/development.rb - will override any variables in base.rb
|
|
9
|
+
#
|
|
10
|
+
def load_variables
|
|
11
|
+
load_variables_file(blueprint_path("base"))
|
|
12
|
+
load_variables_file(blueprint_path(Lono.env))
|
|
13
|
+
load_variables_file(project_path("base"))
|
|
14
|
+
load_variables_file(project_path(Lono.env))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def blueprint_path(name)
|
|
18
|
+
"#{Lono.blueprint_root}/config/variables/#{name}.rb"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def project_path(name)
|
|
22
|
+
"#{Lono.root}/configs/#{@blueprint}/variables/#{name}.rb"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Load the variables defined in config/variables/* to make available in the
|
|
26
|
+
# template blocks in config/templates/*.
|
|
27
|
+
#
|
|
28
|
+
# Example:
|
|
29
|
+
#
|
|
30
|
+
# `config/variables/base.rb`:
|
|
31
|
+
# @foo = 123
|
|
32
|
+
#
|
|
33
|
+
# `app/definitions/base.rb`:
|
|
34
|
+
# template "mytemplate.yml" do
|
|
35
|
+
# source "mytemplate.yml.erb"
|
|
36
|
+
# variables(foo: @foo)
|
|
37
|
+
# end
|
|
38
|
+
#
|
|
39
|
+
# NOTE: Only able to make instance variables avaialble with instance_eval,
|
|
40
|
+
# wasnt able to make local variables available.
|
|
41
|
+
def load_variables_file(path)
|
|
42
|
+
# if File.exist?(path)
|
|
43
|
+
# puts "context.rb loading #{path}"
|
|
44
|
+
# else
|
|
45
|
+
# puts "context.rb file doesnt exist #{path}"
|
|
46
|
+
# end
|
|
47
|
+
|
|
48
|
+
return unless File.exist?(path)
|
|
49
|
+
|
|
50
|
+
instance_eval(IO.read(path), path)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Load custom helper methods from project
|
|
54
|
+
def load_project_helpers
|
|
55
|
+
Dir.glob("#{Lono.config.helpers_path}/**/*_helper.rb").each do |path|
|
|
56
|
+
filename = path.sub(%r{.*/},'').sub('.rb','')
|
|
57
|
+
module_name = filename.classify
|
|
58
|
+
|
|
59
|
+
# Prepend a period so require works LONO_ROOT is set to a relative path
|
|
60
|
+
# without a period.
|
|
61
|
+
#
|
|
62
|
+
# Example: LONO_ROOT=tmp/lono_project
|
|
63
|
+
first_char = path[0..0]
|
|
64
|
+
path = "./#{path}" unless %w[. /].include?(first_char)
|
|
65
|
+
require path
|
|
66
|
+
self.class.send :include, module_name.constantize
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
data/lib/lono/template/dsl.rb
CHANGED
|
@@ -1,157 +1,21 @@
|
|
|
1
|
-
class Lono::Template
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
write_output
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# Instance eval's the template declarations in app/definitions in this order:
|
|
17
|
-
#
|
|
18
|
-
# app/definitions/base.rb
|
|
19
|
-
# app/definitions/base - all files in folder
|
|
20
|
-
# app/definitions/[Lono.env].rb
|
|
21
|
-
# app/definitions/[Lono.env] - all files in folder
|
|
22
|
-
#
|
|
23
|
-
# So Lono.env specific template declarations override base template declarations.
|
|
24
|
-
def evaluate_templates
|
|
25
|
-
evaluate_template("base")
|
|
26
|
-
evaluate_folder("base")
|
|
27
|
-
evaluate_template(Lono.env)
|
|
28
|
-
evaluate_folder(Lono.env)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def evaluate_template(name)
|
|
32
|
-
path = "#{Lono.config.definitions_path}/#{name}.rb"
|
|
33
|
-
evaluate_template_path(path)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def evaluate_template_path(path)
|
|
37
|
-
return unless File.exist?(path)
|
|
38
|
-
|
|
39
|
-
begin
|
|
40
|
-
instance_eval(File.read(path), path)
|
|
41
|
-
rescue Exception => e
|
|
42
|
-
template_evaluation_error(e)
|
|
43
|
-
puts "\nFull error:"
|
|
44
|
-
raise
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def evaluate_folder(folder)
|
|
49
|
-
paths = Dir.glob("#{Lono.config.definitions_path}/#{folder}/**/*")
|
|
50
|
-
paths.select{ |e| File.file?(e) }.each do |path|
|
|
51
|
-
evaluate_template_path(path)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
# Prints out a user friendly task_definition error message
|
|
56
|
-
def template_evaluation_error(e)
|
|
57
|
-
error_info = e.backtrace.first
|
|
58
|
-
path, line_no, _ = error_info.split(':')
|
|
59
|
-
line_no = line_no.to_i
|
|
60
|
-
puts "Error evaluating #{path}:".color(:red)
|
|
61
|
-
puts e.message
|
|
62
|
-
puts "Here's the line in #{path} with the error:\n\n"
|
|
63
|
-
|
|
64
|
-
contents = IO.read(path)
|
|
65
|
-
content_lines = contents.split("\n")
|
|
66
|
-
context = 5 # lines of context
|
|
67
|
-
top, bottom = [line_no-context-1, 0].max, line_no+context-1
|
|
68
|
-
spacing = content_lines.size.to_s.size
|
|
69
|
-
content_lines[top..bottom].each_with_index do |line_content, index|
|
|
70
|
-
line_number = top+index+1
|
|
71
|
-
if line_number == line_no
|
|
72
|
-
printf("%#{spacing}d %s\n".color(:red), line_number, line_content)
|
|
73
|
-
else
|
|
74
|
-
printf("%#{spacing}d %s\n", line_number, line_content)
|
|
1
|
+
class Lono::Template
|
|
2
|
+
class Dsl < Base
|
|
3
|
+
attr_reader :results
|
|
4
|
+
def initialize(blueprint, options={})
|
|
5
|
+
super
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def run
|
|
9
|
+
puts "Generating CloudFormation templates for blueprint #{@blueprint.color(:green)}:" unless @options[:quiet]
|
|
10
|
+
paths = Dir.glob("#{Lono.config.templates_path}/**/*.rb")
|
|
11
|
+
paths.select{ |e| File.file?(e) }.each do |path|
|
|
12
|
+
build_template(path)
|
|
75
13
|
end
|
|
76
14
|
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def template(name, &block)
|
|
80
|
-
@templates << {name: name, block: block}
|
|
81
|
-
end
|
|
82
15
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
16
|
+
def build_template(path)
|
|
17
|
+
builder = Builder.new(path, @blueprint, @options)
|
|
18
|
+
builder.build
|
|
86
19
|
end
|
|
87
20
|
end
|
|
88
|
-
|
|
89
|
-
def write_output
|
|
90
|
-
output_path = "#{Lono.config.output_path}/templates"
|
|
91
|
-
FileUtils.rm_rf(output_path) if @options[:clean]
|
|
92
|
-
FileUtils.mkdir_p(output_path)
|
|
93
|
-
puts "Generating CloudFormation templates:" unless @options[:quiet]
|
|
94
|
-
@results.each do |name,text|
|
|
95
|
-
path = "#{output_path}/#{name}".sub(/^\.\//,'') # strip leading '.'
|
|
96
|
-
path += ".yml"
|
|
97
|
-
puts " #{path}" unless @options[:quiet]
|
|
98
|
-
ensure_parent_dir(path)
|
|
99
|
-
text = commented(text)
|
|
100
|
-
IO.write(path, text) # write file first so validate method is simpler
|
|
101
|
-
validate(path)
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def validate(path)
|
|
106
|
-
text = IO.read(path)
|
|
107
|
-
begin
|
|
108
|
-
YAML.load(text)
|
|
109
|
-
rescue Psych::SyntaxError => e
|
|
110
|
-
handle_yaml_syntax_error(e, path)
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
def handle_yaml_syntax_error(e, path)
|
|
115
|
-
io = StringIO.new
|
|
116
|
-
io.puts "Invalid yaml. Output written to debugging: #{path}".color(:red)
|
|
117
|
-
io.puts "ERROR: #{e.message}".color(:red)
|
|
118
|
-
|
|
119
|
-
# Grab line info. Example error:
|
|
120
|
-
# ERROR: (<unknown>): could not find expected ':' while scanning a simple key at line 2 column 1
|
|
121
|
-
md = e.message.match(/at line (\d+) column (\d+)/)
|
|
122
|
-
line = md[1].to_i
|
|
123
|
-
|
|
124
|
-
lines = IO.read(path).split("\n")
|
|
125
|
-
context = 5 # lines of context
|
|
126
|
-
top, bottom = [line-context-1, 0].max, line+context-1
|
|
127
|
-
spacing = lines.size.to_s.size
|
|
128
|
-
lines[top..bottom].each_with_index do |line_content, index|
|
|
129
|
-
line_number = top+index+1
|
|
130
|
-
if line_number == line
|
|
131
|
-
io.printf("%#{spacing}d %s\n".color(:red), line_number, line_content)
|
|
132
|
-
else
|
|
133
|
-
io.printf("%#{spacing}d %s\n", line_number, line_content)
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
if ENV['TEST']
|
|
138
|
-
io.string
|
|
139
|
-
else
|
|
140
|
-
puts io.string
|
|
141
|
-
exit 1
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def commented(text)
|
|
146
|
-
comment =<<~EOS
|
|
147
|
-
# This file was generated with lono. Do not edit directly, the changes will be lost.
|
|
148
|
-
# More info: http://lono.cloud
|
|
149
|
-
EOS
|
|
150
|
-
"#{comment}#{text}"
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def ensure_parent_dir(path)
|
|
154
|
-
dir = File.dirname(path)
|
|
155
|
-
FileUtils.mkdir_p(dir) unless File.exist?(dir)
|
|
156
|
-
end
|
|
157
21
|
end
|