lono 3.5.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +15 -4
  3. data/.rspec +1 -0
  4. data/CHANGELOG.md +15 -1
  5. data/Gemfile +3 -3
  6. data/Guardfile +17 -8
  7. data/{LICENSE → LICENSE.txt} +1 -1
  8. data/README.md +20 -12
  9. data/Rakefile +1 -2
  10. data/{bin → exe}/lono +1 -0
  11. data/lib/lono.rb +12 -9
  12. data/lib/lono/cfn.rb +7 -9
  13. data/lib/lono/cfn/{aws_services.rb → aws_service.rb} +1 -1
  14. data/lib/lono/cfn/base.rb +41 -38
  15. data/lib/lono/cfn/create.rb +6 -2
  16. data/lib/lono/cfn/delete.rb +2 -2
  17. data/lib/lono/cfn/diff.rb +1 -1
  18. data/lib/lono/cfn/preview.rb +26 -15
  19. data/lib/lono/cfn/update.rb +11 -9
  20. data/lib/lono/cfn/util.rb +3 -3
  21. data/lib/lono/clean.rb +1 -1
  22. data/lib/lono/cli.rb +71 -39
  23. data/lib/lono/command.rb +42 -18
  24. data/lib/lono/completer.rb +162 -0
  25. data/lib/lono/completer/script.rb +6 -0
  26. data/lib/lono/completer/script.sh +10 -0
  27. data/lib/lono/completion.rb +15 -0
  28. data/lib/lono/core.rb +23 -9
  29. data/lib/lono/core/config.rb +20 -0
  30. data/lib/lono/default/settings.yml +33 -13
  31. data/lib/lono/help.rb +6 -79
  32. data/lib/lono/help/cfn.md +6 -0
  33. data/lib/lono/help/cfn/create.md +22 -0
  34. data/lib/lono/help/cfn/delete.md +5 -0
  35. data/lib/lono/help/cfn/diff.md +5 -0
  36. data/lib/lono/help/cfn/download.md +5 -0
  37. data/lib/lono/help/cfn/preview.md +11 -0
  38. data/lib/lono/help/cfn/update.md +21 -0
  39. data/lib/lono/help/completion.md +22 -0
  40. data/lib/lono/help/completion_script.md +3 -0
  41. data/lib/lono/help/generate.md +7 -0
  42. data/lib/lono/help/hello.md +5 -0
  43. data/lib/lono/help/import.md +7 -0
  44. data/lib/lono/help/inspect.md +4 -0
  45. data/lib/lono/help/inspect/depends.md +3 -0
  46. data/lib/lono/help/inspect/summary.md +3 -0
  47. data/lib/lono/help/new.md +8 -0
  48. data/lib/lono/help/param.md +3 -0
  49. data/lib/lono/{param/help.rb → help/param/generate.md} +1 -9
  50. data/lib/lono/help/script/build.md +5 -0
  51. data/lib/lono/help/script/upload.md +8 -0
  52. data/lib/lono/help/template.md +4 -0
  53. data/lib/lono/help/template/bashify.md +4 -0
  54. data/lib/lono/help/template/generate.md +7 -0
  55. data/lib/lono/help/user_data.md +3 -0
  56. data/lib/lono/importer.rb +43 -20
  57. data/lib/lono/inspector.rb +2 -19
  58. data/lib/lono/inspector/base.rb +2 -2
  59. data/lib/lono/inspector/{depends.rb → graph.rb} +3 -3
  60. data/lib/lono/inspector/summary.rb +1 -1
  61. data/lib/lono/new.rb +79 -26
  62. data/lib/lono/new/helper.rb +16 -0
  63. data/lib/lono/new/message.rb +35 -0
  64. data/lib/lono/param.rb +1 -2
  65. data/lib/lono/param/generator.rb +34 -86
  66. data/lib/lono/project_checker.rb +35 -40
  67. data/lib/lono/script.rb +19 -0
  68. data/lib/lono/script/base.rb +9 -0
  69. data/lib/lono/script/build.rb +73 -0
  70. data/lib/lono/script/upload.rb +81 -0
  71. data/lib/lono/sequence.rb +33 -0
  72. data/lib/lono/setting.rb +83 -0
  73. data/lib/lono/template.rb +8 -9
  74. data/lib/lono/template/{aws_services.rb → aws_service.rb} +1 -1
  75. data/lib/lono/template/context.rb +73 -0
  76. data/lib/lono/template/dsl.rb +63 -64
  77. data/lib/lono/template/helper.rb +201 -0
  78. data/lib/lono/template/template.rb +29 -221
  79. data/lib/lono/template/upload.rb +41 -33
  80. data/lib/lono/upgrade4.rb +175 -0
  81. data/lib/lono/user_data.rb +31 -0
  82. data/lib/lono/version.rb +1 -1
  83. data/lib/starter_projects/autoscaling/.gitignore +1 -0
  84. data/lib/starter_projects/{json_project → autoscaling}/Gemfile +0 -0
  85. data/lib/starter_projects/{yaml_project → autoscaling}/Guardfile +0 -0
  86. data/lib/starter_projects/autoscaling/README.md +118 -0
  87. data/lib/starter_projects/autoscaling/app/definitions/base.rb +2 -0
  88. data/lib/starter_projects/autoscaling/app/templates/autoscaling.yml +682 -0
  89. data/lib/starter_projects/autoscaling/config/params/base/autoscaling.txt +6 -0
  90. data/lib/starter_projects/autoscaling/config/settings.yml +33 -0
  91. data/lib/starter_projects/ec2/.gitignore +1 -0
  92. data/lib/starter_projects/{yaml_project → ec2}/Gemfile +0 -0
  93. data/lib/starter_projects/{json_project → ec2}/Guardfile +1 -1
  94. data/lib/starter_projects/ec2/README.md +86 -0
  95. data/lib/starter_projects/ec2/app/definitions/base.rb +2 -0
  96. data/lib/starter_projects/ec2/app/definitions/development.rb +1 -0
  97. data/lib/starter_projects/ec2/app/definitions/production.rb +1 -0
  98. data/lib/starter_projects/{yaml_project → ec2/app}/helpers/my_custom_helper.rb +0 -0
  99. data/lib/starter_projects/{json_project/templates/user_data/app.sh → ec2/app/partials/user_data/bootstrap.sh} +1 -2
  100. data/lib/starter_projects/{yaml_project → ec2/app}/templates/example.yml +0 -0
  101. data/lib/starter_projects/{json_project/params/base/api-web.txt → ec2/config/params/base/example.txt} +0 -0
  102. data/lib/starter_projects/ec2/config/params/development/example.txt +3 -0
  103. data/lib/starter_projects/ec2/config/params/production/example.txt +2 -0
  104. data/lib/starter_projects/ec2/config/settings.yml +33 -0
  105. data/lib/starter_projects/ec2/config/variables/base.rb +3 -0
  106. data/lib/starter_projects/ec2/config/variables/development.rb +2 -0
  107. data/lib/starter_projects/ec2/config/variables/production.rb +2 -0
  108. data/lib/starter_projects/ec2/welcome.txt +8 -0
  109. data/lib/starter_projects/skeleton/.gitignore +1 -0
  110. data/lib/starter_projects/skeleton/Gemfile +3 -0
  111. data/lib/starter_projects/skeleton/Guardfile +12 -0
  112. data/lib/starter_projects/skeleton/README.md +53 -0
  113. data/{spec/fixtures/my_project/templates/.gitkeep → lib/starter_projects/skeleton/app/definitions/base.rb} +0 -0
  114. data/lib/starter_projects/skeleton/config/settings.yml +33 -0
  115. data/lib/starter_projects/skeleton/welcome.txt +7 -0
  116. data/lono.gemspec +12 -10
  117. data/spec/fixtures/lono_project/.gitignore +1 -0
  118. data/spec/fixtures/lono_project/Gemfile +3 -0
  119. data/spec/fixtures/lono_project/Guardfile +12 -0
  120. data/spec/fixtures/lono_project/app/definitions/base.rb +10 -0
  121. data/spec/fixtures/lono_project/app/definitions/base/more.rb +7 -0
  122. data/spec/fixtures/lono_project/app/definitions/development.rb +1 -0
  123. data/spec/fixtures/lono_project/app/definitions/production.rb +1 -0
  124. data/spec/fixtures/lono_project/app/helpers/custom_helper.rb +5 -0
  125. data/spec/fixtures/lono_project/app/partials/security_group.yml +10 -0
  126. data/{lib/starter_projects/yaml_project/templates/partial → spec/fixtures/lono_project/app/partials}/user_data/bootstrap.sh +8 -2
  127. data/spec/fixtures/lono_project/app/templates/example.yml +50 -0
  128. data/{lib/starter_projects/yaml_project/params/base/api-web-prod.txt → spec/fixtures/lono_project/config/params/base/example.txt} +1 -0
  129. data/spec/fixtures/lono_project/config/params/development/example.txt +1 -0
  130. data/spec/fixtures/lono_project/config/params/production/example.txt +1 -0
  131. data/spec/fixtures/lono_project/config/settings.yml +31 -0
  132. data/spec/fixtures/lono_project/config/variables/base.rb +3 -0
  133. data/spec/fixtures/lono_project/config/variables/development.rb +1 -0
  134. data/spec/fixtures/lono_project/config/variables/production.rb +1 -0
  135. data/spec/fixtures/params/envonly/params/{prod → development}/network.txt +0 -0
  136. data/spec/fixtures/params/overlay/params/{prod → development}/network.txt +0 -0
  137. data/spec/fixtures/raw_templates/aws-waf-security-automations.template +2 -2
  138. data/spec/lib/lono/cfn_spec.rb +6 -9
  139. data/spec/lib/lono/cli_spec.rb +44 -0
  140. data/spec/lib/lono/completion_spec.rb +17 -0
  141. data/spec/lib/lono/inspect_spec.rb +6 -15
  142. data/spec/lib/lono/param/generator_spec.rb +45 -26
  143. data/spec/lib/lono/param_spec.rb +1 -3
  144. data/spec/lib/lono/setting_spec.rb +47 -0
  145. data/spec/lib/lono/template/dsl_spec.rb +33 -157
  146. data/spec/lib/lono/template_spec.rb +4 -16
  147. data/spec/spec_helper.rb +45 -14
  148. metadata +168 -82
  149. data/.coveralls.yml +0 -1
  150. data/lib/lono/cfn/help.rb +0 -103
  151. data/lib/lono/current_region.rb +0 -42
  152. data/lib/lono/inspector/help.rb +0 -21
  153. data/lib/lono/settings.rb +0 -45
  154. data/lib/lono/template/help.rb +0 -25
  155. data/lib/lono/template/helpers.rb +0 -136
  156. data/lib/starter_projects/json_project/.gitignore +0 -1
  157. data/lib/starter_projects/json_project/config/templates/base/blog.rb +0 -20
  158. data/lib/starter_projects/json_project/config/templates/base/stacks.rb +0 -58
  159. data/lib/starter_projects/json_project/templates/db.json +0 -212
  160. data/lib/starter_projects/json_project/templates/partial/host_record.json +0 -28
  161. data/lib/starter_projects/json_project/templates/partial/server.json +0 -45
  162. data/lib/starter_projects/json_project/templates/user_data/db.sh +0 -39
  163. data/lib/starter_projects/json_project/templates/user_data/db2.sh +0 -2
  164. data/lib/starter_projects/json_project/templates/user_data/ruby_script.rb +0 -5
  165. data/lib/starter_projects/json_project/templates/web.json +0 -386
  166. data/lib/starter_projects/yaml_project/.gitignore +0 -1
  167. data/lib/starter_projects/yaml_project/config/templates/base/blog.rb +0 -20
  168. data/lib/starter_projects/yaml_project/config/templates/base/stacks.rb +0 -56
  169. data/lib/starter_projects/yaml_project/config/templates/prod/stacks.rb +0 -1
  170. data/lib/starter_projects/yaml_project/config/templates/stag/stacks.rb +0 -1
  171. data/lib/starter_projects/yaml_project/config/variables/base/variables.rb +0 -4
  172. data/lib/starter_projects/yaml_project/config/variables/prod/variables.rb +0 -1
  173. data/lib/starter_projects/yaml_project/config/variables/stag/variables.rb +0 -1
  174. data/lib/starter_projects/yaml_project/params/base/example.txt +0 -2
  175. data/lib/starter_projects/yaml_project/params/prod/example.txt +0 -1
  176. data/lib/starter_projects/yaml_project/params/stag/example.txt +0 -1
  177. data/lib/starter_projects/yaml_project/templates/db.yml +0 -148
  178. data/lib/starter_projects/yaml_project/templates/partial/host_record.yml +0 -14
  179. data/lib/starter_projects/yaml_project/templates/partial/server.yml +0 -59
  180. data/lib/starter_projects/yaml_project/templates/web.yml +0 -206
  181. data/spec/fixtures/my_project/config/templates/base/stacks.rb +0 -3
  182. data/spec/fixtures/my_project/params/my-stack.txt +0 -3
  183. data/spec/fixtures/my_project/templates/my-stack.yml +0 -0
  184. data/spec/lib/lono/new_spec.rb +0 -59
  185. data/spec/lib/lono/template/template_spec.rb +0 -104
  186. data/spec/lib/lono_spec.rb +0 -27
