lono 6.1.11 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. checksums.yaml +4 -4
  2. data/.cody/acceptance.sh +19 -3
  3. data/.gitignore +2 -2
  4. data/CHANGELOG.md +16 -1
  5. data/README.md +18 -20
  6. data/Rakefile +1 -0
  7. data/lib/lono.rb +7 -5
  8. data/lib/lono/abstract_base.rb +25 -0
  9. data/lib/lono/api/client.rb +30 -0
  10. data/lib/lono/api/proxy.rb +58 -0
  11. data/lib/lono/api/repos.rb +8 -0
  12. data/lib/lono/api/verify.rb +13 -0
  13. data/lib/lono/app_file/base.rb +4 -11
  14. data/lib/lono/app_file/build.rb +1 -1
  15. data/lib/lono/app_file/upload.rb +1 -4
  16. data/lib/lono/autoloader.rb +3 -1
  17. data/lib/lono/aws_services.rb +9 -9
  18. data/lib/lono/aws_services/helper.rb +14 -0
  19. data/lib/lono/aws_services/{util.rb → stack.rb} +1 -9
  20. data/lib/lono/aws_services/stack_set.rb +41 -0
  21. data/lib/lono/blueprint.rb +2 -2
  22. data/lib/lono/blueprint/configset/loader.rb +7 -0
  23. data/lib/lono/blueprint/helper.rb +8 -2
  24. data/lib/lono/blueprint/meta.rb +4 -12
  25. data/lib/lono/blueprint/new.rb +3 -3
  26. data/lib/lono/blueprint/root.rb +6 -26
  27. data/lib/lono/bundle.rb +54 -0
  28. data/lib/lono/cfn.rb +31 -75
  29. data/lib/lono/cfn/base.rb +39 -136
  30. data/lib/lono/cfn/cancel.rb +14 -9
  31. data/lib/lono/cfn/create.rb +15 -19
  32. data/lib/lono/cfn/delete.rb +9 -9
  33. data/lib/lono/cfn/deploy.rb +4 -4
  34. data/lib/lono/cfn/download.rb +27 -9
  35. data/lib/lono/cfn/opts.rb +80 -0
  36. data/lib/lono/cfn/preview/changeset.rb +23 -23
  37. data/lib/lono/cfn/preview/codediff.rb +5 -6
  38. data/lib/lono/cfn/preview/param.rb +10 -10
  39. data/lib/lono/cfn/rollback.rb +5 -5
  40. data/lib/lono/cfn/status.rb +0 -10
  41. data/lib/lono/cfn/update.rb +22 -27
  42. data/lib/lono/clean.rb +3 -3
  43. data/lib/lono/cli.rb +69 -34
  44. data/lib/lono/code.rb +22 -0
  45. data/lib/lono/command.rb +7 -0
  46. data/lib/lono/config_location.rb +6 -13
  47. data/lib/lono/configset.rb +9 -0
  48. data/lib/lono/configset/combiner.rb +128 -0
  49. data/lib/lono/configset/evaluate_file.rb +8 -0
  50. data/lib/lono/configset/list.rb +67 -0
  51. data/lib/lono/configset/loader.rb +98 -0
  52. data/lib/lono/configset/loader/dsl.rb +9 -0
  53. data/lib/lono/configset/materializer/final.rb +10 -0
  54. data/lib/lono/configset/materializer/gems_builder.rb +81 -0
  55. data/lib/lono/configset/materializer/jade.rb +15 -0
  56. data/lib/lono/configset/materializer/source.rb +54 -0
  57. data/lib/lono/configset/meta.rb +19 -0
  58. data/lib/lono/configset/meta/dsl.rb +12 -0
  59. data/lib/lono/configset/new.rb +84 -0
  60. data/lib/lono/configset/preparer.rb +44 -0
  61. data/lib/lono/configset/register/base.rb +121 -0
  62. data/lib/lono/configset/register/blueprint.rb +16 -0
  63. data/lib/lono/configset/register/dsl.rb +15 -0
  64. data/lib/lono/configset/register/project.rb +12 -0
  65. data/lib/lono/configset/registry.rb +34 -0
  66. data/lib/lono/configset/resolver.rb +42 -0
  67. data/lib/lono/conventions.rb +18 -7
  68. data/lib/lono/core.rb +16 -20
  69. data/lib/lono/default/settings.yml +2 -3
  70. data/lib/lono/ext/bundler.rb +7 -0
  71. data/lib/lono/file_uploader.rb +8 -5
  72. data/lib/lono/finder/base.rb +140 -0
  73. data/lib/lono/finder/blueprint.rb +11 -0
  74. data/lib/lono/finder/blueprint/configset.rb +17 -0
  75. data/lib/lono/finder/configset.rb +11 -0
  76. data/lib/lono/generate.rb +93 -0
  77. data/lib/lono/help/blueprint/new.md +0 -1
  78. data/lib/lono/help/cfn/delete.md +1 -1
  79. data/lib/lono/help/cfn/deploy.md +5 -76
  80. data/lib/lono/help/cfn/status.md +0 -4
  81. data/lib/lono/help/cfn/update.md +1 -1
  82. data/lib/lono/help/code/convert.md +51 -0
  83. data/lib/lono/help/code/import.md +30 -0
  84. data/lib/lono/help/configsets.md +24 -0
  85. data/lib/lono/help/generate.md +4 -4
  86. data/lib/lono/help/new.md +1 -2
  87. data/lib/lono/help/sets/delete.md +8 -0
  88. data/lib/lono/help/sets/deploy.md +76 -0
  89. data/lib/lono/help/sets/instances/delete.md +21 -0
  90. data/lib/lono/help/sets/instances/list.md +14 -0
  91. data/lib/lono/help/sets/instances/status.md +15 -0
  92. data/lib/lono/help/sets/instances/sync.md +88 -0
  93. data/lib/lono/help/sets/status.md +23 -0
  94. data/lib/lono/help/upgrade.md +1 -0
  95. data/lib/lono/importer.rb +22 -0
  96. data/lib/lono/importer/base.rb +59 -0
  97. data/lib/lono/importer/converter.rb +19 -0
  98. data/lib/lono/importer/download.rb +46 -0
  99. data/lib/lono/importer/dsl.rb +36 -0
  100. data/lib/lono/importer/erb.rb +31 -0
  101. data/lib/lono/importer/params.rb +56 -0
  102. data/lib/lono/importer/service/coder.rb +81 -0
  103. data/lib/lono/inspector/base.rb +12 -22
  104. data/lib/lono/inspector/graph.rb +1 -1
  105. data/lib/lono/inspector/summary.rb +41 -17
  106. data/lib/lono/jade.rb +103 -0
  107. data/lib/lono/jade/circular.rb +26 -0
  108. data/lib/lono/jadespec.rb +41 -0
  109. data/lib/lono/new.rb +2 -2
  110. data/lib/lono/opts.rb +43 -0
  111. data/lib/lono/output/template.rb +48 -0
  112. data/lib/lono/param.rb +3 -5
  113. data/lib/lono/param/generator.rb +13 -33
  114. data/lib/lono/pro.rb +15 -0
  115. data/lib/lono/pro/base.rb +16 -0
  116. data/lib/lono/pro/repo.rb +27 -0
  117. data/lib/lono/project_checker.rb +4 -29
  118. data/lib/lono/registration.rb +15 -0
  119. data/lib/lono/registration/base.rb +37 -0
  120. data/lib/lono/registration/check.rb +15 -0
  121. data/lib/lono/registration/temp.rb +60 -0
  122. data/lib/lono/registration/user.rb +54 -0
  123. data/lib/lono/script/base.rb +1 -10
  124. data/lib/lono/script/upload.rb +2 -12
  125. data/lib/lono/seed.rb +2 -11
  126. data/lib/lono/seed/base.rb +55 -110
  127. data/lib/lono/sets.rb +38 -0
  128. data/lib/lono/sets/base.rb +45 -0
  129. data/lib/lono/sets/create.rb +30 -0
  130. data/lib/lono/sets/delete.rb +47 -0
  131. data/lib/lono/sets/deploy.rb +11 -0
  132. data/lib/lono/sets/instances.rb +33 -0
  133. data/lib/lono/sets/instances/base.rb +30 -0
  134. data/lib/lono/sets/instances/delete.rb +69 -0
  135. data/lib/lono/sets/instances/list.rb +13 -0
  136. data/lib/lono/sets/instances/opts.rb +29 -0
  137. data/lib/lono/sets/instances/status.rb +12 -0
  138. data/lib/lono/sets/instances/sync.rb +182 -0
  139. data/lib/lono/sets/list.rb +35 -0
  140. data/lib/lono/sets/opts.rb +18 -0
  141. data/lib/lono/sets/preview/codediff.rb +35 -0
  142. data/lib/lono/sets/preview/param.rb +32 -0
  143. data/lib/lono/sets/status.rb +116 -0
  144. data/lib/lono/sets/status/instance.rb +20 -0
  145. data/lib/lono/sets/status/instance/base.rb +120 -0
  146. data/lib/lono/sets/status/instance/completed.rb +35 -0
  147. data/lib/lono/sets/status/instance/deleted.rb +32 -0
  148. data/lib/lono/sets/status/instance/show.rb +7 -0
  149. data/lib/lono/sets/status/instances.rb +111 -0
  150. data/lib/lono/sets/summarize.rb +20 -0
  151. data/lib/lono/sets/time_spent.rb +11 -0
  152. data/lib/lono/sets/update.rb +81 -0
  153. data/lib/lono/template.rb +5 -7
  154. data/lib/lono/template/configset_injector.rb +50 -0
  155. data/lib/lono/template/context.rb +4 -4
  156. data/lib/lono/template/context/loader.rb +4 -16
  157. data/lib/lono/template/evaluate.rb +2 -1
  158. data/lib/lono/template/generator.rb +17 -15
  159. data/lib/lono/template/helper.rb +7 -7
  160. data/lib/lono/template/post_processor.rb +2 -12
  161. data/lib/lono/template/strategy/base.rb +4 -0
  162. data/lib/lono/template/{dsl.rb → strategy/dsl.rb} +4 -6
  163. data/lib/lono/template/{dsl → strategy/dsl}/builder.rb +11 -15
  164. data/lib/lono/template/{dsl → strategy/dsl}/builder/fn.rb +1 -1
  165. data/lib/lono/template/strategy/dsl/builder/helpers.rb +11 -0
  166. data/lib/lono/template/strategy/dsl/builder/helpers/core_helper.rb +14 -0
  167. data/lib/lono/template/strategy/dsl/builder/helpers/file_helper.rb +48 -0
  168. data/lib/lono/template/strategy/dsl/builder/helpers/lookup_helper.rb +27 -0
  169. data/lib/lono/template/strategy/dsl/builder/helpers/s3_helper.rb +13 -0
  170. data/lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb +39 -0
  171. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/base.rb +6 -17
  172. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/condition.rb +1 -1
  173. data/lib/lono/template/strategy/dsl/builder/section/extensions.rb +9 -0
  174. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/mapping.rb +1 -1
  175. data/lib/lono/template/{dsl/builder/section_methods.rb → strategy/dsl/builder/section/methods.rb} +9 -2
  176. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/output.rb +1 -1
  177. data/lib/lono/template/strategy/dsl/builder/section/parameter.rb +69 -0
  178. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource.rb +1 -1
  179. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource/property_mover.rb +1 -1
  180. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/section.rb +1 -1
  181. data/lib/lono/template/{dsl → strategy/dsl}/builder/squeezer.rb +1 -1
  182. data/lib/lono/template/strategy/dsl/builder/stringify.rb +15 -0
  183. data/lib/lono/template/{dsl → strategy/dsl}/builder/syntax.rb +3 -2
  184. data/lib/lono/template/strategy/dsl/finalizer.rb +12 -0
  185. data/lib/lono/template/strategy/dsl/finalizer/parameter_groups.rb +56 -0
  186. data/lib/lono/template/{erb.rb → strategy/erb.rb} +5 -5
  187. data/lib/lono/template/strategy/source.rb +8 -0
  188. data/lib/lono/template/template.rb +1 -1
  189. data/lib/lono/template/upload.rb +4 -9
  190. data/lib/lono/template/util.rb +0 -40
  191. data/lib/lono/upgrade.rb +12 -10
  192. data/lib/lono/user_data.rb +4 -4
  193. data/lib/lono/utils/pretty_time.rb +14 -0
  194. data/lib/lono/utils/sure.rb +23 -0
  195. data/lib/lono/version.rb +1 -1
  196. data/lib/lono/yamler/loader.rb +52 -0
  197. data/lib/lono/yamler/validator.rb +51 -0
  198. data/lib/templates/blueprint/%blueprint_name%.gemspec.tt +4 -0
  199. data/lib/templates/blueprint/README.md.tt +1 -1
  200. data/lib/templates/blueprint/seed/configs.rb +2 -2
  201. data/lib/templates/blueprint_types/dsl/app/templates/%blueprint_name%.rb +17 -18
  202. data/lib/templates/blueprint_types/erb/app/templates/%blueprint_name%.yml +63 -4
  203. data/lib/templates/configset/%configset_name%.gemspec.tt +41 -0
  204. data/lib/templates/configset/.gitignore +11 -0
  205. data/lib/templates/configset/CHANGELOG.md +7 -0
  206. data/lib/templates/configset/Gemfile +4 -0
  207. data/lib/templates/configset/README.md.tt +3 -0
  208. data/lib/templates/configset/Rakefile.tt +9 -0
  209. data/lib/templates/configset/lib/configset.yml +20 -0
  210. data/lib/templates/skeleton/.gitignore +1 -0
  211. data/lib/templates/skeleton/Gemfile +0 -1
  212. data/lib/templates/skeleton/README.md +4 -4
  213. data/lib/templates/skeleton/configs/settings.yml +1 -1
  214. data/lono.gemspec +1 -4
  215. metadata +146 -79
  216. data/Guardfile +0 -19
  217. data/lib/lono/app_file.rb +0 -5
  218. data/lib/lono/blueprint/find.rb +0 -90
  219. data/lib/lono/blueprint/info.rb +0 -10
  220. data/lib/lono/blueprint/list.rb +0 -14
  221. data/lib/lono/cfn/current.rb +0 -95
  222. data/lib/lono/cfn/preview.rb +0 -4
  223. data/lib/lono/cfn/suffix.rb +0 -67
  224. data/lib/lono/cfn/util.rb +0 -27
  225. data/lib/lono/help/cfn/current.md +0 -18
  226. data/lib/lono/help/upgrade4.md +0 -25
  227. data/lib/lono/inspector.rb +0 -4
  228. data/lib/lono/output_template.rb +0 -35
  229. data/lib/lono/template/base.rb +0 -13
  230. data/lib/lono/template/dsl/builder/helpers.rb +0 -8
  231. data/lib/lono/template/dsl/builder/helpers/core_helper.rb +0 -107
  232. data/lib/lono/template/dsl/builder/helpers/param_helper.rb +0 -61
  233. data/lib/lono/template/dsl/builder/parameter.rb +0 -39
  234. data/lib/lono/upgrade/upgrade4.rb +0 -175
  235. data/lib/lono/upgrade/upgrade42.rb +0 -36
  236. data/lib/lono/upgrade/upgrade5.rb +0 -55
  237. data/lib/templates/blueprint/.meta/config.yml.tt +0 -4
  238. data/lib/templates/skeleton/Guardfile +0 -12
  239. data/lib/templates/upgrade5/blueprints/main/.lono/config.yml +0 -3
  240. data/lib/templates/upgrade5/blueprints/main/.meta/config.yml +0 -3
