lono 8.0.0.pre.rc3 → 8.0.0.pre.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +84 -0
  3. data/.github/ISSUE_TEMPLATE/documentation.md +12 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +64 -0
  5. data/.github/ISSUE_TEMPLATE/question.md +14 -0
  6. data/.github/ISSUE_TEMPLATE.md +7 -0
  7. data/.github/PULL_REQUEST_TEMPLATE.md +50 -0
  8. data/CHANGELOG.md +33 -0
  9. data/lib/lono/app.rb +37 -3
  10. data/lib/lono/builder/allow.rb +1 -1
  11. data/lib/lono/builder/configset/definition/context.rb +50 -9
  12. data/lib/lono/builder/configset/definition/dsl/syntax/content.rb +3 -7
  13. data/lib/lono/builder/context.rb +1 -1
  14. data/lib/lono/builder/dsl/finalizer/files/build.rb +4 -12
  15. data/lib/lono/builder/dsl/finalizer/files/replace.rb +6 -1
  16. data/lib/lono/builder/dsl/helpers/files.rb +2 -2
  17. data/lib/lono/builder/dsl/helpers/s3.rb +5 -7
  18. data/lib/lono/builder/dsl/helpers/stack.rb +2 -4
  19. data/lib/lono/builder/dsl/helpers/template_file.rb +2 -2
  20. data/lib/lono/builder/dsl/syntax/core/squeezer.rb +3 -1
  21. data/lib/lono/builder/dsl/syntax/fn.rb +0 -2
  22. data/lib/lono/builder/dsl.rb +1 -1
  23. data/lib/lono/builder/param.rb +1 -1
  24. data/lib/lono/builder/template.rb +1 -3
  25. data/lib/lono/builder.rb +39 -0
  26. data/lib/lono/bundler/util/git.rb +18 -16
  27. data/lib/lono/cfn/base.rb +2 -2
  28. data/lib/lono/cfn/concerns/build.rb +1 -1
  29. data/lib/lono/cfn/delete.rb +5 -2
  30. data/lib/lono/cfn/deploy/rollback.rb +1 -3
  31. data/lib/lono/cfn/deploy.rb +16 -4
  32. data/lib/lono/cfn/plan/changeset.rb +1 -1
  33. data/lib/lono/cli/base.rb +1 -0
  34. data/lib/lono/cli/help/new/helper.md +27 -0
  35. data/lib/lono/cli/help/new/hook.md +14 -0
  36. data/lib/lono/cli/help/new/project.md +3 -10
  37. data/lib/lono/cli/iam.rb +27 -0
  38. data/lib/lono/cli/new/blueprint.rb +2 -4
  39. data/lib/lono/cli/new/helper.rb +35 -8
  40. data/lib/lono/cli/new/hook.rb +32 -0
  41. data/lib/lono/cli/new.rb +8 -4
  42. data/lib/lono/cli/script/build.rb +0 -5
  43. data/lib/lono/{inspector → cli}/summary.rb +23 -30
  44. data/lib/lono/cli.rb +9 -7
  45. data/lib/lono/command.rb +28 -1
  46. data/lib/lono/core.rb +10 -0
  47. data/lib/lono/{utils → files/builder/lambda_layer}/rsync.rb +3 -5
  48. data/lib/lono/files/builder/lambda_layer/ruby_packager.rb +178 -0
  49. data/lib/lono/files/builder/lambda_layer/ruby_version.rb +38 -0
  50. data/lib/lono/files/builder/lambda_layer.rb +17 -0
  51. data/lib/lono/files/concerns/post_processing.rb +19 -2
  52. data/lib/lono/files/concerns/registration.rb +4 -1
  53. data/lib/lono/files.rb +6 -2
  54. data/lib/lono/hooks/builder.rb +50 -0
  55. data/lib/lono/hooks/concern.rb +9 -0
  56. data/lib/lono/hooks/dsl.rb +20 -0
  57. data/lib/lono/hooks/runner.rb +46 -0
  58. data/lib/lono/layering/layer.rb +63 -41
  59. data/lib/lono/names.rb +6 -9
  60. data/lib/lono/s3/bucket.rb +17 -11
  61. data/lib/lono/s3/uploader.rb +4 -0
  62. data/lib/lono/script/build.rb +0 -5
  63. data/lib/lono/seeder.rb +1 -1
  64. data/lib/lono/utils/sh.rb +32 -0
  65. data/lib/lono/utils.rb +5 -0
  66. data/lib/lono/version.rb +1 -1
  67. data/lib/templates/hook/config/hooks.rb.tt +14 -0
  68. data/lono.gemspec +1 -1
  69. metadata +27 -30
  70. data/lib/lono/builder/template/post_processor.rb +0 -67
  71. data/lib/lono/cli/build.rb +0 -47
  72. data/lib/lono/cli/code.rb +0 -22
  73. data/lib/lono/cli/help/blueprint/new.md +0 -56
  74. data/lib/lono/cli/help/new/helper/blueprint.md +0 -17
  75. data/lib/lono/cli/help/new/helper/project.md +0 -16
  76. data/lib/lono/cli/new/extension.rb +0 -57
  77. data/lib/lono/cli/new/helper/blueprint.rb +0 -26
  78. data/lib/lono/cli/new/helper/project.rb +0 -24
  79. data/lib/lono/importer/base.rb +0 -48
  80. data/lib/lono/importer/converter.rb +0 -19
  81. data/lib/lono/importer/download.rb +0 -46
  82. data/lib/lono/importer/dsl.rb +0 -36
  83. data/lib/lono/importer/params.rb +0 -56
  84. data/lib/lono/importer/service/coder.rb +0 -85
  85. data/lib/lono/inspector/base.rb +0 -32
  86. data/lib/templates/extension/lib/%extension_name%/autoloader.rb.tt +0 -23
  87. data/lib/templates/extension/lib/%extension_name%/helpers/mappings.rb.tt +0 -24
  88. data/lib/templates/extension/lib/%extension_name%/helpers/outputs.rb.tt +0 -7
  89. data/lib/templates/extension/lib/%extension_name%/helpers/parameters.rb.tt +0 -10
  90. data/lib/templates/extension/lib/%extension_name%/helpers/resources/resource.rb.tt +0 -4
  91. data/lib/templates/extension/lib/%extension_name%/helpers/variables.rb.tt +0 -6
  92. data/lib/templates/extension/lib/%extension_name%/version.rb.tt +0 -3
  93. data/lib/templates/extension/lib/%extension_name%.rb.tt +0 -8