@@ -4,20 +4,20 @@ require 'base64'
4
4
  require 'digest'
5
5
 
6
6
  class Lono::Template::Upload
7
- include Lono::Template::AwsServices
7
+ include Lono::Template::AwsService
8
8
 
9
9
  def initialize(options={})
10
10
  @options = options
11
11
  @checksums = {}
12
+ @prefix = "#{folder_key}/#{Lono.env}/templates" # s3://s3-bucket/folder/developemnt/templates
12
13
  end
13
14
 
14
15
  def run
15
16
  ensure_s3_setup!
16
17
  load_checksums!
17
18
 
18
- paths = Dir.glob("#{Lono.root}/output/**/*")
19
- paths.reject { |p| p =~ %r{output/params} }.
20
- select { |p| File.file?(p) }.each do |path|
19
+ paths = Dir.glob("#{Lono.config.output_path}/templates/**/*")
20
+ paths.select { |p| File.file?(p) }.each do |path|
21
21
  upload(path)
22
22
  end
23
23
  say "Templates uploaded to s3."
@@ -35,12 +35,11 @@ class Lono::Template::Upload
35
35
  def load_checksums!
36
36
  return if @options[:noop]
37
37
 
38
- prefix = "#{s3_path}/#{Lono.env}" # s3://s3-bucket-and-path-from-settings/prod
39
- resp = s3.list_objects(bucket: s3_bucket, prefix: prefix)
38
+ resp = s3.list_objects(bucket: s3_bucket, prefix: @prefix)
40
39
  resp.contents.each do |object|
