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
@@ -0,0 +1,44 @@
1
+ class Lono::Configset
2
+ class Preparer < Lono::AbstractBase
3
+ def initialize(options={})
4
+ super
5
+ @blueprint = Register::Blueprint.new(options)
6
+ @project = Register::Project.new(options)
7
+ @meta = Meta.new(options)
8
+ @resolver = Resolver.new
9
+ end
10
+
11
+ def run
12
+ register
13
+ resolve_dependencies
14
+ register_dependencies
15
+ materialize
16
+ validate_all! # run after final materializer
17
+ end
18
+
19
+ # Stores configsets registry items
20
+ def register
21
+ @project.register # IE: evaluates configs/BLUEPRINT/configsets/base.rb
22
+ @blueprint.register # IE: evaluates BLUEPRINT/config/configsets.rb
23
+ end
24
+
25
+ def resolve_dependencies
26
+ jades = Lono::Jade.tracked # at this point only top-level
27
+ @resolver.resolve(jades)
28
+ end
29
+
30
+ def register_dependencies
31
+ @resolver.register
32
+ end
33
+
34
+ def materialize
35
+ jades = Lono::Jade.downloaded
36
+ Materializer::Final.new.build(jades)
37
+ end
38
+
39
+ def validate_all!
40
+ @blueprint.validate!
41
+ @project.validate!
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,121 @@
1
+ # Subclasses must implement:
2
+ #
3
+ # evaluate
4
+ #
5
+ module Lono::Configset::Register
6
+ class Base < Lono::AbstractBase
7
+ class_attribute :configsets
8
+ class_attribute :validations
9
+ class_attribute :source
10
+
11
+ include Dsl
12
+ include Lono::Configset::EvaluateFile
13
+
14
+ def register
15
+ evaluate
16
+ jadify
17
+ end
18
+
19
+ def jadify
20
+ self.class.configsets.each do |registry|
21
+ Lono::Jade.new(registry.name, jade_type, registry)
22
+ end
23
+ end
24
+
25
+ def jade_type
26
+ finder_class.to_s.sub('Lono::Finder::','').underscore
27
+ end
28
+
29
+ # Used in Base#validate!
30
+ def finder_class
31
+ case self
32
+ when Lono::Configset::Register::Blueprint
33
+ Lono::Finder::Blueprint::Configset
34
+ when Lono::Configset::Register::Project
35
+ Lono::Finder::Configset
36
+ end
37
+ end
38
+
39
+ # Store to be able to provide the validation errors altogether later.
40
+ def store_for_validation(registry)
41
+ # save caller line to use later for pointing to exactly line
42
+ caller_line = caller.grep(/evaluate_file/).first
43
+ registry.caller_line = caller_line
44
+ # huge performance improvement by only validating the first configset registration of duplicate gems
45
+ names = self.class.validations.map {|r| r.name }
46
+ self.class.validations << registry unless names.include?(registry.name)
47
+ end
48
+
49
+ # Validate the configset before building templates. So user finds out about errors early.
50
+ def validate!
51
+ errors = []
52
+ self.class.validations.each do |registry|
53
+ config = finder_class.find(registry.name) # finder_class implemented in subclass
54
+ errors << [:finder_missing, registry] unless config
55
+
56
+ if registry.depends_on.nil? && registry.resource.nil?
57
+ errors << [:resource_missing, registry]
58
+ end
59
+ end
60
+
61
+ return if errors.empty? # all good
62
+ show_errors_and_exit!(errors)
63
+ end
64
+
65
+ def show_errors_and_exit!(errors)
66
+ errors.each do |error_type, registry|
67
+ name, caller_line = registry.name, registry.caller_line
68
+ case error_type
69
+ when :finder_missing
70
+ puts "ERROR: Configset with name #{name} not found. Please double check Gemfile and configs/#{@blueprint}/configsets files.".color(:red)
71
+ pretty_trace(caller_line)
72
+ when :resource_missing
73
+ puts "ERROR: Configset with name #{name} does not specify resource. The resource key is required.".color(:red)
74
+ pretty_trace(caller_line)
75
+ raise
76
+ end
77
+ end
78
+ exit 1
79
+ end
80
+
81
+ def pretty_trace(caller_line)
82
+ md = caller_line.match(/(.*\.rb):(\d+):/)
83
+ path, error_line_number = md[1], md[2].to_i
84
+
85
+ context = 5 # lines of context
86
+ top, bottom = [error_line_number-context-1, 0].max, error_line_number+context-1
87
+
88
+ puts "Showing file: #{path}"
89
+ lines = IO.read(path).split("\n")
90
+ spacing = lines.size.to_s.size
91
+ lines[top..bottom].each_with_index do |line_content, index|
92
+ current_line_number = top+index+1
93
+ if current_line_number == error_line_number
94
+ printf("%#{spacing}d %s\n".color(:red), current_line_number, line_content)
95
+ else
96
+ printf("%#{spacing}d %s\n", current_line_number, line_content)
97
+ end
98
+ end
99
+ end
100
+
101
+ public
102
+ class << self
103
+ def clear!
104
+ self.configsets = []
105
+ self.validations = []
106
+ end
107
+
108
+ def prepend(registry)
109
+ self.configsets.unshift(registry) unless has?(registry)
110
+ end
111
+
112
+ def append(registry)
113
+ self.configsets << registry unless has?(registry)
114
+ end
115
+
116
+ def has?(registry)
117
+ configsets.detect { |r| r.name == registry.name && r.args == registry.args }
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,16 @@
1
+ module Lono::Configset::Register
2
+ class Blueprint < Base
3
+ self.configsets = []
4
+ self.validations = []
5
+
6
+ def evaluate
7
+ path = find_configsets
8
+ evaluate_file(path)
9
+ end
10
+
11
+ def find_configsets
12
+ path = "#{Lono.blueprint_root}/config/configsets.rb"
13
+ path if File.exist?(path)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ module Lono::Configset::Register
2
+ module Dsl
3
+ def configset(*args)
4
+ options = args.last.is_a?(Hash) ? args.pop : {}
5
+ registry = Lono::Configset::Registry.new(args, options)
6
+ self.class.append(registry)
7
+ store_for_validation(registry)
8
+ end
9
+
10
+ # DSL
11
+ def source(v)
12
+ self.class.source = v
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module Lono::Configset::Register
2
+ class Project < Base
3
+ self.configsets = []
4
+ self.validations = []
5
+
6
+ def evaluate
7
+ location = Lono::ConfigLocation.new("configsets", @options, Lono.env)
8
+ evaluate_file(location.lookup_base) if location.lookup_base
9
+ evaluate_file(location.lookup) if location.lookup # config file
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,34 @@
1
+ class Lono::Configset
2
+ class Registry
3
+ attr_reader :args, :options
4
+ attr_accessor :caller_line, :parent, :depends_on
5
+ def initialize(args, options)
6
+ @args, @options = args, options
7
+ end
8
+
9
+ def name
10
+ @args.first
11
+ end
12
+
13
+ def resource
14
+ @options[:resource]
15
+ end
16
+
17
+ def resource=(v)
18
+ @options[:resource] = v
19
+ end
20
+
21
+ def gem_options
22
+ options = @options.dup
23
+ # Delete special options that is not supported by bundler Gemfile
24
+ options.delete(:repo)
25
+ options.delete(:resource)
26
+ options.delete(:vars)
27
+ options
28
+ end
29
+
30
+ def vars
31
+ options[:vars] || {}
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,42 @@
1
+ class Lono::Configset
2
+ class Resolver
3
+ extend Memoist
4
+
5
+ @@dependencies = [] # save to later regsiter configsets
6
+
7
+ @@resolving_message_shown = false
8
+ def resolve(*unresolved)
9
+ unresolved.flatten! # initially only top-level
10
+ puts "Resolving dependencies..." if !@@resolving_message_shown && !unresolved.empty?
11
+ puts "Resolving #{unresolved.map(&:name)}" if ENV['LONO_DEBUG_CONFIGSET']
12
+
13
+ @@resolving_message_shown = true
14
+
15
+ unresolved.each do |jade|
16
+ jade.check_for_circular_dependency!
17
+ jade.materialize
18
+ jade.dependencies.each do |j|
19
+ @@dependencies << j # store for later registration
20
+ unless j.resolved? or unresolved.include?(j)
21
+ resolve(j)
22
+ end
23
+ end
24
+ jade.resolved! # resolve after depth-first tranversal. So all dependencies have also been resolved at this point.
25
+ end
26
+ end
27
+
28
+ def register
29
+ @@dependencies.each do |jade|
30
+ # dependency jades have minimal registry info. For additional info is pulled from stored reference data in
31
+ # jade like jade.resource_from_parent.
32
+ registry = jade.registry
33
+ registry.resource = jade.resource_from_parent
34
+ if jade.type == "blueprint/configset"
35
+ Register::Blueprint.prepend(registry)
36
+ elsif jade.type == "configset"
37
+ Register::Project.prepend(registry)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,11 +1,22 @@
1
1
  module Lono
