lono 8.0.0.pre.rc4 → 8.0.0.pre.rc5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 963246c282376afe61a61f60ad1ec0ccb17ee194420d972802868f8574fbc97a
4
- data.tar.gz: 3e8b4c478d5ee57744ff05ad45023592dffab08825a5af2e044a8656680b0512
3
+ metadata.gz: 060b7af587a3c5cf93ccbd9c5f7431d987b3198c4fdd1477978f196107d80bce
4
+ data.tar.gz: 67007f1e5c107869e8a40a125d25a578153ade317c93a8cec52b340ad7a1821b
5
5
  SHA512:
6
- metadata.gz: f8ea0aa2e31ea1dad60b69d7993ef1b6eb9781c1ee0d04770ed2a1eb0fec9387703e79b95faf1a04918685d147ff884a7f712420891dbb50f9091bdf3439fa9b
7
- data.tar.gz: f73dd80095b287c9be478a68c4de4181fdd0657153d69dc0c72145497555a7c542096e8bd0fb5b85877589251d878cd2dee7cace277614917dcab383991de30f
6
+ metadata.gz: '075091a4124f123f1d1fa7d98558c3b55c2fc83c0bbfe5c60b417d4f2d09f9334d2999ff4c3a2915f80f221edd17161fdc387a9b84b65eae9e0d84de35fd95c8'
7
+ data.tar.gz: 11d2770339bcd8723984d837413b663016c04350dcca587479a616e1cb44a6c7f2df3868f44e713141fd8c032ba384f61b65749df3a17a6d9a7b52fe393856a3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## [8.0.0.rc5] - 2022-04-29
4
+
5
+ * #76 fix plan: upload template to s3
6
+ * #75 user_data helper improvements
7
+ * Improve lono error reported to use with better call line backtrace
8
+ * load helpers before variables so they're available in vars files
9
+ * vpc helper returns object
10
+
3
11
  ## [8.0.0.rc4] - 2022-03-19
4
12
 
5
13
  Notable:
@@ -3,8 +3,8 @@ class Lono::Builder
3
3
  include DslEvaluator
4
4
 
5
5
  def load_context
6
+ load_helpers # load helpers before variable so user custom helpers are available in vars files
6
7
  load_variables
7
- load_helpers
8
8
  end
9
9
 
10
10
  # Variables in base.rb are overridden by their environment specific variables
@@ -2,12 +2,25 @@ module Lono::Builder::Dsl::Helpers
2
2
  module Ec2
3
3
  extend Memoist
4
4
 
5
+ # Returns vpc object
6
+ def vpc(name)
7
+ filters = name == "default" ?
8
+ [name: "isDefault", values: ["true"]] :
9
+ [name: "tag:Name", values: [name]]
10
+ resp = ec2.describe_vpcs(filters: filters)
11
+ resp.vpcs.first
12
+ end
13
+ memoize :vpc
14
+
5
15
  def default_vpc
6
- resp = ec2.describe_vpcs(filters: [name: "isDefault", values: ["true"]])
7
- vpc = resp.vpcs.first
16
+ vpc = vpc("default")
8
17
  vpc ? vpc.vpc_id : "no default vpc found"
9
18
  end
10
- memoize :default_vpc
19
+
20
+ def default_vpc_cidr
21
+ vpc = vpc("default")
22
+ vpc.cidr_block
23
+ end
11
24
 
12
25
  def default_subnets
13
26
  return "no default subnets because no default vpc found" if default_vpc == "no default vpc found"
@@ -1,66 +1,48 @@
1
1
  module Lono::Builder::Dsl::Helpers
2
2
  module TemplateFile
3
3
  extend Memoist
4
+ include Lono::Utils::CallLine
4
5
  include Lono::Utils::Pretty
5
6
 
7
+ # Do not memoize :template_file - it'll hide the template_file_missing error
6
8
  def template_file(path)
7
- path = "#{@blueprint.root}/#{path}"
9
+ path = "#{@blueprint.root}/#{path}" unless path.starts_with?('/')
8
10
  if File.exist?(path)
9
- render_file(path)
11
+ RenderMePretty.result(path, context: self)
10
12
  else
11
13
  template_file_missing(path)
12
14
  end
13
15
  end
14
- # do not memoize :template_file - it'll hide the template_file_missing error
16
+ alias_method :render_file, :template_file
17
+ alias_method :render_path, :template_file
18
+ alias_method :user_data, :template_file
19
+ alias_method :content, :template_file
20
+
15
21
 