41
40
  # key does not include the bucket name
42
- # full path = s3://my-bucket/cloudformation-templates/prod/my-template.yml
43
- # key = cloudformation-templates/prod/my-template.yml
41
+ # full path = s3://my-bucket/s3_folder/templates/production/my-template.yml
42
+ # key = s3_folder/templates/production/my-template.yml
44
43
  # etag is the checksum as long as the file is not a multi-part file upload
45
44
  # it has extra double quotes wrapped around it.
46
45
  # etag = "\"9cb437490cee2cc96101baf326e5ca81\""
@@ -55,7 +54,7 @@ class Lono::Template::Upload
55
54
 
56
55
  def upload(path)
57
56
  pretty_path = path.sub(/^\.\//, '')
58
- key = "#{s3_path}/#{Lono.env}/#{pretty_path.sub(/^output\//,'')}"
57
+ key = "#{@prefix}/#{pretty_path.sub(%r{output/templates/},'')}"
59
58
  s3_full_path = "s3://#{s3_bucket}/#{key}"
60
59
 
61
60
  local_checksum = Digest::MD5.hexdigest(IO.read(path))
@@ -73,57 +72,66 @@ class Lono::Template::Upload
73
72
  ) unless @options[:noop]
74
73
 
75
74
  # Example output:
