lono 1.1.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +3 -0
  3. data/CHANGELOG.md +8 -0
  4. data/README.md +150 -39
  5. data/bin/lono +2 -2
  6. data/circle.yml +4 -0
  7. data/lib/lono.rb +16 -7
  8. data/lib/lono/cfn.rb +64 -0
  9. data/lib/lono/cfn/aws_services.rb +37 -0
  10. data/lib/lono/cfn/base.rb +144 -0
  11. data/lib/lono/cfn/create.rb +34 -0
  12. data/lib/lono/cfn/delete.rb +26 -0
  13. data/lib/lono/cfn/diff.rb +43 -0
  14. data/lib/lono/cfn/help.rb +93 -0
  15. data/lib/lono/cfn/preview.rb +133 -0
  16. data/lib/lono/cfn/update.rb +62 -0
  17. data/lib/lono/cfn/util.rb +21 -0
  18. data/lib/lono/cli.rb +19 -10
  19. data/lib/lono/command.rb +25 -0
  20. data/lib/lono/help.rb +59 -0
  21. data/lib/lono/new.rb +3 -2
  22. data/lib/lono/param.rb +20 -0
  23. data/lib/lono/param/generator.rb +90 -0
  24. data/lib/lono/param/help.rb +15 -0
  25. data/lib/lono/project_checker.rb +44 -0
  26. data/lib/lono/template.rb +22 -248
  27. data/lib/lono/template/bashify.rb +39 -0
  28. data/lib/lono/template/dsl.rb +139 -0
  29. data/lib/lono/template/help.rb +25 -0
  30. data/lib/lono/template/template.rb +251 -0
  31. data/lib/lono/version.rb +1 -1
  32. data/lib/{starter_project_yaml → starter_projects/json_project}/Gemfile +0 -1
  33. data/lib/{starter_project_json → starter_projects/json_project}/Guardfile +0 -0
  34. data/lib/{starter_project_json → starter_projects/json_project}/config/lono.rb +0 -0
  35. data/lib/{starter_project_json → starter_projects/json_project}/config/lono/api.rb +0 -0
  36. data/lib/starter_projects/json_project/params/api-web-prod.txt +20 -0
  37. data/lib/{starter_project_json → starter_projects/json_project}/templates/db.json.erb +0 -0
  38. data/lib/{starter_project_json → starter_projects/json_project}/templates/partial/host_record.json.erb +0 -0
  39. data/lib/{starter_project_json → starter_projects/json_project}/templates/partial/server.json.erb +0 -0
  40. data/lib/{starter_project_json → starter_projects/json_project}/templates/user_data/app.sh.erb +0 -0
  41. data/lib/{starter_project_json → starter_projects/json_project}/templates/user_data/db.sh.erb +0 -0
  42. data/lib/{starter_project_json → starter_projects/json_project}/templates/user_data/db2.sh.erb +0 -0
  43. data/lib/{starter_project_json → starter_projects/json_project}/templates/user_data/ruby_script.rb.erb +0 -0
  44. data/lib/{starter_project_json → starter_projects/json_project}/templates/web.json.erb +0 -0
  45. data/lib/{starter_project_json → starter_projects/yaml_project}/Gemfile +0 -1
  46. data/lib/{starter_project_yaml → starter_projects/yaml_project}/Guardfile +0 -0
  47. data/lib/{starter_project_yaml → starter_projects/yaml_project}/config/lono.rb +0 -0
  48. data/lib/{starter_project_yaml → starter_projects/yaml_project}/config/lono/api.rb +0 -0
  49. data/lib/starter_projects/yaml_project/params/api-web-prod.txt +20 -0
  50. data/lib/{starter_project_yaml → starter_projects/yaml_project}/templates/db.yml.erb +0 -0
  51. data/lib/{starter_project_yaml → starter_projects/yaml_project}/templates/partial/host_record.yml.erb +0 -0
  52. data/lib/{starter_project_yaml → starter_projects/yaml_project}/templates/partial/server.yml.erb +0 -0
  53. data/lib/{starter_project_yaml → starter_projects/yaml_project}/templates/partial/user_data/bootstrap.sh.erb +0 -0
  54. data/lib/{starter_project_yaml → starter_projects/yaml_project}/templates/web.yml.erb +0 -0
  55. data/lono.gemspec +15 -10
  56. data/spec/fixtures/my_project/config/lono.rb +1 -0
  57. data/spec/fixtures/my_project/params/my-stack.txt +3 -0
  58. data/spec/fixtures/my_project/templates/.gitkeep +0 -0
  59. data/spec/fixtures/my_project/templates/my-stack.yml.erb +0 -0
  60. data/spec/lib/lono/cfn_spec.rb +35 -0
  61. data/spec/lib/lono/new_spec.rb +3 -3
  62. data/spec/lib/lono/param_spec.rb +15 -0
  63. data/spec/lib/lono/{dsl_spec.rb → template/dsl_spec.rb} +9 -9
  64. data/spec/lib/lono/template/template_spec.rb +104 -0
  65. data/spec/lib/lono/template_spec.rb +22 -37
  66. data/spec/lib/lono_spec.rb +6 -83
  67. data/vendor/plissken/Gemfile +14 -0
  68. data/vendor/plissken/LICENSE.txt +20 -0
  69. data/vendor/plissken/README.md +46 -0
  70. data/vendor/plissken/Rakefile +56 -0
  71. data/vendor/plissken/VERSION +1 -0
  72. data/vendor/plissken/lib/plissken.rb +1 -0
  73. data/vendor/plissken/lib/plissken/ext/hash/to_snake_keys.rb +45 -0
  74. data/vendor/plissken/plissken.gemspec +61 -0
  75. data/vendor/plissken/spec/lib/to_snake_keys_spec.rb +177 -0
  76. data/vendor/plissken/spec/spec_helper.rb +90 -0
  77. data/vendor/plissken/test/helper.rb +20 -0
  78. data/vendor/plissken/test/plissken/ext/hash/to_snake_keys_test.rb +184 -0
  79. data/vendor/plissken/test/test_plissken.rb +2 -0
  80. metadata +115 -39
  81. data/lib/lono/bashify.rb +0 -41
  82. data/lib/lono/cli/help.rb +0 -37
  83. data/lib/lono/dsl.rb +0 -132