16
22
  # Caller lines are different for OSes:
17
23
  #
18
24
  # windows: "C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/lono-1.1.1/lib/lono/builder.rb:34:in `build'"
19
25
  # linux: "/home/ec2-user/.rvm/gems/ruby-3.0.3/gems/lono-1.1.1/lib/lono/compiler/dsl/syntax/mod.rb:4:in `<module:Mod>'"
20
26
  #
21
- class TempleFileNotFoundError < StandardError; end
22
27
  def template_file_missing(path)
23
- message = "ERROR: path #{pretty_path(path)} not found"
24
- caller_line = caller.find { |l| l =~ %r{/blueprints/} }
25
- logger.error message.color(:red)
26
- logger.error "Called from:"
27
- logger.error " #{pretty_path(caller_line)}"
28
- # Raise an error so Dsl::Evaluator#template_evaluation_error provides user friendly info
29
- raise TempleFileNotFoundError.new
30
- end
31
-
32
- def render_file(path)
33
- if File.exist?(path)
34
- RenderMePretty.result(path, context: self)
35
- else
36
- lines = caller.select { |l| l.include?(Lono.root.to_s) }
37
- caller_line = pretty_path(lines.first)
38
- message =<<~EOL
39
- WARN: #{pretty_path(path)} does not exist
40
- Called from: #{caller_line}
41
- EOL
42
- logger.info message.color(:yellow)
43
- message
44
- end
28
+ logger.warn "WARN: File path not found: #{pretty_path(path)}".color(:yellow)
29
+ call_line = lono_call_line
30
+ DslEvaluator.print_code(call_line) # returns true right now
31
+ ""
45
32
  end
46
- alias_method :render_path, :render_file
47
33
 
48
34
  def user_data_script
49
- unless @user_data_script
50
- script_example = pretty_path("#{@blueprint.root}/template/user_data.sh")
35
+ path = @user_data_script || @user_data_script_path
36
+ unless path
37
+ # script_example = pretty_path("#{@blueprint.root}/template/bootstrap.sh")
38
+ script_example = "bootstrap.sh"
51
39
  return <<~EOL
52
- # @user_data_script variable not set. IE: @user_data_script = "#{script_example}"
40
+ # @user_data_script_path variable not set. IE: @user_data_script_path = "#{script_example}"
53
41
  # Also, make sure that "#{script_example}" exists.
54
42
  EOL
55
43
  end
56
-
57
- if File.exist?(@user_data_script)
58
- render_file(@user_data_script)
59
- else
60
- message = "WARN: #{@user_data_script} not found"
61
- logger.info message.color(:yellow)
62
- "# #{message}"
63
- end
44
+ user_data(path)
64
45
  end
46
+ alias_method :user_data_script_path, :user_data_script
65
47
  end
66
48
  end
@@ -2,10 +2,12 @@ class Lono::Builder
2
2
  class Param < Lono::CLI::Base
3
3
  attr_reader :env_path, :base_path # set when build is called
4
4
  include Lono::Builder::Dsl::Syntax
5
+ include Lono::Builder::Context
5
6
  # Overriding output resource DSL method
6
7
  alias_method :output, :stack_output
7
8
 
8
9
  def build
10
+ load_context
9
11
  logger.info "Building parameters"
10
12
 
11
13
  contents = []
@@ -3,7 +3,7 @@ class Lono::Cfn::Deploy
3
3
  def check!
4
4
  status = stack_status
5
5
  unless status =~ /_COMPLETE$/ || status == "UPDATE_ROLLBACK_FAILED"
6
- logger.info "Cannot create run operation on stack #{@stack} is not in an updatable state. Stack status: #{status}".color(:red)
6
+ logger.info "Cannot run operation on stack #{@stack} is not in an updatable state. Stack status: #{status}".color(:red)
7
7
  quit 1
8
8
  end
9
9
  end
@@ -59,7 +59,6 @@ module Lono::Cfn
59
59
  opts = Opts.new(@blueprint, "create_stack", iam, options)
60
60
  opts.show
61
61
  options = opts.values
62
- upload_all
63
62
  cfn.create_stack(options)
64
63
  end
65
64
 
@@ -70,33 +69,11 @@ module Lono::Cfn
70
69
  end
71
70
 
72
71
  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