76
- # Uploaded: output/docker.yml to s3://boltops-stag/cloudformation-templates/stag/docker.yml
77
- # Uploaded: output/ecs/private.yml to s3://boltops-stag/cloudformation-templates/stag/ecs/private.yml
75
+ # Uploaded: output/templates/docker.yml to s3://boltops-dev/s3_folder/templates/development/docker.yml
76
+ # Uploaded: output/templates/ecs/private.yml to s3://boltops-dev/s3_folder/templates/development/ecs/private.yml
78
77
  message = "Uploaded: #{pretty_path} to #{s3_full_path}".colorize(:green)
79
78
  message = "NOOP: #{message}" if @options[:noop]
80
79
  say message
81
80
  end
82
81
 
83
- # @checksums map has a key format: cloudformation-templates/stag/docker.yml
82
+ # @checksums map has a key format: s3_folder/templates/development/docker.yml
84
83
  #
85
- # path = ./output/docker.yml
86
- # s3_path = s3://boltops-stag/cloudformation-templates/stag/docker.yml
84
+ # path = ./output/templates/docker.yml
85
+ # s3_folder = s3://boltops-dev/s3_folder/templates/development/docker.yml
87
86
  def remote_checksum(path)
88
87
  # first convert the local path to the path format that is stored in @checksums keys