@@ -1,22 +1,7 @@
1
1
  module Lono::Bundler::Util
2
2
  module Git
3
3
  include Logging
4
-
5
- def sh(command)
6
- command = "#{command} 2>&1" # always need output for the sha
7
- logger.debug "=> #{command}"
8
- out = `#{command}`
9
- unless $?.success?
10
- if command.include?("git")
11
- raise LB::GitError.new("#{command}\n#{out}")
12
- else
13
- logger.error "ERROR: running #{command}".color(:red)
14
- logger.error out
15
- exit $?.exitstatus
16
- end
17
- end
18
- out
19
- end
4
+ include Lono::Utils::Sh
20
5
 
21
6
  def git(command)
22
7
  sh("git #{command}")
@@ -33,5 +18,22 @@ module Lono::Bundler::Util
33
18
  end
34
19
  exit 1
35
20
  end
21
+
22
+ # Different from Lono::Utils::Sh
23
+ def sh(command)
24
+ command = "#{command} 2>&1" # always need output for the sha
25
+ logger.debug "=> #{command}"
26
+ out = `#{command}`
27
+ unless $?.success?
28
+ if command.include?("git")
29
+ raise LB::GitError.new("#{command}\n#{out}")
30
+ else
31
+ logger.error "ERROR: running #{command}".color(:red)
32
+ logger.error out
33
+ exit $?.exitstatus
34
+ end
35
+ end
36
+ out
37
+ end
36
38
  end
