lono 3.4.1 → 3.5.0
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/.circleci/config.yml +2 -10
- data/CHANGELOG.md +6 -0
- data/lib/lono.rb +4 -1
- data/lib/lono/cfn.rb +0 -1
- data/lib/lono/cfn/base.rb +9 -17
- data/lib/lono/cfn/delete.rb +0 -1
- data/lib/lono/clean.rb +1 -2
- data/lib/lono/cli.rb +0 -2
- data/lib/lono/core.rb +24 -0
- data/lib/lono/importer.rb +4 -5
- data/lib/lono/inspector.rb +0 -1
- data/lib/lono/inspector/base.rb +1 -2
- data/lib/lono/param.rb +0 -1
- data/lib/lono/param/generator.rb +10 -12
- data/lib/lono/project_checker.rb +17 -13
- data/lib/lono/settings.rb +3 -7
- data/lib/lono/template.rb +0 -2
- data/lib/lono/template/dsl.rb +8 -14
- data/lib/lono/template/helpers.rb +6 -14
- data/lib/lono/template/template.rb +5 -6
- data/lib/lono/template/upload.rb +8 -7
- data/lib/lono/version.rb +1 -1
- data/spec/fixtures/my_project/config/templates/base/stacks.rb +1 -1
- data/spec/fixtures/my_project/templates/{my-stack.yml.erb → my-stack.yml} +0 -0
- data/spec/lib/lono/cfn_spec.rb +9 -8
- data/spec/lib/lono/inspect_spec.rb +1 -1
- data/spec/lib/lono/new_spec.rb +9 -9
- data/spec/lib/lono/param/generator_spec.rb +4 -1
- data/spec/lib/lono/param_spec.rb +1 -1
- data/spec/lib/lono/template/dsl_spec.rb +16 -17
- data/spec/lib/lono/template_spec.rb +7 -10
- data/spec/lib/lono_spec.rb +7 -3
- data/spec/spec_helper.rb +4 -2
- metadata +5 -5
- data/lib/lono/env.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea871b8860abb2c1fbfc39edeae04a90c43f46780dd8fd4c37a1b97ca6480370
|
4
|
+
data.tar.gz: d52b9f70968c615adb50d16b3c84327b2300123b049a48abfa3affd2e5d6699a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93bff1d68869ca94ba8ddc8014ceef8f403962d3f0f04261a6461c76e5e354fd2780e8c50e0a1cdcdb458ef5820ee2683014249a163b4d13e7a3f2e4afe0483b
|
7
|
+
data.tar.gz: cf812cbf0e9eb23190ddeb615d5d7471bcd19ea31b1094e80ec642ac3b04fa15a2123c8cf43431cf1e8331d41ae3b34e4bbd665167d7fbced8a22c4717a76526
|
data/.circleci/config.yml
CHANGED
@@ -28,7 +28,7 @@ jobs:
|
|
28
28
|
# Download and cache dependencies
|
29
29
|
- restore_cache:
|
30
30
|
keys:
|
31
|
-
- v1-dependencies-{{ checksum "Gemfile
|
31
|
+
- v1-dependencies-{{ checksum "Gemfile" }}
|
32
32
|
# fallback to using the latest cache if no exact match is found
|
33
33
|
- v1-dependencies-
|
34
34
|
|
@@ -40,21 +40,13 @@ jobs:
|
|
40
40
|
- save_cache:
|
41
41
|
paths:
|
42
42
|
- ./vendor/bundle
|
43
|
-
key: v1-dependencies-{{ checksum "Gemfile
|
43
|
+
key: v1-dependencies-{{ checksum "Gemfile" }}
|
44
44
|
|
45
45
|
# run tests!
|
46
46
|
- run:
|
47
47
|
name: run tests
|
48
48
|
command: |
|
49
49
|
mkdir /tmp/test-results
|
50
|
-
|
51
|
-
cat >.rspec <<EOL
|
52
|
-
--format documentation
|
53
|
-
--exclude-pattern spec/fixtures/apps/**/*
|
54
|
-
--format RspecJunitFormatter \
|
55
|
-
--out /tmp/test-results/rspec.xml
|
56
|
-
EOL
|
57
|
-
|
58
50
|
bundle exec rspec
|
59
51
|
|
60
52
|
# collect reports
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,12 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [3.5.0]
|
7
|
+
- Using Lono.root instead of scattered project_root parameters
|
8
|
+
- prefer use of Lono.env over LONO_ENV internally
|
9
|
+
- do not remove blank lines from the generated template, it makes user-data scripts harder to read
|
10
|
+
- remove adding of extra line to partials, causing issues with user data partials
|
11
|
+
|
6
12
|
## [3.4.1]
|
7
13
|
- docs for lono settings
|
8
14
|
|
data/lib/lono.rb
CHANGED
data/lib/lono/cfn.rb
CHANGED
@@ -15,7 +15,6 @@ class Lono::Cfn < Lono::Command
|
|
15
15
|
|
16
16
|
class_option :verbose, type: :boolean
|
17
17
|
class_option :noop, type: :boolean
|
18
|
-
class_option :project_root, desc: "Project folder. Defaults to current directory", default: "."
|
19
18
|
class_option :region, desc: "AWS region"
|
20
19
|
|
21
20
|
# common to create and update
|
data/lib/lono/cfn/base.rb
CHANGED
@@ -9,8 +9,7 @@ class Lono::Cfn::Base
|
|
9
9
|
@randomize_stack_name = options[:randomize_stack_name]
|
10
10
|
@stack_name = randomize(stack_name)
|
11
11
|
@options = options
|
12
|
-
|
13
|
-
Lono::ProjectChecker.check(@project_root) unless options[:lono] # already ran checker in lono generate
|
12
|
+
Lono::ProjectChecker.check unless options[:lono] # already ran checker in lono generate
|
14
13
|
|
15
14
|
@template_name = options[:template] || derandomize(@stack_name)
|
16
15
|
@param_name = options[:param] || @template_name
|
@@ -61,26 +60,19 @@ class Lono::Cfn::Base
|
|
61
60
|
end
|
62
61
|
|
63
62
|
def generate_templates
|
64
|
-
Lono::Template::DSL.new(
|
65
|
-
project_root: @project_root,
|
66
|
-
pretty: true
|
67
|
-
).run
|
63
|
+
Lono::Template::DSL.new(pretty: true).run
|
68
64
|
end
|
69
65
|
|
70
66
|
def upload_templates
|
71
67
|
# only upload templates if s3.path configured in settings
|
72
|
-
settings = Lono::Settings.new
|
68
|
+
settings = Lono::Settings.new
|
73
69
|
return unless settings.s3_path
|
74
70
|
|
75
|
-
Lono::Template::Upload.new(
|
76
|
-
project_root: @project_root,
|
77
|
-
pretty: true
|
78
|
-
).run
|
71
|
+
Lono::Template::Upload.new(pretty: true).run
|
79
72
|
end
|
80
73
|
|
81
74
|
def generate_params(options={})
|
82
75
|
generator_options = {
|
83
|
-
project_root: @project_root,
|
84
76
|
path: @param_path,
|
85
77
|
allow_no_file: true
|
86
78
|
}.merge(options)
|
@@ -111,7 +103,7 @@ class Lono::Cfn::Base
|
|
111
103
|
# @param_path = params/prod/ecs.txt
|
112
104
|
# => output/params/prod/ecs.json
|
113
105
|
output_param_path = @param_path.sub(/\.txt/, '.json')
|
114
|
-
output_param_path = "#{
|
106
|
+
output_param_path = "#{Lono.root}/output/#{output_param_path}"
|
115
107
|
if @options[:param] && !File.exist?(output_param_path)
|
116
108
|
warns << "Parameters file missing: could not find #{output_param_path}"
|
117
109
|
end
|
@@ -136,9 +128,9 @@ class Lono::Cfn::Base
|
|
136
128
|
path = case type
|
137
129
|
when :template
|
138
130
|
format = detect_format
|
139
|
-
"#{
|
131
|
+
"#{Lono.root}/output/#{name}.#{format}"
|
140
132
|
when :param
|
141
|
-
"#{
|
133
|
+
"#{Lono.root}/params/#{Lono.env}/#{name}.txt"
|
142
134
|
else
|
143
135
|
raise "hell: dont come here"
|
144
136
|
end
|
@@ -147,7 +139,7 @@ class Lono::Cfn::Base
|
|
147
139
|
|
148
140
|
# Returns String with value of "yml" or "json".
|
149
141
|
def detect_format
|
150
|
-
formats = Dir.glob("#{
|
142
|
+
formats = Dir.glob("#{Lono.root}/templates/**/*").
|
151
143
|
map { |path| path.sub(/\.erb$/, '') }.
|
152
144
|
map { |path| File.extname(path) }.
|
153
145
|
reject { |s| s.empty? }. # reject ""
|
@@ -210,7 +202,7 @@ class Lono::Cfn::Base
|
|
210
202
|
end
|
211
203
|
|
212
204
|
# otherwise use the settings preference
|
213
|
-
settings = Lono::Settings.new
|
205
|
+
settings = Lono::Settings.new
|
214
206
|
settings.data['randomize_stack_name']
|
215
207
|
end
|
216
208
|
|
data/lib/lono/cfn/delete.rb
CHANGED
data/lib/lono/clean.rb
CHANGED
@@ -4,12 +4,11 @@ class Lono::Clean
|
|
4
4
|
attr_reader :options
|
5
5
|
def initialize(options)
|
6
6
|
@options = options
|
7
|
-
@project_root = options[:project_root] || '.'
|
8
7
|
end
|
9
8
|
|
10
9
|
def run
|
11
10
|
puts "Cleaning up"
|
12
11
|
puts "Removing output/ folder"
|
13
|
-
FileUtils.rm_rf("#{
|
12
|
+
FileUtils.rm_rf("#{Lono.root}/output")
|
14
13
|
end
|
15
14
|
end
|
data/lib/lono/cli.rb
CHANGED
@@ -17,7 +17,6 @@ module Lono
|
|
17
17
|
desc "import [SOURCE]", "Imports raw CloudFormation template and lono-fies it"
|
18
18
|
long_desc Help.import
|
19
19
|
option :format, type: :string, default: "yaml", desc: "format for the final template"
|
20
|
-
option :project_root, default: ".", aliases: "-r", desc: "project root"
|
21
20
|
option :casing, default: "underscore", desc: "camelcase or underscore the template name"
|
22
21
|
option :name, default: nil, desc: "final name of downloaded template without extension"
|
23
22
|
def import(source)
|
@@ -27,7 +26,6 @@ module Lono
|
|
27
26
|
desc "generate", "Generate both CloudFormation templates and parameters files"
|
28
27
|
Help.generate
|
29
28
|
option :clean, type: :boolean, aliases: "-c", desc: "remove all output files before generating"
|
30
|
-
option :project_root, default: ".", aliases: "-r", desc: "project root"
|
31
29
|
option :quiet, type: :boolean, aliases: "-q", desc: "silence the output"
|
32
30
|
option :pretty, type: :boolean, default: true, desc: "json pretty the output. only applies with json format"
|
33
31
|
def generate
|
data/lib/lono/core.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Lono
|
4
|
+
module Core
|
5
|
+
def env
|
6
|
+
LONO_ENV
|
7
|
+
end
|
8
|
+
|
9
|
+
def root
|
10
|
+
path = ENV['LONO_ROOT'] || '.'
|
11
|
+
Pathname.new(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup!
|
15
|
+
settings = Lono::Settings.new.data
|
16
|
+
map = settings['aws_profile_lono_env_map']
|
17
|
+
|
18
|
+
lono_env = map[ENV['AWS_PROFILE']] || map['default'] || 'prod' # defaults to prod
|
19
|
+
lono_env = ENV['LONO_ENV'] if ENV['LONO_ENV'] # highest precedence
|
20
|
+
|
21
|
+
Kernel.const_set(:LONO_ENV, lono_env)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/lono/importer.rb
CHANGED
@@ -8,7 +8,6 @@ class Lono::Importer
|
|
8
8
|
@source = source
|
9
9
|
@options = options
|
10
10
|
@format = normalize_format(@options[:format])
|
11
|
-
@project_root = options[:project_root] || '.'
|
12
11
|
end
|
13
12
|
|
14
13
|
def run
|
@@ -39,7 +38,7 @@ class Lono::Importer
|
|
39
38
|
|
40
39
|
# Add template definition to config/templates/base/stacks.rb.
|
41
40
|
def add_template_definition
|
42
|
-
path = "#{
|
41
|
+
path = "#{Lono.root}/config/templates/base/stacks.rb"
|
43
42
|
lines = File.exist?(path) ? IO.readlines(path) : []
|
44
43
|
new_template_definition = %Q|template "#{template_name}"|
|
45
44
|
unless lines.detect { |l| l.include?(new_template_definition) }
|
@@ -74,12 +73,12 @@ class Lono::Importer
|
|
74
73
|
end
|
75
74
|
|
76
75
|
def params_path
|
77
|
-
"#{
|
76
|
+
"#{Lono.root}/params/base/#{template_name}.txt"
|
78
77
|
end
|
79
78
|
|
80
79
|
|
81
80
|
def template_path
|
82
|
-
"#{
|
81
|
+
"#{Lono.root}/templates/#{template_name}.#{@format}"
|
83
82
|
end
|
84
83
|
|
85
84
|
def template_name
|
@@ -104,7 +103,7 @@ private
|
|
104
103
|
|
105
104
|
def template_data
|
106
105
|
return @template_data if @template_data
|
107
|
-
template_path = "#{
|
106
|
+
template_path = "#{Lono.root}/templates/#{template_name}.#{@format}"
|
108
107
|
@template_data = YAML.load(IO.read(template_path))
|
109
108
|
end
|
110
109
|
|
data/lib/lono/inspector.rb
CHANGED
@@ -8,7 +8,6 @@ class Lono::Inspector < Lono::Command
|
|
8
8
|
|
9
9
|
class_option :verbose, type: :boolean
|
10
10
|
class_option :noop, type: :boolean
|
11
|
-
class_option :project_root, desc: "Project folder. Defaults to current directory", default: "."
|
12
11
|
|
13
12
|
desc "depends STACK", "Prints dependencies tree of CloudFormation template resources"
|
14
13
|
long_desc Help.depends
|
data/lib/lono/inspector/base.rb
CHANGED
@@ -2,7 +2,6 @@ class Lono::Inspector::Base
|
|
2
2
|
def initialize(stack_name, options)
|
3
3
|
@stack_name = stack_name
|
4
4
|
@options = options
|
5
|
-
@project_root = options[:project_root] || '.'
|
6
5
|
end
|
7
6
|
|
8
7
|
def generate_templates
|
@@ -16,7 +15,7 @@ class Lono::Inspector::Base
|
|
16
15
|
|
17
16
|
def data
|
18
17
|
return @data if @data
|
19
|
-
template_path = "#{
|
18
|
+
template_path = "#{Lono.root}/output/#{@stack_name}.yml"
|
20
19
|
check_template_exists(template_path)
|
21
20
|
@data = YAML.load(IO.read(template_path))
|
22
21
|
end
|
data/lib/lono/param.rb
CHANGED
@@ -7,7 +7,6 @@ class Lono::Param < Lono::Command
|
|
7
7
|
class_option :verbose, type: :boolean
|
8
8
|
class_option :noop, type: :boolean
|
9
9
|
class_option :mute, type: :boolean
|
10
|
-
class_option :project_root, desc: "project root to use", default: '.'
|
11
10
|
|
12
11
|
desc "generate", "generate all parameter files to json format"
|
13
12
|
long_desc Help.generate
|
data/lib/lono/param/generator.rb
CHANGED
@@ -3,9 +3,8 @@ class Lono::Param::Generator
|
|
3
3
|
|
4
4
|
def self.generate_all(options)
|
5
5
|
puts "Generating params files"
|
6
|
-
project_root = options[:project_root] || '.'
|
7
6
|
|
8
|
-
params = param_names(
|
7
|
+
params = param_names("base") + param_names(Lono.env)
|
9
8
|
params.uniq.each do |name|
|
10
9
|
param = Lono::Param::Generator.new(name, options)
|
11
10
|
param.generate
|
@@ -18,19 +17,18 @@ class Lono::Param::Generator
|
|
18
17
|
# params/base/a.txt params/base/b.txt params/base/c.txt
|
19
18
|
# Returns:
|
20
19
|
# param_names("base") => ["a", "b", "c"]
|
21
|
-
def self.param_names(
|
22
|
-
base_folder = "#{
|
20
|
+
def self.param_names(folder)
|
21
|
+
base_folder = "#{Lono.root}/params/#{folder}" # Example: "./params/base"
|
23
22
|
Dir.glob("#{base_folder}/**/*.txt").map do |path|
|
24
23
|
path.sub("#{base_folder}/", '').sub('.txt','')
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
27
|
def initialize(name, options)
|
29
|
-
@_name = "#{
|
28
|
+
@_name = "#{Lono.env}/#{name}"
|
30
29
|
@_options = options
|
31
|
-
@
|
32
|
-
@
|
33
|
-
@_base_path = @_env_path.sub("/#{LONO_ENV}/", "/base/")
|
30
|
+
@_env_path = options[:path] || "#{Lono.root}/params/#{@_name}.txt"
|
31
|
+
@_base_path = @_env_path.sub("/#{Lono.env}/", "/base/")
|
34
32
|
end
|
35
33
|
|
36
34
|
def generate
|
@@ -44,7 +42,7 @@ class Lono::Param::Generator
|
|
44
42
|
write_output(json)
|
45
43
|
# Example: @_name = stag/ecs/private
|
46
44
|
# pretty_name = ecs/private
|
47
|
-
pretty_name = @_name.sub("#{
|
45
|
+
pretty_name = @_name.sub("#{Lono.env}/", '')
|
48
46
|
puts "Params file generated for #{pretty_name} at #{output_path}" unless @_options[:mute]
|
49
47
|
else
|
50
48
|
puts "#{@_base_path} or #{@_env_path} could not be found? Are you sure it exist?"
|
@@ -179,7 +177,7 @@ class Lono::Param::Generator
|
|
179
177
|
end
|
180
178
|
|
181
179
|
def output_path
|
182
|
-
"#{
|
180
|
+
"#{Lono.root}/output/params/#{@_name}.json".sub(/\.\//,'')
|
183
181
|
end
|
184
182
|
|
185
183
|
def write_output(json)
|
@@ -191,7 +189,7 @@ class Lono::Param::Generator
|
|
191
189
|
|
192
190
|
def load_variables
|
193
191
|
load_variables_folder("base")
|
194
|
-
load_variables_folder(
|
192
|
+
load_variables_folder(Lono.env)
|
195
193
|
end
|
196
194
|
|
197
195
|
# Load the variables defined in config/variables/* to make available the params/*.txt files
|
@@ -205,7 +203,7 @@ class Lono::Param::Generator
|
|
205
203
|
# AmiId=<%= @ami %>
|
206
204
|
#
|
207
205
|
def load_variables_folder(folder)
|
208
|
-
paths = Dir.glob("#{
|
206
|
+
paths = Dir.glob("#{Lono.root}/config/variables/#{folder}/**/*")
|
209
207
|
paths.select{ |e| File.file? e }.each do |path|
|
210
208
|
instance_eval(IO.read(path))
|
211
209
|
end
|
data/lib/lono/project_checker.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
class Lono::ProjectChecker
|
2
2
|
# Checks to see command is running in a lono project.
|
3
3
|
# If not, provide a friendly message and exit.
|
4
|
-
def self.check
|
5
|
-
new
|
6
|
-
end
|
7
|
-
|
8
|
-
def initialize(project_root)
|
9
|
-
@project_root = project_root
|
4
|
+
def self.check
|
5
|
+
new.check
|
10
6
|
end
|
11
7
|
|
12
8
|
def check
|
@@ -16,26 +12,34 @@ class Lono::ProjectChecker
|
|
16
12
|
end
|
17
13
|
|
18
14
|
def config_folder_exist
|
19
|
-
unless File.exist?("#{
|
15
|
+
unless File.exist?("#{Lono.root}/config")
|
20
16
|
puts "The config folder does not exist in this project. Are you sure this is a lono project?"
|
21
|
-
|
17
|
+
quit
|
22
18
|
end
|
23
19
|
end
|
24
20
|
|
25
21
|
def templates_folder_exist
|
26
|
-
unless File.exist?("#{
|
22
|
+
unless File.exist?("#{Lono.root}/templates")
|
27
23
|
puts "The templates folder does not exist in this project. Are you sure this is a lono project?"
|
28
|
-
|
24
|
+
quit
|
29
25
|
end
|
30
26
|
end
|
31
27
|
|
32
28
|
def empty_folders
|
33
|
-
if Dir["#{
|
29
|
+
if Dir["#{Lono.root}/config/**/*.rb"].empty?
|
34
30
|
puts "The config folder does not contain any lono template definitions."
|
35
|
-
|
31
|
+
quit
|
36
32
|
end
|
37
|
-
if Dir["#{
|
33
|
+
if Dir["#{Lono.root}/templates/**/*"].empty?
|
38
34
|
puts "The templates folder does not contain any lono template definitions."
|
35
|
+
quit
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def quit
|
40
|
+
if ENV['TEST'] == '1'
|
41
|
+
raise("Not in lono project")
|
42
|
+
else
|
39
43
|
exit 1
|
40
44
|
end
|
41
45
|
end
|
data/lib/lono/settings.rb
CHANGED
@@ -1,8 +1,4 @@
|
|
1
1
|
class Lono::Settings
|
2
|
-
def initialize(project_root=nil)
|
3
|
-
@project_root = project_root || '.'
|
4
|
-
end
|
5
|
-
|
6
2
|
# The options from the files get merged with the following precedence:
|
7
3
|
#
|
8
4
|
# current folder - The current folder’s config/settings.yml values take the highest precedence.
|
@@ -13,7 +9,7 @@ class Lono::Settings
|
|
13
9
|
def data
|
14
10
|
return @settings_yaml if @settings_yaml
|
15
11
|
|
16
|
-
project_file = "#{
|
12
|
+
project_file = "#{Lono.root}/config/settings.yml"
|
17
13
|
project = File.exist?(project_file) ? YAML.load_file(project_file) : {}
|
18
14
|
|
19
15
|
user_file = "#{ENV['HOME']}/.lono/settings.yml"
|
@@ -27,7 +23,7 @@ class Lono::Settings
|
|
27
23
|
|
28
24
|
# Examples:
|
29
25
|
#
|
30
|
-
# Using the
|
26
|
+
# Using the Lono.env
|
31
27
|
# s3:
|
32
28
|
# path:
|
33
29
|
# production: s3://infrastructure-prod/cloudformation
|
@@ -44,6 +40,6 @@ class Lono::Settings
|
|
44
40
|
s3_path = s3['path']
|
45
41
|
# s3_path['default'] - key will always exist because of default lono/settings.yml
|
46
42
|
# default value is nil though
|
47
|
-
s3_path[ENV['AWS_PROFILE']] || s3_path[
|
43
|
+
s3_path[ENV['AWS_PROFILE']] || s3_path[Lono.env] || s3_path['default']
|
48
44
|
end
|
49
45
|
end
|
data/lib/lono/template.rb
CHANGED
@@ -16,14 +16,12 @@ class Lono::Template < Lono::Command
|
|
16
16
|
desc "generate", "Generate the CloudFormation templates"
|
17
17
|
Help.generate
|
18
18
|
option :clean, type: :boolean, aliases: "-c", desc: "remove all output files before generating"
|
19
|
-
option :project_root, default: ".", aliases: "-r", desc: "project root"
|
20
19
|
option :pretty, type: :boolean, default: true, desc: "json pretty the output. only applies with json format"
|
21
20
|
def generate
|
22
21
|
DSL.new(options.clone).run
|
23
22
|
end
|
24
23
|
|
25
24
|
desc "upload", "Uploads templates to configured s3 folder"
|
26
|
-
option :project_root, default: ".", aliases: "-r", desc: "project root"
|
27
25
|
def upload
|
28
26
|
Upload.new(options.clone).run
|
29
27
|
end
|
data/lib/lono/template/dsl.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
class Lono::Template::DSL
|
2
2
|
def initialize(options={})
|
3
3
|
@options = options
|
4
|
-
@
|
5
|
-
|
6
|
-
Lono::ProjectChecker.check(@project_root)
|
4
|
+
@config_path = "#{Lono.root}/config"
|
5
|
+
Lono::ProjectChecker.check
|
7
6
|
@templates = []
|
8
7
|
@results = {}
|
9
8
|
@detected_format = nil
|
@@ -16,12 +15,12 @@ class Lono::Template::DSL
|
|
16
15
|
end
|
17
16
|
|
18
17
|
# Instance eval's all the files within each folder under
|
19
|
-
# config/lono/base and config/lono/[
|
20
|
-
# Base gets base first and then the
|
18
|
+
# config/lono/base and config/lono/[Lono.env]
|
19
|
+
# Base gets base first and then the Lono.env configs get evaluate second.
|
21
20
|
# This means the env specific configs override the base configs.
|
22
21
|
def evaluate_templates
|
23
22
|
evaluate_folder("base")
|
24
|
-
evaluate_folder(
|
23
|
+
evaluate_folder(Lono.env)
|
25
24
|
@detected_format = detect_format
|
26
25
|
end
|
27
26
|
|
@@ -70,7 +69,7 @@ class Lono::Template::DSL
|
|
70
69
|
# templates files.
|
71
70
|
# All the templates must be of the same format, either all json or all yaml.
|
72
71
|
def detect_format
|
73
|
-
extensions = Dir.glob("#{
|
72
|
+
extensions = Dir.glob("#{Lono.root}/templates/**/*").map do |path|
|
74
73
|
File.extname(path).sub(/^\./,'')
|
75
74
|
end.reject(&:empty?).uniq
|
76
75
|
extensions.include?('yml') ? 'yml' : 'json' # defaults to yml - falls back to json
|
@@ -88,7 +87,7 @@ class Lono::Template::DSL
|
|
88
87
|
end
|
89
88
|
|
90
89
|
def write_output
|
91
|
-
output_path = "#{
|
90
|
+
output_path = "#{Lono.root}/output"
|
92
91
|
FileUtils.rm_rf(output_path) if @options[:clean]
|
93
92
|
FileUtils.mkdir(output_path) unless File.exist?(output_path)
|
94
93
|
puts "Generating CloudFormation templates:" unless @options[:quiet]
|
@@ -149,12 +148,7 @@ class Lono::Template::DSL
|
|
149
148
|
# This file was generated with lono. Do not edit directly, the changes will be lost.
|
150
149
|
# More info: http://lono.cloud
|
151
150
|
EOS
|
152
|
-
"#{comment}#{
|
153
|
-
end
|
154
|
-
|
155
|
-
# ERB templates leaves blank lines around, remove those lines
|
156
|
-
def remove_blank_lines(text)
|
157
|
-
text.split("\n").reject { |l| l.strip == '' }.join("\n") + "\n"
|
151
|
+
"#{comment}#{text}"
|
158
152
|
end
|
159
153
|
|
160
154
|
def ensure_parent_dir(path)
|
@@ -4,7 +4,7 @@ module Lono::Template::Helpers
|
|
4
4
|
template_path = "#{template_name}.#{format}"
|
5
5
|
|
6
6
|
# must have settings.s3_path for this to owrk
|
7
|
-
settings = Lono::Settings.new
|
7
|
+
settings = Lono::Settings.new
|
8
8
|
if settings.s3_path
|
9
9
|
# high jacking Upload for useful s3_https_url method
|
10
10
|
upload = Lono::Template::Upload.new(@_options)
|
@@ -17,9 +17,8 @@ module Lono::Template::Helpers
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def template_params(param_name)
|
20
|
-
param_path = "params/#{
|
20
|
+
param_path = "params/#{Lono.env}/#{param_name}.txt"
|
21
21
|
generator_options = {
|
22
|
-
project_root: @_project_root,
|
23
22
|
path: param_path,
|
24
23
|
allow_no_file: true
|
25
24
|
}.merge(@_options)
|
@@ -28,8 +27,9 @@ module Lono::Template::Helpers
|
|
28
27
|
generator.params # Returns Array in underscore keys format
|
29
28
|
end
|
30
29
|
|
30
|
+
# Really only useful if using json format
|
31
31
|
def user_data(path, vars={})
|
32
|
-
path = "#{
|
32
|
+
path = "#{Lono.root}/templates/user_data/#{path}"
|
33
33
|
template = IO.read(path)
|
34
34
|
variables(vars)
|
35
35
|
result = erb_result(path, template)
|
@@ -92,15 +92,7 @@ module Lono::Template::Helpers
|
|
92
92
|
variables(vars)
|
93
93
|
result = erb_result(path, template)
|
94
94
|
result = indent(result, options[:indent]) if options[:indent]
|
95
|
-
|
96
|
-
# Add empty line at beginning because empty lines gets stripped during
|
97
|
-
# processing anyway. This allows the user to call partial without having
|
98
|
-
# to put the partial call at very beginning of the line.
|
99
|
-
# This only should happen if user is using indent option.
|
100
|
-
["\n", result].join("\n")
|
101
|
-
else
|
102
|
-
result
|
103
|
-
end
|
95
|
+
result
|
104
96
|
end
|
105
97
|
|
106
98
|
# add indentation
|
@@ -112,7 +104,7 @@ module Lono::Template::Helpers
|
|
112
104
|
|
113
105
|
private
|
114
106
|
def partial_path_for(path)
|
115
|
-
"#{
|
107
|
+
"#{Lono.root}/templates/partial/#{path}"
|
116
108
|
end
|
117
109
|
|
118
110
|
def auto_add_format(path)
|
@@ -15,13 +15,12 @@ class Lono::Template::Template
|
|
15
15
|
@_options = options
|
16
16
|
@_detected_format = options[:detected_format]
|
17
17
|
@_block = block
|
18
|
-
@
|
19
|
-
@_config_path = "#{@_project_root}/config"
|
18
|
+
@_config_path = "#{Lono.root}/config"
|
20
19
|
@_source = default_source(name)
|
21
20
|
end
|
22
21
|
|
23
22
|
def default_source(name)
|
24
|
-
"#{
|
23
|
+
"#{Lono.root}/templates/#{name}.#{@_detected_format}" # defaults to name, source method overrides
|
25
24
|
end
|
26
25
|
|
27
26
|
def build
|
@@ -34,7 +33,7 @@ class Lono::Template::Template
|
|
34
33
|
|
35
34
|
def load_variables
|
36
35
|
load_variables_folder("base")
|
37
|
-
load_variables_folder(
|
36
|
+
load_variables_folder(Lono.env)
|
38
37
|
end
|
39
38
|
|
40
39
|
# Load the variables defined in config/variables/* to make available in the
|
@@ -62,7 +61,7 @@ class Lono::Template::Template
|
|
62
61
|
|
63
62
|
# Load custom helper methods from the user's infra repo
|
64
63
|
def load_custom_helpers
|
65
|
-
Dir.glob("#{
|
64
|
+
Dir.glob("#{Lono.root}/helpers/**/*_helper.rb").each do |path|
|
66
65
|
filename = path.sub(%r{.*/},'').sub('.rb','')
|
67
66
|
module_name = filename.classify
|
68
67
|
|
@@ -72,7 +71,7 @@ class Lono::Template::Template
|
|
72
71
|
end
|
73
72
|
|
74
73
|
def source(path)
|
75
|
-
@_source = path[0..0] == '/' ? path : "#{
|
74
|
+
@_source = path[0..0] == '/' ? path : "#{Lono.root}/templates/#{path}"
|
76
75
|
@_source += ".#{@_detected_format}"
|
77
76
|
end
|
78
77
|
|
data/lib/lono/template/upload.rb
CHANGED
@@ -8,7 +8,6 @@ class Lono::Template::Upload
|
|
8
8
|
|
9
9
|
def initialize(options={})
|
10
10
|
@options = options
|
11
|
-
@project_root = options[:project_root] || '.'
|
12
11
|
@checksums = {}
|
13
12
|
end
|
14
13
|
|
@@ -16,7 +15,7 @@ class Lono::Template::Upload
|
|
16
15
|
ensure_s3_setup!
|
17
16
|
load_checksums!
|
18
17
|
|
19
|
-
paths = Dir.glob("#{
|
18
|
+
paths = Dir.glob("#{Lono.root}/output/**/*")
|
20
19
|
paths.reject { |p| p =~ %r{output/params} }.
|
21
20
|
select { |p| File.file?(p) }.each do |path|
|
22
21
|
upload(path)
|
@@ -36,7 +35,7 @@ class Lono::Template::Upload
|
|
36
35
|
def load_checksums!
|
37
36
|
return if @options[:noop]
|
38
37
|
|
39
|
-
prefix = "#{s3_path}/#{
|
38
|
+
prefix = "#{s3_path}/#{Lono.env}" # s3://s3-bucket-and-path-from-settings/prod
|
40
39
|
resp = s3.list_objects(bucket: s3_bucket, prefix: prefix)
|
41
40
|
resp.contents.each do |object|
|
42
41
|
# key does not include the bucket name
|
@@ -56,7 +55,7 @@ class Lono::Template::Upload
|
|
56
55
|
|
57
56
|
def upload(path)
|
58
57
|
pretty_path = path.sub(/^\.\//, '')
|
59
|
-
key = "#{s3_path}/#{
|
58
|
+
key = "#{s3_path}/#{Lono.env}/#{pretty_path.sub(/^output\//,'')}"
|
60
59
|
s3_full_path = "s3://#{s3_bucket}/#{key}"
|
61
60
|
|
62
61
|
local_checksum = Digest::MD5.hexdigest(IO.read(path))
|
@@ -89,25 +88,27 @@ class Lono::Template::Upload
|
|
89
88
|
# first convert the local path to the path format that is stored in @checksums keys
|
90
89
|
# ./output/docker.yml => cloudformation-templates/stag/docker.yml
|
91
90
|
pretty_path = path.sub(/^\.\//, '')
|
92
|
-
key = "#{s3_path}/#{
|
91
|
+
key = "#{s3_path}/#{Lono.env}/#{pretty_path.sub(/^output\//,'')}"
|
93
92
|
@checksums[key]
|
94
93
|
end
|
95
94
|
|
96
95
|
# https://s3.amazonaws.com/mybucket/cloudformation-templates/prod/parent.yml
|
97
96
|
def s3_https_url(template_path)
|
98
97
|
ensure_s3_setup!
|
99
|
-
"https://s3.amazonaws.com/#{s3_bucket}/#{s3_path}/#{
|
98
|
+
"https://s3.amazonaws.com/#{s3_bucket}/#{s3_path}/#{Lono.env}/#{template_path}"
|
100
99
|
end
|
101
100
|
|
102
101
|
# Example:
|
103
102
|
# s3_bucket('s3://mybucket/templates/storage/path') => mybucket
|
104
103
|
def s3_bucket
|
104
|
+
return '' if @options[:noop] # to get spec passing
|
105
105
|
@s3_full_path.sub('s3://','').split('/').first
|
106
106
|
end
|
107
107
|
|
108
108
|
# Example:
|
109
109
|
# s3_bucket('s3://mybucket/templates/storage/path') => templates/storage/path
|
110
110
|
def s3_path
|
111
|
+
return '' if @options[:noop] # to get spec passing
|
111
112
|
@s3_full_path.sub('s3://','').split('/')[1..-1].join('/')
|
112
113
|
end
|
113
114
|
|
@@ -115,7 +116,7 @@ class Lono::Template::Upload
|
|
115
116
|
def ensure_s3_setup!
|
116
117
|
return if @options[:noop]
|
117
118
|
|
118
|
-
settings = Lono::Settings.new
|
119
|
+
settings = Lono::Settings.new
|
119
120
|
if settings.s3_path
|
120
121
|
@s3_full_path = settings.s3_path
|
121
122
|
else
|
data/lib/lono/version.rb
CHANGED
File without changes
|
data/spec/lib/lono/cfn_spec.rb
CHANGED
@@ -1,38 +1,39 @@
|
|
1
|
-
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Lono::Cfn do
|
4
4
|
before(:all) do
|
5
|
-
@
|
5
|
+
@env = "LONO_ROOT=#{ENV['LONO_ROOT']}"
|
6
|
+
@args = "--noop"
|
6
7
|
end
|
7
8
|
|
8
9
|
describe "lono cfn" do
|
9
10
|
it "create stack" do
|
10
|
-
out = execute("bin/lono cfn create my-stack #{@args}")
|
11
|
+
out = execute("#{@env} bin/lono cfn create my-stack #{@args}")
|
11
12
|
expect(out).to include("Creating")
|
12
13
|
end
|
13
14
|
|
14
15
|
it "update stack" do
|
15
|
-
out = execute("bin/lono cfn update my-stack #{@args}")
|
16
|
+
out = execute("#{@env} bin/lono cfn update my-stack #{@args}")
|
16
17
|
expect(out).to include("Updating")
|
17
18
|
end
|
18
19
|
|
19
20
|
it "delete stack" do
|
20
|
-
out = execute("bin/lono cfn delete my-stack #{@args}")
|
21
|
+
out = execute("#{@env} bin/lono cfn delete my-stack #{@args}")
|
21
22
|
expect(out).to include("Deleted")
|
22
23
|
end
|
23
24
|
|
24
25
|
it "preview stack" do
|
25
|
-
out = execute("bin/lono cfn preview my-stack #{@args}")
|
26
|
+
out = execute("#{@env} bin/lono cfn preview my-stack #{@args}")
|
26
27
|
expect(out).to include("CloudFormation preview")
|
27
28
|
end
|
28
29
|
|
29
30
|
it "diff stack" do
|
30
|
-
out = execute("bin/lono cfn diff my-stack #{@args}")
|
31
|
+
out = execute("#{@env} bin/lono cfn diff my-stack #{@args}")
|
31
32
|
expect(out).to include("diff")
|
32
33
|
end
|
33
34
|
|
34
35
|
it "download stack" do
|
35
|
-
out = execute("bin/lono cfn download my-stack #{@args}")
|
36
|
+
out = execute("#{@env} bin/lono cfn download my-stack #{@args}")
|
36
37
|
expect(out).to include("Download")
|
37
38
|
end
|
38
39
|
end
|
data/spec/lib/lono/new_spec.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Lono::New do
|
4
4
|
before(:each) do
|
5
|
-
@
|
5
|
+
@saved_root = ENV['LONO_ROOT']
|
6
|
+
ENV['LONO_ROOT'] = ENV['TMP_LONO_ROOT']
|
6
7
|
end
|
7
8
|
after(:each) do
|
8
|
-
|
9
|
+
ENV['LONO_ROOT'] = @saved_root
|
10
|
+
FileUtils.rm_rf(ENV['TMP_LONO_ROOT']) unless ENV['KEEP_TMP_PROJECT']
|
9
11
|
end
|
10
12
|
|
11
13
|
context "json starter project" do
|
@@ -14,18 +16,17 @@ describe Lono::New do
|
|
14
16
|
force: true,
|
15
17
|
quiet: true,
|
16
18
|
format: 'json',
|
17
|
-
project_root:
|
19
|
+
project_root: ENV['TMP_LONO_ROOT'],
|
18
20
|
)
|
19
21
|
new_project.run
|
20
22
|
end
|
21
23
|
|
22
24
|
it "should be able to lono generate" do
|
23
25
|
dsl = Lono::Template::DSL.new(
|
24
|
-
project_root: @project_root,
|
25
26
|
quiet: true
|
26
27
|
)
|
27
28
|
dsl.run
|
28
|
-
generated = File.exist?("#{
|
29
|
+
generated = File.exist?("#{Lono.root}/output/blog-web.json")
|
29
30
|
expect(generated).to be true
|
30
31
|
end
|
31
32
|
end
|
@@ -36,18 +37,17 @@ describe Lono::New do
|
|
36
37
|
force: true,
|
37
38
|
quiet: true,
|
38
39
|
format: 'yaml',
|
39
|
-
project_root:
|
40
|
+
project_root: ENV['TMP_LONO_ROOT'],
|
40
41
|
)
|
41
42
|
new_project.run
|
42
43
|
end
|
43
44
|
|
44
45
|
it "should be able to lono generate" do
|
45
46
|
dsl = Lono::Template::DSL.new(
|
46
|
-
project_root: @project_root,
|
47
47
|
quiet: true
|
48
48
|
)
|
49
49
|
dsl.run
|
50
|
-
generated = File.exist?("#{
|
50
|
+
generated = File.exist?("#{Lono.root}/output/blog-web.yml")
|
51
51
|
expect(generated).to be true
|
52
52
|
end
|
53
53
|
end
|
@@ -2,11 +2,14 @@ require_relative "../../../spec_helper"
|
|
2
2
|
|
3
3
|
describe Lono::Param::Generator do
|
4
4
|
def generate(project_root)
|
5
|
+
@saved_root = ENV['LONO_ROOT']
|
6
|
+
ENV['LONO_ROOT'] = project_root
|
5
7
|
param = Lono::Param::Generator.new("network",
|
6
|
-
project_root: project_root,
|
7
8
|
mute: true
|
8
9
|
)
|
9
10
|
json = param.generate
|
11
|
+
ENV['LONO_ROOT'] = @saved_root
|
12
|
+
|
10
13
|
data = JSON.load(json)
|
11
14
|
param_value = data.first["ParameterValue"]
|
12
15
|
end
|
data/spec/lib/lono/param_spec.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Lono::Template::DSL do
|
4
4
|
before(:each) do
|
5
|
-
@
|
5
|
+
@saved_root = ENV['LONO_ROOT']
|
6
|
+
ENV['LONO_ROOT'] = ENV['TMP_LONO_ROOT']
|
6
7
|
end
|
7
8
|
after(:each) do
|
8
|
-
|
9
|
+
ENV['LONO_ROOT'] = @saved_root
|
10
|
+
FileUtils.rm_rf(ENV['TMP_LONO_ROOT']) unless ENV['KEEP_TMP_PROJECT']
|
9
11
|
end
|
10
12
|
|
11
13
|
context "json starter project" do
|
@@ -14,14 +16,13 @@ describe Lono::Template::DSL do
|
|
14
16
|
force: true,
|
15
17
|
quiet: true,
|
16
18
|
format: 'json',
|
17
|
-
project_root:
|
19
|
+
project_root: ENV['TMP_LONO_ROOT'],
|
18
20
|
)
|
19
21
|
new_project.run
|
20
22
|
end
|
21
23
|
|
22
24
|
it "json" do
|
23
25
|
dsl = Lono::Template::DSL.new(
|
24
|
-
project_root: @project_root,
|
25
26
|
quiet: true
|
26
27
|
)
|
27
28
|
dsl.evaluate_templates # run the dependent instance_eval and load_subfoler so @templates is assigned
|
@@ -36,14 +37,13 @@ describe Lono::Template::DSL do
|
|
36
37
|
force: true,
|
37
38
|
quiet: true,
|
38
39
|
format: 'yaml',
|
39
|
-
project_root:
|
40
|
+
project_root: ENV['TMP_LONO_ROOT'],
|
40
41
|
)
|
41
42
|
new_project.run
|
42
43
|
end
|
43
44
|
|
44
45
|
it "yaml" do
|
45
46
|
dsl = Lono::Template::DSL.new(
|
46
|
-
project_root: @project_root,
|
47
47
|
quiet: true
|
48
48
|
)
|
49
49
|
dsl.evaluate_templates # run the dependent instance_eval and load_subfoler so @templates is assigned
|
@@ -69,32 +69,31 @@ describe Lono::Template::DSL do
|
|
69
69
|
force: true,
|
70
70
|
quiet: true,
|
71
71
|
format: 'json',
|
72
|
-
project_root:
|
72
|
+
project_root: ENV['TMP_LONO_ROOT'],
|
73
73
|
)
|
74
74
|
new_project.run
|
75
75
|
|
76
76
|
dsl = Lono::Template::DSL.new(
|
77
|
-
project_root: @project_root,
|
78
77
|
quiet: true
|
79
78
|
)
|
80
79
|
dsl.run
|
81
80
|
end
|
82
81
|
|
83
82
|
it "should generate cloudformation template" do
|
84
|
-
raw = IO.read("#{
|
83
|
+
raw = IO.read("#{Lono.root}/output/api-web.json")
|
85
84
|
json = JSON.load(raw)
|
86
85
|
expect(json['Description']).to eq "Api Stack"
|
87
86
|
expect(json['Mappings']['AWSRegionArch2AMI']['us-east-1']['64']).to eq 'ami-123'
|
88
87
|
end
|
89
88
|
|
90
89
|
it "should make trailing options pass to the partial helper available as instance variables" do
|
91
|
-
raw = IO.read("#{
|
90
|
+
raw = IO.read("#{Lono.root}/output/api-web.json")
|
92
91
|
json = JSON.load(raw)
|
93
92
|
expect(json['Resources']['HostRecord']['Properties']['Comment']).to eq 'DNS name for mydomain.com'
|
94
93
|
end
|
95
94
|
|
96
95
|
it "should generate user data with variables" do
|
97
|
-
raw = IO.read("#{
|
96
|
+
raw = IO.read("#{Lono.root}/output/api-redis.json")
|
98
97
|
json = JSON.load(raw)
|
99
98
|
expect(json['Description']).to eq "Api redis"
|
100
99
|
user_data = json['Resources']['server']['Properties']['UserData']['Fn::Base64']['Fn::Join'][1]
|
@@ -102,7 +101,7 @@ describe Lono::Template::DSL do
|
|
102
101
|
end
|
103
102
|
|
104
103
|
it "should include multiple user_data scripts" do
|
105
|
-
raw = IO.read("#{
|
104
|
+
raw = IO.read("#{Lono.root}/output/api-redis.json")
|
106
105
|
json = JSON.load(raw)
|
107
106
|
expect(json['Description']).to eq "Api redis"
|
108
107
|
user_data = json['Resources']['server']['Properties']['UserData']['Fn::Base64']['Fn::Join'][1]
|
@@ -110,7 +109,7 @@ describe Lono::Template::DSL do
|
|
110
109
|
end
|
111
110
|
|
112
111
|
it "should generate db template" do
|
113
|
-
raw = IO.read("#{
|
112
|
+
raw = IO.read("#{Lono.root}/output/api-redis.json")
|
114
113
|
json = JSON.load(raw)
|
115
114
|
expect(json['Description']).to eq "Api redis"
|
116
115
|
user_data = json['Resources']['server']['Properties']['UserData']['Fn::Base64']['Fn::Join'][1]
|
@@ -161,7 +160,7 @@ describe Lono::Template::DSL do
|
|
161
160
|
end
|
162
161
|
|
163
162
|
it "should not transform user_data ruby scripts" do
|
164
|
-
raw = IO.read("#{
|
163
|
+
raw = IO.read("#{Lono.root}/output/api-worker.json")
|
165
164
|
json = JSON.load(raw)
|
166
165
|
user_data = json['Resources']['LaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'][1]
|
167
166
|
expect(user_data).to include(%Q|ec2.tags.create(ec2.instances[my_instance_id], "Name", {value: Facter.hostname})\n|)
|
@@ -169,12 +168,12 @@ describe Lono::Template::DSL do
|
|
169
168
|
end
|
170
169
|
|
171
170
|
it "should create parent folders for parent/db-stack.json" do
|
172
|
-
directory_created = File.exist?("#{
|
171
|
+
directory_created = File.exist?("#{Lono.root}/output/parent")
|
173
172
|
expect(directory_created).to be true
|
174
173
|
end
|
175
174
|
|
176
175
|
it "task should generate CloudFormation templates" do
|
177
|
-
raw = IO.read("#{
|
176
|
+
raw = IO.read("#{Lono.root}/output/api-web.json")
|
178
177
|
json = JSON.load(raw)
|
179
178
|
expect(json['Description']).to eq "Api Stack"
|
180
179
|
expect(json['Mappings']['AWSRegionArch2AMI']['us-east-1']['64']).to eq 'ami-123'
|
@@ -1,17 +1,14 @@
|
|
1
|
-
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Lono do
|
4
4
|
before(:each) do
|
5
|
+
@env = "LONO_ROOT=tmp/foo"
|
5
6
|
lono_bin = File.expand_path("../../../../bin/lono", __FILE__)
|
6
|
-
|
7
|
-
dir = File.dirname(@project_root)
|
8
|
-
name = File.basename(@project_root)
|
9
|
-
FileUtils.mkdir(dir) unless File.exist?(dir)
|
10
|
-
execute("cd #{dir} && #{lono_bin} new #{name} -f -q --format json")
|
7
|
+
execute("cd tmp && #{lono_bin} new foo -f -q --format json")
|
11
8
|
end
|
12
9
|
|
13
10
|
after(:each) do
|
14
|
-
FileUtils.rm_rf(
|
11
|
+
# FileUtils.rm_rf("foo") unless ENV['KEEP_TMP_PROJECT']
|
15
12
|
end
|
16
13
|
|
17
14
|
describe "bashify" do
|
@@ -24,12 +21,12 @@ describe Lono do
|
|
24
21
|
|
25
22
|
describe "cli specs" do
|
26
23
|
it "should generate templates" do
|
27
|
-
out = execute("./bin/lono template generate -c
|
24
|
+
out = execute("#{@env} ./bin/lono template generate -c")
|
28
25
|
expect(out).to match /Generating CloudFormation templates/
|
29
26
|
end
|
30
27
|
|
31
|
-
it "should
|
32
|
-
out = execute("./bin/lono template upload --
|
28
|
+
it "should upload templates" do
|
29
|
+
out = execute("#{@env} ./bin/lono template upload --noop")
|
33
30
|
expect(out).to match /Templates uploaded to s3/
|
34
31
|
end
|
35
32
|
end
|
data/spec/lib/lono_spec.rb
CHANGED
@@ -3,20 +3,24 @@ require_relative "../spec_helper"
|
|
3
3
|
describe Lono do
|
4
4
|
describe "lono" do
|
5
5
|
before(:each) do
|
6
|
-
@
|
6
|
+
@env = "LONO_ROOT=#{ENV['LONO_ROOT']}"
|
7
7
|
end
|
8
8
|
after(:each) do
|
9
9
|
FileUtils.rm_rf("spec/fixtures/my_project/params/base")
|
10
10
|
end
|
11
11
|
|
12
12
|
it "generate should build templates" do
|
13
|
-
out = execute("
|
13
|
+
out = execute("#{@env} bin/lono generate")
|
14
14
|
expect(out).to match /Generating both CloudFormation template and parameter/
|
15
15
|
end
|
16
16
|
|
17
17
|
it "import should download template" do
|
18
|
-
|
18
|
+
path = "spec/fixtures/my_project/config/templates/base/stacks.rb"
|
19
|
+
backup = "spec/fixtures/my_project/config/templates/base/stacks.rb.bak"
|
20
|
+
FileUtils.cp(path, backup)
|
21
|
+
out = execute("#{@env} bin/lono import spec/fixtures/raw_templates/aws-waf-security-automations.template #{@args}")
|
19
22
|
expect(out).to match /Imported raw CloudFormation template/
|
23
|
+
FileUtils.mv(backup, path)
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
ENV['TEST'] = '1'
|
2
2
|
# Ensures aws api never called. Fixture home folder does not contain ~/.aws/credentails
|
3
3
|
ENV['HOME'] = "spec/fixtures/home"
|
4
|
+
ENV['LONO_ROOT'] = "spec/fixtures/my_project" # this gets kept
|
5
|
+
ENV['TMP_LONO_ROOT'] = "./tmp/lono_project" # need the period for the load_custom_helpers require , unsure if I should adjust the LOAD_PATH
|
4
6
|
|
5
7
|
require "pp"
|
6
8
|
require "byebug"
|
@@ -12,8 +14,8 @@ $root = File.expand_path('../../', __FILE__)
|
|
12
14
|
|
13
15
|
require "#{$root}/lib/lono"
|
14
16
|
|
15
|
-
require 'coveralls'
|
16
|
-
Coveralls.wear!
|
17
|
+
# require 'coveralls'
|
18
|
+
# Coveralls.wear!
|
17
19
|
|
18
20
|
module Helpers
|
19
21
|
def execute(cmd)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lono
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -285,9 +285,9 @@ files:
|
|
285
285
|
- lib/lono/clean.rb
|
286
286
|
- lib/lono/cli.rb
|
287
287
|
- lib/lono/command.rb
|
288
|
+
- lib/lono/core.rb
|
288
289
|
- lib/lono/current_region.rb
|
289
290
|
- lib/lono/default/settings.yml
|
290
|
-
- lib/lono/env.rb
|
291
291
|
- lib/lono/help.rb
|
292
292
|
- lib/lono/importer.rb
|
293
293
|
- lib/lono/inspector.rb
|
@@ -350,7 +350,7 @@ files:
|
|
350
350
|
- spec/fixtures/my_project/config/templates/base/stacks.rb
|
351
351
|
- spec/fixtures/my_project/params/my-stack.txt
|
352
352
|
- spec/fixtures/my_project/templates/.gitkeep
|
353
|
-
- spec/fixtures/my_project/templates/my-stack.yml
|
353
|
+
- spec/fixtures/my_project/templates/my-stack.yml
|
354
354
|
- spec/fixtures/params/baseonly/params/base/network.txt
|
355
355
|
- spec/fixtures/params/envonly/params/prod/network.txt
|
356
356
|
- spec/fixtures/params/overlay/params/base/network.txt
|
@@ -409,7 +409,7 @@ test_files:
|
|
409
409
|
- spec/fixtures/my_project/config/templates/base/stacks.rb
|
410
410
|
- spec/fixtures/my_project/params/my-stack.txt
|
411
411
|
- spec/fixtures/my_project/templates/.gitkeep
|
412
|
-
- spec/fixtures/my_project/templates/my-stack.yml
|
412
|
+
- spec/fixtures/my_project/templates/my-stack.yml
|
413
413
|
- spec/fixtures/params/baseonly/params/base/network.txt
|
414
414
|
- spec/fixtures/params/envonly/params/prod/network.txt
|
415
415
|
- spec/fixtures/params/overlay/params/base/network.txt
|
data/lib/lono/env.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
class Lono::Env
|
2
|
-
def self.setup!(project_root='.')
|
3
|
-
settings = Lono::Settings.new(project_root).data
|
4
|
-
map = settings['aws_profile_lono_env_map']
|
5
|
-
|
6
|
-
lono_env = map[ENV['AWS_PROFILE']] || map['default'] || 'prod' # defaults to prod
|
7
|
-
lono_env = ENV['LONO_ENV'] if ENV['LONO_ENV'] # highest precedence
|
8
|
-
|
9
|
-
Kernel.const_set(:LONO_ENV, lono_env)
|
10
|
-
end
|
11
|
-
end
|