@@ -1,8 +0,0 @@
1
- # Built-in helpers for the DSL form
2
- class Lono::Template::Dsl::Builder
3
- module Helpers
4
- extend Memoist
5
- include CoreHelper
6
- include ParamHelper
7
- end
8
- end
@@ -1,107 +0,0 @@
1
- module Lono::Template::Dsl::Builder::Helpers
2
- module CoreHelper
3
- extend Memoist
4
-
5
- def tags(list={})
6
- casing = list.delete(:casing) || :camelize
7
- if list.empty?
8
- tag_list(@tags) if @tags # when list is empty, use @tags variable. If not set then return nil
9
- else
10
- tag_list(list, casing: casing)
11
- end
12
- end
13
-
14
- def tag_list(list, casing: :camelize)
15
- raise "tags list cannot be empty" if list == nil
16
-
17
- if list.is_a?(Array)
18
- hash = list.inject({}) do |h,i|
19
- i.symbolize_keys!
20
- h[i[:Key]] = i[:Value]
21
- h
22
- end
23
- return tag_list(hash) # recursive call tag_list to normalized the argument with a Hash
24
- end
25
-
26
- list.map do |k,v|
27
- k = k.to_s
28
- k = case casing
29
- when :camelize
30
- k.camelize
31
- when :underscore
32
- k.underscore
33
- when :dasherize
34
- k.dasherize
35
- else # leave alone
36
- k
37
- end
38
-
39
- {Key: k, Value: v}
40
- end
41
- end
42
-
43
- def dimensions(hash, casing: :camelize)
44
- tag_list(hash, casing: casing).map { |h|
45
- h[:Name] = h.delete(:Key) || h.delete(:key)
46
- h
47
- }
48
- end
49
-
50
- def stack_name
51
- @options[:stack]
52
- end
53
-
54
- def content(path)
55
- render_file(Lono.config.content_path, path)
56
- end
57
-
58
- def user_data(path)
59
- render_file(Lono.config.user_data_path, path)
60
- end
61
-
62
- def user_data_script
63
- return "# @user_data variable not set" unless @user_data
64
-
65
- if File.exist?(@user_data)
66
- IO.read(@user_data)
67
- else
68
- message = "WARN: #{@user_data} not found"
69
- puts message.color(:yellow)
70
- "# #{message}"
71
- end
72
- end
73
-
74
- def render_file(folder, path)
75
- path = "#{folder}/#{path}"
76
- if File.exist?(path)
77
- render_path(path)
78
- else
79
- message = "WARNING: path #{path} not found"
80
- puts message.color(:yellow)
81
- puts "Called from:"
82
- puts caller[2]
83
- message
84
- end
85
- end
86
- memoize :render_file
87
-
88
- def render_path(path)
89
- RenderMePretty.result(path, context: self)
90
- end
91
-
92
- def s3_bucket
93
- Lono::S3::Bucket.name
94
- end
95
-
96
- def file_s3_key(name, options={})
97
- Lono::AppFile::Registry.register(name, @blueprint, options)
98
- "file://app/files/#{name}" # placeholder for post processing
99
- end
100
- alias_method :s3_key, :file_s3_key
101
-
102
- def setting
103
- Lono::Setting.new
104
- end
105
- memoize :setting
106
- end
107
- end
@@ -1,61 +0,0 @@
1
- # Note: These are experimental helpers. Their interface may change or removed entirely.
2
- module Lono::Template::Dsl::Builder::Helpers
3
- module ParamHelper
4
- # Decorate the parameter method to make smarter.
5
- def parameter(*definition)
6
- name, second, third = definition
7
- create_condition = true
8
- # medium form
9
- if definition.size == 2 && second.is_a?(Hash) && second[:Conditional]
10
- # Creates:
11
- #
12
- # 1. parameter
13
- # 2. condition - used to make it optional
14
- #
15
- options = normalize_conditional_parameter_options(second)
16
- super(name, options)
17
- elsif definition.size == 3 && !second.is_a?(Hash) && third.is_a?(Hash)
18
- options = normalize_conditional_parameter_options(third)
19
- options[:Default] = second # probably a String, Integer, or Float
20
- super(name, options)
21
- else
22
- super
23
- create_condition = false
24
- end
25
-
26
- condition("Has#{name}", not!(equals(ref(name), ""))) if create_condition
27
- end
28
-
29
- # use long name to minimize method name collision
30
- def normalize_conditional_parameter_options(options)
31
- if options.is_a?(Hash)
32
- options.delete(:Conditional)
33
- options = if options.empty?
34
- { Default: "" }
35
- else
36
- defaults = { Default: "" }
37
- options.reverse_merge(defaults)
38
- end
39
- end
40
-
41
- options
42
- end
43
-
44
- # Creates:
45
- #
46
- # 1. parameter
47
- # 2. condition - used to make it optional
48
- #
49
- def conditional_parameter(name, options={})
50
- puts "DEPRECATED: Will be removed. Instead use: parameter(name, Conditional: true)"
51
- options = normalize_conditional_parameter_options(options)
52
- parameter(name, options)
53
- condition("Has#{name}", not!(equals(ref(name), "")))
54
- end
55
-
56
- def optional_ref(name)
57
- puts "DEPRECATED: Will be removed. Instead use: ref(name, Conditional: true)"
58
- if!("Has#{name}", ref(name), ref("AWS::NoValue"))
59
- end
60
- end
61
- end
@@ -1,39 +0,0 @@
1
- # Implements:
2
- #
3
- # template - uses @definition to build a CloudFormation template section
4
- #
5
- class Lono::Template::Dsl::Builder
6
- class Parameter < Base
7
- def template
8
- camelize(add_required(standarize(@definition)))
9
- end
10
-
11
- # Type is the only required property: https://amzn.to/2x8W5aD
12
- def standarize(definition)
13
- first, second, _ = definition
14
- if definition.size == 1 && first.is_a?(Hash) # long form
15
- first # pass through
16
- elsif definition.size == 2 && second.is_a?(Hash) # medium form
17
- logical_id, properties = first, second
18
- { logical_id => properties }
19
- elsif (definition.size == 2 && valid_value?(second)) || # short form
20
- definition.size == 1
21
- logical_id = first
22
- properties = valid_value?(second) ? { Default: second } : {}
23
- { logical_id => properties }
24
- else # I dont know what form
25
- raise "Invalid form provided. definition #{definition.inspect}"
26
- end
27
- end
28
-
29
- def add_required(attributes)
30
- properties = attributes.values.first
31
- properties["Type"] ||= 'String'
32
- attributes
33
- end
34
-
35
- def valid_value?(o)
36
- o.is_a?(Float) || o.is_a?(Integer) || o.is_a?(String) || o.is_a?(TrueClass) || o.is_a?(FalseClass)
37
- end
38
- end
39
- end
@@ -1,175 +0,0 @@
1
- require 'fileutils'
2
- require 'yaml'
3
-
4
- class Lono::Upgrade
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
@@ -1,36 +0,0 @@
1
- require 'fileutils'
2
- require 'yaml'
3
-
4
- class Lono::Upgrade
5
- class Upgrade42 < Lono::Sequence
6
- def upsert_gitignore
7
- text =<<-EOL
8
- .lono/current
9
- EOL
10
- if File.exist?(".gitignore")
11
- append_to_file ".gitignore", text
12
- else
13
- create_file ".gitignore", text
14
- end
15
- end
16
-
17
- def update_settings_yaml
18
- path = "config/settings.yml"
19
- puts "Updating #{path}."
20
- data = YAML.load_file(path)
21
-
22
- if data["base"].has_key?("randomize_stack_name")
23
- randomize = data["base"]["randomize_stack_name"]
24
- if randomize
25
- data["base"]["stack_name_suffix"] = "random"
26
- end
27
-
28
- data["base"].delete("randomize_stack_name")
29
- puts "Updated randomize_stack_name with stack_name_suffix."
30
- end
31
-
32
- text = YAML.dump(data)
33
- IO.write(path, text)
34
- end
35
- end
36
- end
@@ -1,55 +0,0 @@
1
- require 'fileutils'
2
- require 'yaml'
3
-
4
- class Lono::Upgrade
5
- class Upgrade5 < Lono::Sequence
6
- def sanity_check
7
- if File.exist?("blueprints")
8
- puts "The blueprints folder already exist. The project already seems to have the lono v5 structure."
9
- exit
10
- end
11
-
12
- unless File.exist?("config/settings.yml")
13
- puts "ERROR: The config/settings.yml file does not exist. Are you sure you're within a lono project?".color(:red)
14
- exit 1
15
- end
16
- end
17
-
18
- def create_blueprints_folder
19
- puts "Creating: blueprints folder"
20
- FileUtils.mkdir_p("blueprints/main")
21
- end
22
-
23
- def move_to_main_blueprint
24
- puts "Moving files to blueprints folder"
25
- # Dir.entries includes hidden files
26
- Dir.entries('.').each do |p|
27
- next if %w[blueprints .git .. .].include?(p)
28
- FileUtils.mv(p, "blueprints/main/#{p}")
29
- end
30
- end
31
-
32
- def move_configs
33
- puts "Setting up the new configs structure"
34
- FileUtils.mkdir_p("configs/main")
35
- FileUtils.mv("blueprints/main/config/params", "configs/main/params")
36
- FileUtils.mv("blueprints/main/config/variables", "configs/main/variables")
37
- FileUtils.mv("blueprints/main/config/settings.yml", "configs/settings.yml")
38
-
39
- FileUtils.rmdir("blueprints/main/config") if Dir.empty?("blueprints/main/config")
40
- end
41
-
42
- def starter_files
43
- puts "Creating remaining starter lono project files"
44
- files = %w[
45
- .gitignore
46
- Gemfile
47
- Guardfile
48
- README.md
49
- ]
50
- files.each { |f | template(f) }
51
-
52
- template("../upgrade5/blueprints/main/.meta/config.yml", "blueprints/main/.meta/config.yml")
53
- end
54
- end
55
- end