37
39
  end
data/lib/lono/cfn/base.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  module Lono::Cfn
2
2
  class Base < Lono::CLI::Base
3
3
  extend Memoist
4
-
5
4
  include Lono::AwsServices
6
- include Lono::Utils::Sure
5
+ include Lono::Hooks::Concern
7
6
  include Lono::Utils::Logging
8
7
  include Lono::Utils::Pretty
9
8
  include Lono::Utils::Quit
9
+ include Lono::Utils::Sure
10
10
 
11
11
  include Concerns
12
12
 
@@ -3,7 +3,7 @@ module Lono::Cfn::Concerns
3
3
  extend Memoist
4
4
 
5
5
  def build
6
- Lono::CLI::Build.new(@options)
6
+ Lono::Builder.new(@options)
7
7
  end
8
8
  memoize :build
9
9
  end
@@ -1,9 +1,12 @@
1
1
  module Lono::Cfn
2
2
  class Delete < Base
3
3
  def run
4
+ logger.info "Will delete stack #{@stack.color(:green)}"
4
5
  plan.for_delete
5
- sure?("Are you sure you want to delete the #{@stack} stack?")
6
- cfn.delete_stack(stack_name: @stack)
6
+ sure?("Are you sure you want to delete the stack?")
7
+ run_hooks("down") do
8
+ cfn.delete_stack(stack_name: @stack)
9
+ end
7
10
  if @options[:wait]
8
11
  status.wait
9
12
  else
@@ -11,10 +11,8 @@ class Lono::Cfn::Deploy
11
11
 
12
12
  def continue_update
13
13
  continue_update?
14
- options = {stack_name: @stack}
15
- show_options(options, "continue_update_rollback")
16
14
  begin
17
- cfn.continue_update_rollback(options)
15
+ cfn.continue_update_rollback(stack_name: @stack)
18
16
  rescue Aws::CloudFormation::Errors::ValidationError => e
19
17
  logger.info "ERROR: Continue update: #{e.message}".color(:red)
20
18
  quit 1
@@ -2,7 +2,9 @@ module Lono::Cfn
2
2
  class Deploy < Base
3
3
  def run
4
4
  start_message
5
- perform # create or update
5
+ run_hooks("up") do
6
+ perform # create or update
7
+ end
6
8
  success = status.wait
7
9
  if success
8
10
  finish_message
@@ -29,7 +31,7 @@ module Lono::Cfn
29
31
  # e.message: Template format error: YAML not well-formed. (line 207, column 9)
30
32
  print_code(e)
31
33
  else
32
- logger.info "ERROR: #{e.message}".color(:red)
34
+ logger.info "ERROR: Deploy#perform #{e.class} #{e.message}".color(:red)
33
35
  logger.info "Check: #{pretty_path(@blueprint.output_path)}"
34
36
  quit 1
35
37
  end
@@ -50,7 +52,6 @@ module Lono::Cfn
50
52
  def create
51
53
  plan.for_create
52
54
  @sure || sure?("Going to create stack #{@stack} with blueprint #{@blueprint.name}.")