75
72
  changeset = plan.for_update
76
73
  !changeset.changed? || @sure || sure?("Are you sure you want to update the #{@stack} stack?")
77
74
  changeset.execute_change_set
78
75
  end
79
76
 
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
-
89
- # Upload files right before create_stack or execute_change_set
90
- # Its better to upload here as part of a deploy vs a build
91
- # IE: lono build should try not to do a remote write to s3 if possible
92
- def upload_files
93
- # Files built and compressed in
94
- # Lono::Builder::Dsl::Finalizer::Files::Build#build_files
95
- Lono::Files.files.each do |file| # using singular file, but is like a "file_list"
96
- file.upload
97
- end
98
- end
99
-
100
77
  def create?
101
78
  !stack_exists?(@stack)
102
79
  end
data/lib/lono/cfn/plan.rb CHANGED
@@ -10,6 +10,7 @@ module Lono::Cfn
10
10
  end
11
11
 
12
12
  def for_update
13
+ upload_all
13
14
  # Allow passing down of the build object from Cfn::Deploy so build.all only runs once.
14
15
  # Fallback to creating new build object but still pass one build object instance down.
15
16
  @options[:build] ||= build
@@ -24,11 +25,35 @@ module Lono::Cfn
24
25
  end
25
26
 
26
27
  def for_create
28
+ upload_all
27
29
  New.new(@options).run
28
30
  end
29
31
 
30
32
  def for_delete
31
33
  Delete.new(@options).run
32
34
  end
35
+
36
+ # important to call before for_update and for_create
37
+ # since changeset requires the template to already be uploaded to s3
38
+ def upload_all
39
+ upload_templates
40
+ upload_files
41
+ end
42
+
43
+ def upload_templates
44
+ Lono::Builder::Template::Upload.new(@options).run
45
+ end
46
+
47
+ # Upload files right before create_stack or execute_change_set
48
+ # Its better to upload here as part of a deploy vs a build
49
+ # IE: lono build should try not to do a remote write to s3 if possible
50
+ def upload_files
51
+ # Files built and compressed in
52
+ # Lono::Builder::Dsl::Finalizer::Files::Build#build_files
53
+ Lono::Files.files.each do |file| # using singular file, but is like a "file_list"
54
+ file.upload
55
+ end
56
+ end
57
+
33
58
  end
34
59
  end
@@ -0,0 +1,9 @@
1
+ module Lono::Utils
2
+ module CallLine
3
+ include Pretty
4
+
5
+ def lono_call_line
6
+ caller.find { |l| l.include?(Lono.root.to_s) }
7
+ end
8
+ end
9
+ end
data/lib/lono/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lono
2
- VERSION = "8.0.0-rc4"
2
+ VERSION = "8.0.0-rc5"
3
3
  end
@@ -2,10 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  # gem "lono", "~> <%= Lono::VERSION %>"
4
4
 
5
- if ENV['C9_USER']
6
- gem "lono", path: "~/boltops-tools/lono"
7
- gem "rspec-lono", path: "~/boltops-tools/rspec-lono"
8
- else
9
- gem "lono", git: "https://github.com/boltops-tools/lono", branch: "v8"
10
- gem "rspec-lono", git: "https://github.com/boltops-tools/rspec-lono", branch: "master"
11
- end
5
+ gem "lono", git: "https://github.com/boltops-tools/lono", branch: "master"
6
+ gem "rspec-lono", git: "https://github.com/boltops-tools/rspec-lono", branch: "master"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lono
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.0.pre.rc4
4
+ version: 8.0.0.pre.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-20 00:00:00.000000000 Z
11
+ date: 2022-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -765,6 +765,7 @@ files:
765
765
  - lib/lono/seeder.rb
766
766
  - lib/lono/user_data.rb
767
767
  - lib/lono/utils.rb
768
+ - lib/lono/utils/call_line.rb
768
769
  - lib/lono/utils/logging.rb
769
770
  - lib/lono/utils/pretty.rb
770
771
  - lib/lono/utils/quit.rb
@@ -807,7 +808,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
807
808
  - !ruby/object:Gem::Version
808
809
  version: 1.3.1
809
810
  requirements: []
810
- rubygems_version: 3.2.32
811
+ rubygems_version: 3.3.12
811
812
  signing_key:
812
813
  specification_version: 4
813
814
  summary: 'Lono: The CloudFormation Framework'