2
- module Conventions
3
- # Think can make this a module, but need to figure out how it fits with lono cfn
4
- def template_param_convention(options)
5
- options = options.deep_symbolize_keys
6
- template = options[:template] || @blueprint
7
- param = options[:param] || template || @blueprint
8
- [template, param]
2
+ class Conventions
3
+ attr_reader :stack, :blueprint, :template, :param
4
+ def initialize(options)
5
+ @options = options
6
+ @stack, @blueprint, @template, @param = naming_conventions(options)
7
+ end
8
+
9
+ def naming_conventions(options)
10
+ o = options.deep_symbolize_keys
11
+ stack = o[:stack]
12
+ blueprint = o[:blueprint] || o[:stack]
13
+ template = o[:template] || blueprint
14
+ param = o[:param] || template || blueprint
15
+ [stack, blueprint, template, param]
16
+ end
17
+
18
+ def values
19
+ [@stack, @blueprint, @template, @param]
9
20
  end
10
21
  end
11
22
  end
@@ -39,23 +39,6 @@ module Lono
39
39
  end
40
40
  end
41
41
 
42
- # Precedence (highest to lowest)
43
- # 1. LONO_SUFFIX
44
- # 2. .current/lono
45
- # 3. config/settings.yml
46
- def suffix
47
- suffix = ENV['LONO_SUFFIX'] # highest precedence
48
- suffix ||= Cfn::Current.suffix
49
- unless suffix
50
- settings = Setting.new.data
51
- suffix ||= settings["stack_name_suffix"] # lowest precedence
52
- end
53
-
54
- return if suffix&.empty?
55
- suffix
56
- end
57
- memoize :suffix
58
-
59
42
  # Do not use the Setting#data to load the profile because it can cause an