@@ -1,41 +0,0 @@
1
- require 'open-uri'
2
-
3
- module Lono
4
- class Bashify
5
- def initialize(options={})
6
- @options = options
7
- @path = options[:path]
8
- end
9
-
10
- def user_data_paths(data,path="")
11
- paths = []
12
- paths << path
13
- data.each do |key,value|
14
- if value.is_a?(Hash)
15
- paths += user_data_paths(value,"#{path}/#{key}")
16
- else
17
- paths += ["#{path}/#{key}"]
18
- end
19
- end
20
- paths.select {|p| p =~ /UserData/ && p =~ /Fn::Join/ }
21
- end
22
-
23
- def run
24
- raw = open(@path).read
25
- json = JSON.load(raw)
26
- paths = user_data_paths(json)
27
- if paths.empty?
28
- puts "No UserData script found"
29
- return
30
- end
31
- paths.each do |path|
32
- puts "UserData script for #{path}:"
33
- key = path.sub('/','').split("/").map {|x| "['#{x}']"}.join('')
34
- user_data = eval("json#{key}")
35
- delimiter = user_data[0]
36
- script = user_data[1]
37
- puts script.join(delimiter)
38
- end
39
- end
40
- end
41
- end
@@ -1,37 +0,0 @@
1
- module Lono
2
- module Help
3
- def new_long_desc
4
- <<-EOL
5
- Examples:
6
-
7
- $ lono new project
8
-
9
- $ lono new lono
10
- EOL
11
- end
12
-
13
- def generate
14
- <<-EOL
15
- Examples:
16
-
17
- $ lono generate
18
-
19
- $ lono g -c # shortcut
20
-
21
- Builds the cloudformation templates files based on lono project and writes them to the output folder on the filesystem.
22
- EOL
23
- end
24
-
25
- def bashify
26
- <<-EOL
27
- Examples:
28
-
29
- $ lono bashify /path/to/cloudformation-template.json
30
-
31
- $ lono bashify https://s3.amazonaws.com/cloudformation-templates-us-east-1/EC2WebSiteSample.template
32
- EOL
33
- end
34
-
35
- extend self
36
- end
37
- end
@@ -1,132 +0,0 @@
1
- module Lono
2
- class DSL
3
- def initialize(options={})
4
- @options = options
5
- @options[:project_root] ||= '.'
6
- @path = "#{@options[:project_root]}/config/lono.rb"
7
- @templates = []
8
- @results = {}
9
- @detected_format = nil
10
- end
11
-
12
- def run(options={})
13
- evaluate
14
- build
15
- output
16
- end
17
-
18
- def evaluate
19
- instance_eval(File.read(@path), @path)
20
- load_subfolder
21
- @detected_format = detect_format
22
- end
23
-
24
- # Detects the format of the templates. Simply checks the extension of all the
25
- # templates files.
26
- # All the templates must be of the same format, either all json or all yaml.
27
- def detect_format
28
- # @templates contains Array of Hashes. Example:
29
- # [{name: ""blog-web-prod.json", block: ...},
30
- # {name: ""api-web-prod.json", block: ...}]
31
- formats = @templates.map{ |t| File.extname(t[:name]) }.uniq
32
- if formats.size > 1
33
- puts "ERROR: Detected multiple formats: #{formats.join(", ")}".colorize(:red)
34
- puts "All the source values in the template blocks in the config folder must have the same format extension."
35
- exit 1
36
- else
37
- found_format = formats.first
38
- if found_format
39
- detected_format = found_format.sub(/^\./,'')
40
- detected_format = "yaml" if detected_format == "yml"
41
- else # empty templates, no templates defined yet
42
- detected_format = "yaml" # defaults to yaml
43
- end
44
- end
45
- detected_format
46
- end
47
-
48
- # load any templates defined in project/config/lono/*
49
- def load_subfolder
50
- Dir.glob("#{File.dirname(@path)}/lono/**/*").select{ |e| File.file? e }.each do |path|
51
- instance_eval(File.read(path), path)
52
- end
53
- end
54
-
55
- def template(name, &block)
56
- @templates << {name: name, block: block}
57
- end
58
-
59
- def build
60
- @templates.each do |t|
61
- @results[t[:name]] = Template.new(t[:name], t[:block], @options).build
62
- end
63
- end
64
-
65
- def output
66
- output_path = "#{@options[:project_root]}/output"
67
- FileUtils.rm_rf(output_path) if @options[:clean]
68
- FileUtils.mkdir(output_path) unless File.exist?(output_path)
69
- puts "Generating CloudFormation templates:" unless @options[:quiet]
70
- @results.each do |name,text|
71
- path = "#{output_path}/#{name}".sub(/^\.\//,'')
72
- puts " #{path}" unless @options[:quiet]
73
- ensure_parent_dir(path)
74
- validate(text, path)
75
- File.open(path, 'w') do |f|
76
- f.write(output_format(text))
77
- end
78
- end
79
- end
80
-
81
- # TODO: set @detected_format upon DSL.new
82
- def validate(text, path)
83
- if @detected_format == "json"
84
- validate_json(text, path)
85
- else
86
- validate_yaml(text, path)
87
- end
88
- end
89
-
90
- def validate_yaml(yaml, path)
91
- begin
92
- YAML.load(yaml)
93
- rescue Psych::SyntaxError => e
94
- puts "Invalid yaml. Output written to #{path} for debugging".colorize(:red)
95
- puts "ERROR: #{e.message}".colorize(:red)
96
- File.open(path, 'w') {|f| f.write(yaml) }
97
- exit 1
98
- end
99
- end
100
-
101
- def validate_json(json, path)
102
- begin
103
- JSON.parse(json)
104
- rescue JSON::ParserError => e
105
- puts "Invalid json. Output written to #{path} for debugging".colorize(:red)
106
- puts "ERROR: #{e.message}".colorize(:red)
107
- File.open(path, 'w') {|f| f.write(json) }
108
- exit 1
109
- end
110
- end
111
-
112
- def output_format(text)
113
- @options[:pretty] ? prettify(text) : text
114
- end
115
-
116
- # Input text is either yaml or json.
117
- # Do not prettify yaml format because it removes the !Ref like CloudFormation notation
118
- def prettify(text)
119
- @detected_format == "json" ? JSON.pretty_generate(JSON.parse(text)) : remove_blank_lines(text)
120
- end
121
-
122
- # ERB templates leaves blank lines around, remove those lines
123
- def remove_blank_lines(text)
124
- text.split("\n").reject { |l| l.strip == '' }.join("\n") + "\n"
125
- end
126
-
127
- def ensure_parent_dir(path)
128
- dir = File.dirname(path)
129
- FileUtils.mkdir_p(dir) unless File.exist?(dir)
130
- end
131
- end
132
- end