53
- upload_files
54
55
  options = {
55
56
  stack_name: @stack,
56
57
  parameters: build.parameters,
@@ -58,6 +59,7 @@ module Lono::Cfn
58
59
  opts = Opts.new(@blueprint, "create_stack", iam, options)
59
60
  opts.show
60
61
  options = opts.values
62
+ upload_all
61
63
  cfn.create_stack(options)
62
64
  end
63
65
 
@@ -68,12 +70,22 @@ module Lono::Cfn
68
70
  end
69
71
 
70
72
  operable.check!
73
+ upload_all # important to call before plan.for_update.
74
+ # plan.for_update creates the changeset and requires the template to already be uploaded to s3
71
75
  changeset = plan.for_update
72
76
  !changeset.changed? || @sure || sure?("Are you sure you want to update the #{@stack} stack?")
73
- upload_files
74
77
  changeset.execute_change_set
75
78
  end
76
79
 
80
+ def upload_all
81
+ upload_templates
82
+ upload_files
83
+ end
84
+
85
+ def upload_templates
86
+ Lono::Builder::Template::Upload.new(@options).run
87
+ end
88
+
77
89
  # Upload files right before create_stack or execute_change_set
78
90
  # Its better to upload here as part of a deploy vs a build
79
91
  # IE: lono build should try not to do a remote write to s3 if possible
@@ -36,7 +36,7 @@ class Lono::Cfn::Plan
36
36
  change_set = describe_change_set
37
37
  sleep 1
38
38
  unless newline_needed
39
- logger.print "Determining Change Set"
39
+ logger.print "Calculating Change Set"
40
40
  end
41
41
  newline_needed = true
42
42
  logger.print '.'
data/lib/lono/cli/base.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  class Lono::CLI
2
2
  class Base < Abstract
3
3
  include Lono::Concerns::Names
4
+ include Lono::Utils::Sh
4
5
 
5
6
  def initialize(options={})
6
7
  super
@@ -0,0 +1,27 @@
1
+ ## Blueprint Helpers
2
+
3
+ When the `--blueprint` option is used a blueprint helper is generated.
4
+
5
+ The default name is custom
6
+
7
+ $ lono new helper --blueprint demo
8
+ create app/blueprints/demo/helpers/custom_helper.rb
9
+
10
+ Here's an example with a helper named vars.
11
+
12
+ $ lono new helper vars --blueprint demo
13
+ create app/blueprints/demo/helpers/vars_helper.rb
14
+
15
+ ## Project Helpers
16
+
17
+ When no `--blueprint` option is used a project helper is generated.
18
+
19
+ The default name is custom.
20
+
21
+ $ lono new helper
22
+ create app/helpers/custom/custom_helper.rb
23
+
24
+ Here's an example with a helper named common.
25
+
26
+ $ lono new helper common
27
+ create app/helpers/common/common_helper.rb
@@ -0,0 +1,14 @@
1
+ ## Blueprint Hooks
2
+
3
+ When the `--blueprint` option is used a blueprint hook is generated.
4
+
5
+ $ lono new helper --blueprint demo
6
+ create app/blueprints/demo/config/hooks.rb
7
+
8
+ ## Project Helpers
9
+
10
+ When no `--blueprint` option is used a project hook is generated.
11
+
12
+ $ lono new helper
13
+ create app/config/hooks.rb
14
+
@@ -1,22 +1,15 @@
1
1
  ## Example
2
2
 
3
3
  $ lono new project infra
4
+ Other infra
4
5
  => Creating new project called infra.
5
6
  create infra
6
7
  create infra/.gitignore
7
8
  create infra/Gemfile
8
9
  create infra/README.md
9
10
  create infra/config/app.rb
10
- => Initialize git repo
11
- run git init from "."
12
- Initialized empty Git repository in /home/ec2-user/environment/infra/.git/
13
11
  => Installing dependencies with: bundle install
14
- Resolving dependencies...Fetching gem metadata from https://rubygems.org/.......
15
- ............................
16
- Using concurrent-ruby 1.1.9
17
- ...
18
- Bundle complete! 1 Gemfile dependency, 40 gems now installed.
19
- Use `bundle info [gemname]` to see where a bundled gem is installed.
12
+ Bundle complete! 2 Gemfile dependencies, 47 gems now installed.
20
13
  ================================================================
21
14
  Congrats 🎉 You have successfully created a lono project.
22
15
 
@@ -31,4 +24,4 @@
31
24
  lono up demo
32
25
 
33
26
  More info: https://lono.cloud/
34
- $
27
+ $
@@ -0,0 +1,27 @@
1
+ class Lono::CLI
2
+ class Iam < Base
3
+ include Lono::Cfn::Concerns::Build
4
+ include Lono::Cfn::Concerns::TemplateOutput
5
+
6
+ def run
7
+ build.template_builder.run
8
+ resources = template_output.data['Resources']
9
+ types = resources.map { |logical_id, attrs| attrs['Type'] }
10
+ actions = types.map do |t|
11
+ service = t.split('::')[1]
12
+ "#{service.downcase}:*"
13
+ end.uniq
14
+ text =<<~EOL
15
+ Version: 2012-10-17
16
+ Statement:
17
+ - Sid: #{@blueprint.name}
18
+ Effect: Allow
19
+ Resource: "*"
20
+ EOL
21
+ policy = YAML.load(text)
22
+ policy['Statement'][0]['Action'] = actions
23
+ puts "IAM Policy Example for blueprint #{@blueprint.name}".color(:green)
24
+ puts JSON.pretty_generate(policy)
25
+ end
26
+ end
27
+ end
@@ -5,7 +5,6 @@ class Lono::CLI::New
5
5
  [
6
6
  [:examples, type: :boolean, desc: "Whether not to generate examples"],
7
7
  [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
8
- [:project, desc: "Project name"],
9
8
  ]
10
9
  end
11
10
  cli_options.each do |args|
@@ -21,9 +20,8 @@ class Lono::CLI::New
21
20
  end
22
21
 
23
22
  def create_blueprint
24
- logger.info "=> Creating new blueprint called #{name}."
25
- dest = [@options[:project], "app/blueprints"].compact.join('/')
26
- directory ".", "#{dest}/#{name}"
23
+ logger.info "=> Creating new blueprint: #{name}"
24
+ directory ".", "app/blueprints/#{name}"
27
25
  end
28
26
  end
29
27
  end
@@ -1,13 +1,40 @@
1
1
  class Lono::CLI::New
2
- class Helper < Lono::Command
3
- Help = Lono::CLI::Help
2
+ class Helper < Lono::CLI::New::Sequence
3
+ def self.cli_options
4
+ # required for name => underscore_name => app/blueprints/demo/helpers/%underscore_name%_helper.rb.tt
5
+ argument :name, default: "custom", desc: "Helper name"
4
6
 
5
- long_desc Help.text("new/helper/blueprint")
6
- Blueprint.cli_options.each { |args| option(*args) }
7
- register(Blueprint, "blueprint", "blueprint HELPER_NAME --blueprint", "Generates new blueprint helper")
7
+ [
8
+ [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
9
+ [:blueprint, aliases: :b, desc: "Blueprint name. Only use you want a blueprint helper. Otherwise a project helper is generated"],
10
+ ]
11
+ end
12
+ cli_options.each do |args|
13
+ class_option(*args)
14
+ end
8
15
 
9
- long_desc Help.text("new/helper/project")
10
- Project.cli_options.each { |args| option(*args) }
11
- register(Project, "project", "project HELPER_NAME", "Generates new project helper")
16
+ def set_source
17
+ set_template_source "helper"
18
+ end
19
+
20
+ def create_helper
21
+ if @options[:blueprint]
22
+ create_blueprint_helper
23
+ else
24
+ create_project_helper
25
+ end
26
+ end
27
+
28
+ private
29
+ def create_blueprint_helper
30
+ @blueprint = @options[:blueprint] # allows %underscore_name%_helper.rb.tt to access @blueprint
31
+ logger.info "=> Generating #{underscore_name}_helper.rb"
32
+ directory ".", "app/blueprints/#{@blueprint}/helpers"
33
+ end
34
+
35
+ def create_project_helper
36
+ logger.info "=> Generating #{underscore_name}_helper.rb"
37
+ directory ".", "app/helpers/#{underscore_name}"
38
+ end
12
39
  end
13
40
  end
@@ -0,0 +1,32 @@
1
+ class Lono::CLI::New
2
+ class Hook < Lono::CLI::New::Sequence
3
+ def self.cli_options
4
+ [
5
+ [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
6
+ [:blueprint, aliases: :b, desc: "Blueprint name. Only use you want a blueprint helper. Otherwise a project helper is generated"],
7
+ ]
8
+ end
9
+ cli_options.each do |args|
10
+ class_option(*args)
11
+ end
12
+
13
+ def set_source
14
+ set_template_source "hook"
15
+ end
16
+
17
+ def create_hook
18
+ logger.info "=> Generating hook"
19
+ if blueprint
20
+ directory ".", "app/blueprints/#{blueprint}"
21
+ else
22
+ directory ".", "."
23
+ end
24
+ end
25
+
26
+ private
27
+ # So templates/hooks/config/hooks.rb.tt has access to blueprint
28
+ def blueprint
29
+ @options[:blueprint]
30
+ end
31
+ end
32
+ end
data/lib/lono/cli/new.rb CHANGED
@@ -8,6 +8,14 @@ class Lono::CLI
8
8
  Configset.cli_options.each { |args| option(*args) }
9
9
  register(Configset, "configset", "configset NAME", "Generate new configset")
10
10
 
11
+ long_desc Help.text("new/helper")
12
+ Helper.cli_options.each { |args| option(*args) }
13
+ register(Helper, "helper", "helper NAME", "Generate new helper")
14
+
15
+ long_desc Help.text("new/hook")
16
+ Hook.cli_options.each { |args| option(*args) }
17
+ register(Hook, "hook", "hook NAME", "Generate new hook")
18
+
11
19
  long_desc Help.text("new/project")
12
20
  Project.cli_options.each { |args| option(*args) }
13
21
  register(Project, "project", "project NAME", "Generate new project")
@@ -16,10 +24,6 @@ class Lono::CLI
16
24
  Shim.cli_options.each { |args| option(*args) }
17
25
  register(Shim, "shim", "shim NAME", "Generate new shim")
18
26
 
19
- desc "helper SUBCOMMAND", "helper subcommands"
20
- long_desc Help.text(:helper)
21
- subcommand "helper", Helper
22
-
23
27
  desc "test SUBCOMMAND", "test subcommands"
24
28
  long_desc Help.text(:test)
25
29
  subcommand "test", Test
@@ -63,10 +63,5 @@ class Lono::CLI::Script
63
63
  @md5sum ||= Digest::MD5.file("#{@blueprint.root}/scripts.tgz").to_s[0..7]
64
64
  end
65
65
 
66
- def sh(command)
67
- puts "=> #{command}"
68
- system command
69
- end
70
-
71
66
  end
72
67
  end
@@ -1,29 +1,27 @@
1
- module Lono::Inspector
1
+ class Lono::CLI
2
2
  class Summary < Base
3
+ include Lono::Cfn::Concerns::Build
3
4
  include Lono::Cfn::Concerns::TemplateOutput
4
5
 
5
- def perform(template)
6
- # little dirty but @template is used in data method so we dont have to pass it to the data method
7
- @template = template
8
- logger.info "=> CloudFormation Template Summary for template #{@template.color(:sienna)}:"
6
+ def run
7
+ build.all
9
8
  print_parameters_summary
10
- logger.info "# Resources:"
11
9
  print_resource_types
12
10
  end
13
11
 
14
12
  def print_parameters_summary
15
13
  parameters = template_output.parameters
14
+ logger.info "Parameters (#{parameters.size})".color(:green)
16
15
  parameter_groups = template_output.parameter_groups
17
16
 
18
17
  if parameters.empty?
19
- logger.info "There are no parameters in this template."
18
+ logger.info "No parameters"
20
19
  return
21
20
  end
22
21
 
23
22
  shown = []
24
- logger.info "# Parameters Total (#{parameters.size})"
25
- parameter_groups.each do |label, parameters|
26
- logger.info "# Parameter Group (#{parameters.size}): #{label}".color(:sienna)
23
+ parameter_groups.each do |parameter_group_label, parameters|
24
+ logger.info parameter_group_label
27
25
  parameters.each do |name|
28
26
  logger.info parameter_line(name)
29
27
  shown << name
@@ -37,13 +35,11 @@ module Lono::Inspector
37
35
 
38
36
  def parameter_line(name)
39
37
  data = template_output.parameters[name]
40
- example = description_example(data["Description"])
41
38
  if data["Default"].nil?
42
- line = "#{name}=#{example} # (required)"
39
+ line = " #{name} (required)"
43
40
  else
44
41
  default = data["Default"]
45
- line = "# #{name}=#{default}"
46
- line = "#{line} # #{example}" if example
42
+ line = default.blank? ? " #{name}" : " #{name}=#{default}"
47
43
  end
48
44
  line
49
45
  end
@@ -56,18 +52,9 @@ module Lono::Inspector
56
52
  md[2]
57
53
  end
58
54
 
59
- def resource_types
60
- resources = template_output.data["Resources"]
61
- return unless resources
62
-
63
- types = Hash.new(0)
64
- resources.each do |logical_id, resource|
65
- types[resource["Type"]] += 1
66
- end
67
- types
68
- end
69
-
70
55
  def print_resource_types
56
+ total = template_output.data["Resources"].size
57
+ logger.info "Resources (#{total})".color(:green)
71
58
  unless resource_types
72
59
  logger.info "No resources found."
73
60
  return
@@ -76,15 +63,21 @@ module Lono::Inspector
76
63
  types = resource_types.sort_by {|r| r[1] * -1} # Hash -> 2D Array
77
64
  types.each do |a|
78
65
  type, count = a
79
- printf "%3s %s\n", count, type
66
+ printf "%5s %s\n", count, type
80
67
  end
81
68
  total = types.inject(0) { |sum,(type,count)| sum += count }
82
- printf "%3s %s\n", total, "Total"
69
+ printf "%5s %s\n", total, "Total"
83
70
  end
84
71
 
85
- def template_output
86
- Lono::Builder::Template::Output.new(@blueprint)
72
+ def resource_types
73
+ resources = template_output.data["Resources"]
74
+ return unless resources
75
+
76
+ types = Hash.new(0)
77
+ resources.each do |logical_id, resource|
78
+ types[resource["Type"]] += 1
79
+ end
80
+ types
87
81
  end
88
- memoize :template_output
89
82
  end
90
83
  end
data/lib/lono/cli.rb CHANGED
@@ -10,7 +10,7 @@ module Lono
10
10
  option :quiet, type: :boolean, desc: "silence the output"
11
11
  opts.clean
12
12
  def build(blueprint)
13
- Build.new(options.merge(blueprint: blueprint, build_only: true)).all
13
+ Lono::Builder.new(options.merge(blueprint: blueprint, build_only: true)).all
14
14
  end
15
15
 
16
16
  desc "bundle", "Bundle with Lonofile."
@@ -32,6 +32,12 @@ module Lono
32
32
  Lono::Cfn::Delete.new(options.merge(blueprint: blueprint)).run
33
33
  end
34
34
 
35
+ desc "iam BLUEPRINT", "Generate IAM policy"
36
+ long_desc Help.text(:down)
37
+ def iam(blueprint)
38
+ Iam.new(options.merge(blueprint: blueprint)).run
39
+ end
40
+
35
41
  desc "list", "List blueprints"
36
42
  long_desc Help.text(:list)
37
43
  option :type, aliases: :t, desc: "Type: IE: blueprint, configset, extension. Defaults to all"
@@ -41,7 +47,7 @@ module Lono
41
47
 
42
48
  desc "output BLUEPRINT", "output or preview of the deploy"
43
49
  long_desc Help.text(:output)
44
- option :format, desc: "Output formats: #{CliFormat.formats.join(', ')}"
50
+ option :format, aliases: :f, desc: "Output formats: #{CliFormat.formats.join(', ')}"
45
51
  def output(blueprint)
46
52
  Lono::Cfn::Output.new(options.merge(blueprint: blueprint)).run
47
53
  end
@@ -77,7 +83,7 @@ module Lono
77
83
  desc "summary BLUEPRINT", "Prints summary of CloudFormation template"
78
84
  long_desc Help.text("summary")
79
85
  def summary(blueprint)
80
- Lono::Inspector::Summary.new(options.merge(blueprint: blueprint)).run
86
+ Summary.new(options.merge(blueprint: blueprint)).run
81
87
  end
82
88
 
83
89
  desc "test", "Run test."
@@ -122,10 +128,6 @@ module Lono
122
128
  long_desc Help.text(:cfn)
123
129
  subcommand "cfn", Cfn
124
130
 
125
- desc "code SUBCOMMAND", "code subcommands"
126
- long_desc Help.text(:code)
127
- subcommand "code", Code
128
-
129
131
  desc "new SUBCOMMAND", "new subcommands"
130
132
  long_desc Help.text(:new)
131
133
  subcommand "new", New
data/lib/lono/command.rb CHANGED
@@ -37,6 +37,7 @@ module Lono
37
37
  # Lono.argv provides consistency when lono is being called by rspec-lono test harness
38
38
  Lono.argv = args.clone # important to clone since Thor removes the first argv
39
39
 
40
+ check_version_structure!
40
41
  check_project!(args.first)
41
42
 
42
43
  # Allow calling for help via:
@@ -68,13 +69,39 @@ module Lono
68
69
  return if subcommand?
69
70
  return if command_name.nil?
70
71
  return if help_flags.include?(Lono.argv.last) # IE: -h help
71
- return if %w[-h -v --version completion completion_script help new test version].include?(command_name)
72
+ return if non_project_command?
72
73
  return if File.exist?("#{Lono.root}/config/app.rb")
73
74
  return unless Lono.check_project
74
75
  logger.error "ERROR: It doesnt look like this is a lono project. Are you sure you are in a lono project?".color(:red)
75
76
  ENV['LONO_TEST'] ? raise : exit(1)
76
77
  end
77
78
 
79
+ # Also, using ARGV instead of args because args is called by thor in multiple passes
80
+ # For `lono new project`:
81
+ # * 1st pass: "new"
82
+ # * 2nd pass: "project"
83
+ def non_project_command?
84
+ commands = %w[-h -v --version completion completion_script help new test version]
85
+ commands.include?(ARGV[0])
86
+ end
87
+
88
+ def check_version_structure!
89
+ return if non_project_command?
90
+ return unless File.exist?('configs')
91
+ puts "ERROR: Old lono project structure detected".color(:red)
92
+ puts <<~EOL
93
+ It looks like this Lono project with an old structure.
94
+ The old structure does not work with this version of Lono.
95
+
96
+ Current Installed Lono Version: #{Lono::VERSION}
97
+
98
+ Please upgrade the lono project structure.
99
+
100
+ See: https://lono.com/docs/upgrading/version8/
101
+ EOL
102
+ exit 1
103
+ end
104
+
78
105
  def help_flags
79
106
  Thor::HELP_MAPPINGS + ["help"]
80
107
  end
data/lib/lono/core.rb CHANGED
@@ -19,11 +19,21 @@ module Lono
19
19
  end
20
20
  memoize :app
21
21
 
22
+ def role
23
+ ENV['LONO_ROLE']
24
+ end
25
+ memoize :role
26
+
22
27
  def env
23
28
  ENV['LONO_ENV'] || 'dev'
24
29
  end
25
30
  memoize :env
26
31
 
32
+ def extra
33
+ ENV['LONO_EXTRA']
34
+ end
35
+ memoize :extra
36
+
27
37
  def tmp_root
28
38
  ENV['LONO_TMP_ROOT'] || "/tmp/lono"
29
39
  end
@@ -1,13 +1,11 @@
1
1
  require 'shellwords'
2
2
 
3
- module Lono::Utils
3
+ class Lono::Files::Builder::LambdaLayer
4
4
  module Rsync
5
- include Lono::Utils::Logging
6
-
7
5
  def sh(command)
8
- logger.info "=> #{command}"
6
+ logger.debug "=> #{command}"
9
7
  out = `#{command}`
10
- logger.info out if ENV['LONO_DEBUG_SH']
8
+ logger.debug out
11
9
  success = $?.success?
12
10
  raise("ERROR: running command #{command}").color(:red) unless success
13
11
  success