60
43
  # infinite loop then if we decide to use Lono.env from within settings class.
61
44
  def settings
@@ -67,9 +50,22 @@ module Lono
67
50
  end
68
51
  memoize :settings
69
52
 
70
- def pro_version
71
- installed = Gem::Specification.detect { |spec| spec.name == 'lono-pro' }
72
- installed ? Lono::Pro::VERSION : "not installed"
53
+ def lono_pro_removal_check!
54
+ if lono_pro_installed?
55
+ puts "ERROR: A lono-pro gem installation has been detected.".color(:red)
56
+ puts <<~EOL
57
+ The lono-pro gem is now a part of lono itself. The lono-pro gem has been deprecated.
58
+ Please uninstall the lono-pro gem and remove it from your Gemfile to continue.
59
+ EOL
60
+ exit 1
61
+ end
62
+ end
63
+
64
+ def lono_pro_installed?
65
+ Lono::Pro::VERSION
66
+ true
67
+ rescue NameError
68
+ false
73
69
  end
74
70
 
75
71
  private
@@ -1,13 +1,12 @@
1
- # More info: http://lono.cloud/docs/settings/
1
+ # More info: https://lono.cloud/docs/settings/
2
2
  # The base config is specially treated. It gets included the other environments automatically.
3
3
  # Yaml also directly supports merging with & and <<* syntax but doing it automatically
4
4
  # for a cleaner syntax.
5
5
  base:
6
- # http://lono.cloud/docs/app-scripts/
6
+ # https://lono.cloud/docs/app-scripts/
7
7
  # extract_scripts:
8
8
  # to: "/opt"
9
9
  # as: "ec2-user"
10
- # stack_name_suffix: random # tack on a 3 char random string at the end of the stack name for lono cfn create
11
10
 
12
11
  development:
13
12
  # When you have AWS_PROFILE set to one of these values, lono will switch to the desired
@@ -0,0 +1,7 @@
1
+ # Bundler 2.0 does yet not have with_unbundled_env
2
+ # Bundler 2.1 deprecates with_clean_env for with_unbundled_env
3
+
4
+ require "bundler"
5
+ def Bundler.with_unbundled_env(&block)
6
+ with_clean_env(&block)
7
+ end unless Bundler.respond_to?(:with_unbundled_env)
@@ -1,19 +1,22 @@
1
1
  module Lono
2
- class FileUploader
2
+ class FileUploader < AbstractBase
3
3
  include Lono::Template::AwsService
4
4
  extend Memoist
5
5
 
6
- def initialize(blueprint, options={})
7
- @blueprint, @options = blueprint, options
6
+ def initialize(options={})
7
+ super
8
8
  @checksums = {}
9
9
  @prefix = "#{folder_key}/#{Lono.env}/#{blueprint}/files" # s3://s3-bucket/folder/development/files
10
10
  end
11
11
 
12
12
  def upload_all
13
- puts "Uploading app/files..."
13
+ # pattern = "#{Lono.blueprint_root}/app/files/**/*"
14
+ # size = Dir.glob(pattern).size
15
+ # puts "size #{size}"
16
+ # return unless Dir.glob(pattern).size > 0
17
+ # puts "Uploading app/files2..."
14
18
  load_checksums!
15
19
 
16
- pattern = "#{Lono.blueprint_root}/app/files/**/*"
17
20
  Dir.glob(pattern).each do |path|