89
- # ./output/docker.yml => cloudformation-templates/stag/docker.yml
88
+ # ./output/templates/docker.yml => s3_folder/templates/development/docker.yml
90
89
  pretty_path = path.sub(/^\.\//, '')
91
- key = "#{s3_path}/#{Lono.env}/#{pretty_path.sub(/^output\//,'')}"
90
+ key = "#{@prefix}/#{pretty_path.sub(%r{output/templates/},'')}"
92
91
  @checksums[key]
93
92
  end
94
93
 
95
- # https://s3.amazonaws.com/mybucket/cloudformation-templates/prod/parent.yml
94
+ # https://s3.amazonaws.com/mybucket/s3_folder/templates/production/parent.yml
96
95
  def s3_https_url(template_path)
97
96
  ensure_s3_setup!
98
- "https://s3.amazonaws.com/#{s3_bucket}/#{s3_path}/#{Lono.env}/#{template_path}"
97
+ "https://s3.amazonaws.com/#{s3_bucket}/#{@prefix}/#{template_path}"
99
98
  end
100
99
 
100
+ # Parse the s3_folder setting and remove the folder portion to leave the
101
+ # "s3_bucket" portion
101
102
  # Example:
102
- # s3_bucket('s3://mybucket/templates/storage/path') => mybucket
103
+ # s3_bucket('s3://mybucket/templates/storage/path')
104
+ # => mybucket
103
105
  def s3_bucket
104
- return '' if @options[:noop] # to get spec passing
105
- @s3_full_path.sub('s3://','').split('/').first
106
+ return nil if @options[:noop] # to get spec passing
107
+ return nil unless s3_folder
108
+ s3_folder.sub('s3://','').split('/').first
106
109
  end
107
110
 
111
+ # The folder_key is the s3_folder setting with the s3 bucket.
112
+ #
108
113
  # Example:
109
- # s3_bucket('s3://mybucket/templates/storage/path') => templates/storage/path
110
- def s3_path
111
- return '' if @options[:noop] # to get spec passing
112
- @s3_full_path.sub('s3://','').split('/')[1..-1].join('/')
114
+ # s3_bucket('s3://mybucket/templates/storage/path')
115
+ # => templates/storage/path
116
+ def folder_key
117
+ return nil if @options[:noop] # to get spec passing
118
+ return nil unless s3_folder
119
+ s3_folder.sub('s3://','').split('/')[1..-1].join('/')
120
+ end
121
+
122
+ def s3_folder
123
+ settings = Lono::Setting.new
124
+ settings.s3_folder
113
125
  end
114
126
 
115
127
  # nice warning if the s3 path not found
116
128
  def ensure_s3_setup!
117
129
  return if @options[:noop]
130
+ return if s3_folder
118
131
 
119
- settings = Lono::Settings.new
120
- if settings.s3_path
121
- @s3_full_path = settings.s3_path
122
- else
123
- say "Unable to upload templates to s3 because you have not configured the s3.path option in lono settings.yml.".colorize(:red)
124
- say "Please configure settings.yml with s3.path. Refer to http://lono.cloud/docs/settings/ for more help.".colorize(:red)
125
- exit 1
126
- end
132
+ say "Unable to upload templates to s3 because you have not configured the s3_folder option in lono settings.yml.".colorize(:red)
133
+ say "Please configure settings.yml with s3_folder. For more help: http://lono.cloud/docs/settings/".colorize(:red)
134
+ exit 1
127
135
  end
128
136
 
129
137
  def say(message)
@@ -0,0 +1,175 @@
1
+ require 'fileutils'
2
+ require 'yaml'
3
+
4
+ module Lono
5
+ class Upgrade4
6
+ def initialize(options)
7
+ @options = options
8
+ end
9
+
10
+ def run
11
+ checks
12
+ puts "Upgrading structure of your current project to the new lono version 4 project structure"
13
+
14
+ upgrade_settings("config/settings.yml")
15
+ upgrade_settings("#{ENV['HOME']}/.lono/settings.yml")
16
+ add_mandantory_settings
17
+
18
+ FileUtils.mkdir_p("app")
19
+ mv("helpers", "app/helpers")
20
+ mv("params", "config/params")
21
+ mv("config/templates", "app/definitions")
22
+ mv("templates", "app/templates")
23
+ mv("app/templates/partial", "app/partials")
24
+ mv("app/partials/user_data", "app/user_data")
25
+ update_variables
26
+ update_stacks
27
+ update_params
28
+
29
+ puts "Upgrade to lono version 4 complete!"
30
+ end
31
+
32
+ def update_stacks
33
+ update_structure("app/definitions")
34
+ end
35
+
36
+ def update_variables
37
+ update_structure("config/variables")
38
+ end
39
+
40
+ # Takes variable files in the subfolder like config/variables/production/*
41
+ # and combines the into a single file like config/variables/production.rb.
42
+ #
43
+ # config/variables/base/* -> config/variables/base.rb
44
+ # config/variables/development/* -> config/variables/development.rb
45
+ # config/variables/production/* -> config/variables/production.rb
46
+ # app/definitions/base/* -> app/definitions/base.rb
47
+ # app/definitions/development/* -> app/definitions/development.rb
48
+ # app/definitions/production/* -> app/definitions/production.rb
49
+ def update_structure(component_path)
50
+ puts "Updating structure of #{component_path}"
51
+ Dir.glob("#{component_path}/*").each do |path|
52
+ next unless File.directory?(path)
53
+ folder = File.basename(path)
54
+ update_structure_for(component_path, folder)
55
+ end
56
+
57
+ # remove the old folders
58
+ Dir.glob("#{component_path}/*").each do |path|
59
+ next unless File.directory?(path)
60
+ FileUtils.rm_rf(path)
61
+ end
62
+ end
63
+
64
+ # combines the files in the lono_env subfolder into one file
65
+ def update_structure_for(component_path, lono_env)
66
+ code = ""
67
+ Dir.glob("#{component_path}/#{lono_env}/*.rb").each do |path|
68
+ code << IO.read(path)
69
+ code << "\n"
70
+ end
71
+ IO.write("#{component_path}/#{env_map(lono_env)}.rb", code)
72
+ end
73
+
74
+ def update_params
75
+ Dir.glob("config/params/*").each do |path|
76
+ next unless File.directory?(path)
77
+ lono_env = File.basename(path)
78
+ mapped_env = env_map(lono_env)
79
+ if mapped_env != lono_env
80
+ mv("config/params/#{lono_env}", "config/params/#{mapped_env}")
81
+ end
82
+ end
83
+ end
84
+
85
+ # make to the longer full environment names
86
+ def env_map(lono_env)
87
+ map = {
88
+ "prod" => "production",
89
+ "stag" => "staging",
90
+ "dev" => "development",
91
+ }
92
+ map[lono_env] || lono_env
93
+ end
94
+
95
+ def checks
96
+ if File.exist?(Lono.config.definitions_path)
97
+ puts "It looks like you already have a #{Lono.config.definitions_path} folder in your project. This is the new project structure so exiting without updating anything."
98
+ exit
99
+ end
100
+
101
+ old_templates_path = "#{Lono.root}/config/templates"
102
+ if !File.exist?(old_templates_path)
103
+ puts "Could not find a #{old_templates_path} folder in your project. Maybe you want to run lono new to initialize a new lono project instead?"
104
+ exit
105
+ end
106
+ end
107
+
108
+ def upgrade_settings(path)
109
+ return unless File.exist?(path)
110
+
111
+ data = YAML.load_file(path)
112
+ return if data.key?("base") # already in new format
113
+
114
+ new_structure = {}
115
+
116
+ (data["aws_profile_lono_env_map"] || {}).each do |aws_profile, lono_env|
117
+ new_structure[env_map(lono_env)] ||= {}
118
+ new_structure[env_map(lono_env)]["aws_profiles"] ||= []
119
+ new_structure[env_map(lono_env)]["aws_profiles"] << aws_profile
120
+ end
121
+ data.delete("aws_profile_lono_env_map")
122
+
123
+ data = update_s3_setting(data)
124
+
125
+ new_structure["base"] = data
126
+ text = YAML.dump(new_structure)
127
+ IO.write(path, text)
128
+ puts "Upgraded settings: #{path}"
129
+ if path.include?(ENV['HOME'])
130
+ puts "NOTE: Your ~/.lono/settings.yml file was also upgraded to the new format. If you are using lono in other projects those will have to be upgraded also."
131
+ end
132
+ end
133
+
134
+ # accounts for most cases
135
+ def update_s3_setting(data)
136
+ return data unless data["s3"] && data["s3"]["path"]
137
+
138
+ options = data["s3"]["path"]
139
+ if options.is_a?(String)
140
+ data.delete("s3")
141
+ data["s3_folder"] = options
142
+ return data # return early if String
143
+ end
144
+
145
+ # Reach here: dealing with a Hash
146
+ if options.size == 1 and options["default"]
147
+ data["s3_folder"] = options["default"]
148
+ end
149
+
150
+ if options.size > 1
151
+ data["s3_folder"] = {}
152
+ options.each do |key, value|
153
+ data["s3_folder"][key] = value
154
+ end
155
+ end
156
+
157
+ data.delete("s3")
158
+ data
159
+ end
160
+
161
+ # If config/settings.yml does not exist, use the default one.
162
+ def add_mandantory_settings
163
+ return if File.exists?("config/settings.yml")
164
+
165
+ default_settings = File.expand_path("default/settings.yml", File.dirname(__FILE__))
166
+ FileUtils.cp(default_settings, "config/settings.yml")
167
+ end
168
+
169
+ def mv(src, dest)
170
+ return unless File.exist?(src)
171
+ puts "mv #{src} #{dest}"
172
+ FileUtils.mv(src, dest)
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,31 @@
1
+ module Lono
2
+ # This class is not use by lono internally. It is really only meant to be
3
+ # exposed to the lono userdata command so users can debug their generated
4
+ # app/user_data scripts. It is useful for debugging.
5
+ #
6
+ # Normally, the Lono::DSL#run method generates the CloudFormation templates
7
+ # and embeds user-data script into the template.
8
+ class UserData
9
+ def initialize(options)
10
+ @options = options
11
+ @name = options[:name]
12
+ @path = "#{Lono.root}/app/user_data/#{@name}.sh"
13
+ end
14
+
15
+ def generate
16
+ puts "Generating user_data for '#{@name}' at #{@path}"
17
+ if File.exist?(@path)
18
+ puts RenderMePretty.result(@path, context: context)
19
+ else
20
+ puts "ERROR: #{@path} does not exist".colorize(:red)
21
+ exit 1
22
+ end
23
+ end
24
+
25
+ # Context for ERB rendering.
26
+ # This is where we control what references get passed to the ERB rendering.
27
+ def context
28
+ @context ||= Lono::Template::Context.new(@options)
29
+ end
30
+ end
31
+ end
data/lib/lono/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lono
2
- VERSION = "3.5.0"
2
+ VERSION = "4.0.0"
3
3
  end
@@ -0,0 +1 @@
1
+ output
@@ -0,0 +1,118 @@
1
+ # Autoscaling Lono Example
2
+
3
+ ## Usage
4
+
5
+ Create a new project.
6
+
7
+ ```
8
+ TEMPLATE=autoscaling lono new autoscaling
9
+ cd autoscaling
10
+ ```
11
+
12
+ Edit `config/params/base/autoscaling.txt` with your desired parameters. Here are the current contents of `config/params/base/autoscaling.txt`:
13
+
14
+ ```sh
15
+ VpcId=
16
+ Subnets=
17
+ OperatorEMail=
18
+ KeyName=
19
+ #InstanceType= # optional
20
+ #SSHLocation= # optional
21
+ ```
22
+
23
+
24
+ Then launch the stack.
25
+
26
+ ```sh
27
+ lono cfn create autoscaling
28
+ ```
29
+
30
+ ## How This Example Was Originally Built
31
+
32
+ First, generate a skeleton starter lono project.
33
+
34
+ ```sh
35
+ lono new autoscaling
36
+ ```
37
+
38
+ Then import a standard CloudFormation template into lono. The `--name` option is used to name the template `autoscaling`.
39
+
40
+ ```
41
+ $ lono import https://s3-us-west-2.amazonaws.com/cloudformation-templates-us-west-2/AutoScalingMultiAZWithNotifications.template --name autoscaling
42
+ => Imported CloudFormation template and lono-fied it.
43
+ Template definition added to app/definitions/base.rb
44
+ Params file created to config/params/base/autoscaling.txt
45
+ Template downloaded to app/templates/autoscaling.yml
46
+ => CloudFormation Template Summary:
47
+ Parameters:
48
+ Required:
49
+ VpcId (AWS::EC2::VPC::Id)
50
+ Subnets (List<AWS::EC2::Subnet::Id>)
51
+ OperatorEMail (String)
52
+ KeyName (AWS::EC2::KeyPair::KeyName)
53
+ Optional:
54
+ InstanceType (String) Default: t2.small
55
+ SSHLocation (String) Default: 0.0.0.0/0
56
+ Resources:
57
+ 2 AWS::AutoScaling::ScalingPolicy
58
+ 2 AWS::CloudWatch::Alarm
59
+ 1 AWS::AutoScaling::LaunchConfiguration
60
+ 1 AWS::ElasticLoadBalancingV2::LoadBalancer
61
+ 1 AWS::ElasticLoadBalancingV2::Listener
62
+ 1 AWS::ElasticLoadBalancingV2::TargetGroup
63
+ 1 AWS::SNS::Topic
64
+ 1 AWS::EC2::SecurityGroup
65
+ 1 AWS::AutoScaling::AutoScalingGroup
66
+ 9 Total
67
+ Here are contents of the params config/params/base/autoscaling.txt file:
68
+ VpcId=
69
+ Subnets=
70
+ OperatorEMail=
71
+ KeyName=
72
+ #InstanceType= # optional
73
+ #SSHLocation= # optional
74
+ $
75
+ ```
76
+
77
+ The template was imported from [CloudFormation Auto Scaling Samples](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/sample-templates-services-us-west-2.html#w2ab2c23c48c13b7).
78
+
79
+ A starter `config/params/base/autoscaling.txt` was generated with required parameters emptied and optional parameters commented out. Fill in the required parameters.
80
+
81
+ ### Filling in the Parameters
82
+
83
+ You can use the following commands to grab the default VPC and a subnet, and set the values needed for the parameters:
84
+
85
+ ```
86
+ VPC=$(aws ec2 describe-vpcs | jq -r '.Vpcs[] | select(.IsDefault == true) | .VpcId')
87
+ SUBNETS=$(aws ec2 describe-subnets | jq -r '.Subnets[].SubnetId' | tr -s '\n' ',' | sed 's/,*$//g')
88
+ EMAIL=email@domain.com
89
+ KEY_NAME=default
90
+ ```
91
+
92
+ Now update the required parameters:
93
+
94
+ ```
95
+ sed "s/VpcId=/VpcId=$VPC/; s/Subnets=/Subnets=$SUBNETS/; s/OperatorEMail=/OperatorEMail=$EMAIL/; s/KeyName=/KeyName=$KEY_NAME/;" config/params/base/autoscaling.txt > config/params/base/autoscaling.txt.1
96
+ mv config/params/base/autoscaling.txt{.1,}
97
+ ```
98
+
99
+ Now launch the stack:
100
+
101
+ ```
102
+ lono cfn create autoscaling
103
+ ```
104
+
105
+ ## Commands Summarized
106
+
107
+ ```sh
108
+ lono new autoscaling
109
+ cd autoscaling
110
+ lono import https://s3-us-west-2.amazonaws.com/cloudformation-templates-us-west-2/AutoScalingMultiAZWithNotifications.template --name autoscaling
111
+ VPC=$(aws ec2 describe-vpcs | jq -r '.Vpcs[] | select(.IsDefault == true) | .VpcId')
112
+ SUBNETS=$(aws ec2 describe-subnets | jq -r '.Subnets[].SubnetId' | tr -s '\n' ',' | sed 's/,*$//g')
113
+ EMAIL=email@domain.com
114
+ KEY_NAME=default
115
+ sed "s/VpcId=/VpcId=$VPC/; s/Subnets=/Subnets=$SUBNETS/; s/OperatorEMail=/OperatorEMail=$EMAIL/; s/KeyName=/KeyName=$KEY_NAME/;" config/params/base/autoscaling.txt > config/params/base/autoscaling.txt.1
116
+ mv config/params/base/autoscaling.txt{.1,}
117
+ lono cfn create autoscaling --template autoscaling
118
+ ```