18
21
  next if ::File.directory?(path)
19
22
  s3_upload(path)
@@ -0,0 +1,140 @@
1
+ require "bundler"
2
+ require "text-table"
3
+
4
+ module Lono::Finder
5
+ class Base
6
+ extend Memoist
7
+
8
+ def initialize(lono_root: nil, blueprint_root: nil)
9
+ @lono_root = lono_root || Lono.root
10
+ @blueprint_root = blueprint_root || Lono.blueprint_root
11
+ end
12
+
13
+ # Returns root path of component: blueprint or configset
14
+ def find(name, local_only: false)
15
+ all = find_all(local_only: local_only)
16
+ all.find { |jadespec| jadespec.name == name }
17
+ end
18
+
19
+ def find_all(local_only: false)
20
+ if local_only
21
+ local
22
+ else
23
+ local + materialized
24
+ end
25
+ end
26
+
27
+ # overridden in finder/blueprint/configset.rb
28
+ def local
29
+ project + vendor + gems
30
+ end
31
+
32
+ def project
33
+ roots = path_roots("#{@lono_root}/app/#{type.pluralize}")
34
+ components(roots, "project")
35
+ end
36
+
37
+ def vendor
38
+ roots = path_roots("#{@lono_root}/vendor/#{type.pluralize}")
39
+ components(roots, "vendor")
40
+ end
41
+
42
+ def gems
43
+ components(gem_roots, "gem")
44
+ end
45
+
46
+ # Folders that each materialized gems to tmp/configsets
47
+ def materialized
48
+ components(materialized_gem_roots, "materialized")
49
+ end
50
+
51
+ # Components: blueprints or configsets
52
+ # Returns array of config Hashes. Example structure:
53
+ #
54
+ # [{
55
+ # name: "cfn-hup",
56
+ # root: "/path/to/gem/root",
57
+ # source_type: "project",
58
+ # },...]
59
+ #
60
+ def components(roots, source_type)
61
+ components = []
62
+ roots.each do |root|
63
+ next unless detect?(root)
64
+ jadespec = Lono::Jadespec.new(root, source_type)
65
+ components << jadespec
66
+ end
67
+ components
68
+ end
69
+ memoize :components
70
+
71
+ def detect?(root)
72
+ expr = "#{root}/#{detection_path}"
73
+ Dir.glob(expr).size > 0
74
+ end
75
+
76
+ # Used for blueprints, configsets, and blueprint/configsets
77
+ def list(options={})
78
+ table = Text::Table.new
79
+ table.head = ["Name", "Path", "Type"]
80
+
81
+ components = find_all
82
+ components.each do |jadespec|
83
+ pretty_path = jadespec.root.sub("#{Lono.root}/", "")
84
+ unless options[:filter_materialized] && jadespec.source_type == "materialized"
85
+ table.rows << [jadespec.name, pretty_path, jadespec.source_type]
86
+ end
87
+ end
88
+
89
+ if table.rows.empty?
90
+ puts "No #{type.pluralize} found."
91
+ else
92
+ puts(options[:message] || "Available #{type.pluralize}:")
93
+ puts table
94
+ end
95
+ end
96
+
97
+ private
98
+ def path_roots(path)
99
+ Dir.glob("#{path}/*").to_a
100
+ end
101
+
102
+ # Example return:
103
+ #
104
+ # [
105
+ # "/home/ec2-user/.rbenv/versions/2.5.6/lib/ruby/gems/2.5.0/gems/rake-13.0.1",
106
+ # "/home/ec2-user/.rbenv/versions/2.5.6/lib/ruby/gems/2.5.0/gems/thor-0.20.3"
107
+ # ]
108
+ #
109
+ def gem_roots
110
+ Bundler.load.specs.map do |spec|
111
+ spec.full_gem_path
112
+ end
113
+ end
114
+ memoize :gem_roots
115
+
116
+ def materialized_gem_roots
117
+ gemfile_lock = "#{Lono.root}/tmp/configsets/Gemfile.lock"
118
+ return [] unless File.exist?(gemfile_lock)
119
+ parser = Bundler::LockfileParser.new(Bundler.read_file(gemfile_lock))
120
+ specs = parser.specs
121
+ # __materialize__ only exists in Gem::LazySpecification and not in Gem::Specification
122
+ specs.each { |spec| spec.__materialize__ }
123
+ specs.map do |spec|
124
+ spec.full_gem_path
125
+ end
126
+ end
127
+ memoize :materialized_gem_roots
128
+
129
+ public
130
+ class << self
131
+ def find(name)
132
+ new.find(name)
133
+ end
134
+
135
+ def list(options={})
136
+ new.list(options)
137
+ end
138
+ end
139
+ end
140
+ end