jets 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80c5f0edcf627cb62ec53f7db4daac61b8b6f917d455e7c89c232fdb9c3dcfb9
4
- data.tar.gz: bba8a0fd1a5d236142183032b4831ccfaaad6f13d54da14a17523ddb594131c5
3
+ metadata.gz: edcc031b3ecbf752200590a6b964983604f0fd95e15d0270abe26341a3013cfe
4
+ data.tar.gz: 2b12ab8e0dcd3d7ad5cddb5169a32b189968d946ccc8fbe059dd0a3e37541f3d
5
5
  SHA512:
6
- metadata.gz: 799c0964c8c2dca73780688ca0fd648ce659aa23882918694504151d340d0a499dceb8850b91d5ff007c712dbdce830c5857763bf991d4a7a0075a35e4c0bf48
7
- data.tar.gz: 0c3197ba7f2914a12e4fa919dd08d629b56bc3c08d56942a4c372c53373441a632e0223810719f34d90d0a41bae0c8adbf36eb5173d86c0fc2e15df8bfc4f708
6
+ metadata.gz: 778038a7c6b3d5deb3e78d65061095ffa2c52add54d66aba17abdf1feefcea29e37a9f673eb96ced091f5d58ece36781ac7e72e12e0a4bc99f542f0046d6038d
7
+ data.tar.gz: f6e6aebfe968362c36083e3dc6d60a4ace9772a6135aff0bfc7e138618f43050503010014ad61d1c12425b4f071fd7fca2cdea4797ab3f82da1ead1c98da3977
@@ -3,6 +3,15 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [2.3.1]
7
+ - #378 use JETS_TEST=1 env var instead of TEST=1 and favor Jets.env.test? method
8
+ - #382 associated resources support for controllers
9
+ - #383 add jets and code version to parent template description
10
+ - #384 upload template to s3
11
+ - #386 Allow Jets.once to be called in simple function
12
+ - #387 remove .bundle/config instead of BUNDLE_IGNORE_CONFIG=1
13
+ - allow accidental mount at / to work also
14
+
6
15
  ## [2.3.0]
7
16
  - #377 routes mount support
8
17
 
@@ -5,7 +5,7 @@ module Jets
5
5
  include AwsServices
6
6
 
7
7
  def region
8
- return 'us-east-1' if test?
8
+ return 'us-east-1' if Jets.env.test?
9
9
 
10
10
  return ENV['JETS_AWS_REGION'] if ENV['JETS_AWS_REGION'] # highest precedence
11
11
  return ENV['AWS_REGION'] if ENV['AWS_REGION']
@@ -48,7 +48,7 @@ module Jets
48
48
 
49
49
  # aws sts get-caller-identity
50
50
  def account
51
- return '123456789' if test?
51
+ return '123456789' if Jets.env.test?
52
52
  return ENV['JETS_AWS_ACCOUNT'] if ENV['JETS_AWS_ACCOUNT']
53
53
 
54
54
  # ensure region set, required for sts.get_caller_identity.account to work
@@ -70,7 +70,7 @@ module Jets
70
70
  BUCKET_DOES_NOT_YET_EXIST = "bucket-does-not-yet-exist" # use const to save from misspellings
71
71
  @@s3_bucket = BUCKET_DOES_NOT_YET_EXIST
72
72
  def s3_bucket
73
- return "fake-test-s3-bucket" if ENV['TEST']
73
+ return "fake-test-s3-bucket" if Jets.env.test?
74
74
  return @@s3_bucket unless @@s3_bucket == BUCKET_DOES_NOT_YET_EXIST
75
75
 
76
76
  resp = cfn.describe_stacks(stack_name: Jets::Naming.parent_stack_name)
@@ -90,10 +90,6 @@ module Jets
90
90
  BUCKET_DOES_NOT_YET_EXIST
91
91
  end
92
92
 
93
- def test?
94
- ENV['TEST'] || Jets.env.test?
95
- end
96
-
97
93
  private
98
94
 
99
95
  # Cross-platform way of finding an executable in the $PATH.
@@ -3,7 +3,7 @@ module Jets::AwsServices
3
3
  # Only cache if it is true because the initial deploy checks live status until a stack exists.
4
4
  @@stack_exists_cache = [] # helps with CloudFormation rate limit
5
5
  def stack_exists?(stack_name)
6
- return false if ENV['TEST']
6
+ return false if Jets.env.test?
7
7
  return true if ENV['JETS_BUILD_NO_INTERNET']
8
8
  return true if @@stack_exists_cache.include?(stack_name)
9
9
 
@@ -36,7 +36,7 @@ module Jets::Builders
36
36
  say "Total Package: #{megabytes(total_size)}"
37
37
  say "Over limit by: #{megabytes(overlimit)}"
38
38
  say "Sometimes blowing away the /tmp/jets cache will reduce the size: rm -rf /tmp/jets"
39
- # sh "du -kcsh #{stage_area}/*" unless ENV['TEST'] # uncomment to debug
39
+ # sh "du -kcsh #{stage_area}/*" unless Jets.env.test? # uncomment to debug
40
40
  end
41
41
 
42
42
  def compute_size(path)
@@ -51,7 +51,7 @@ module Jets::Builders
51
51
  end
52
52
 
53
53
  def say(message)
54
- puts message unless ENV['TEST']
54
+ puts message unless Jets.env.test?
55
55
  end
56
56
  end
57
57
  end
@@ -50,11 +50,19 @@ module Jets::Builders
50
50
  # Uncomment out to always remove the cache/vendor/gems to debug
51
51
  # FileUtils.rm_rf("#{cache_area}/vendor/gems")
52
52
 
53
+ # Remove .bundle folder so .bundle/config doesnt affect how Jets packages gems.
54
+ # Not using BUNDLE_IGNORE_CONFIG=1 to allow home ~/.bundle/config to affect bundling though.
55
+ # This is useful if you have private gems sources that require authentication. Example:
56
+ #
57
+ # bundle config gems.myprivatesource.com user:pass
58
+ #
59
+
60
+ FileUtils.rm_rf("#{cache_area}/.bundle")
53
61
  require "bundler" # dynamically require bundler so user can use any bundler
54
62
  Bundler.with_clean_env do
55
63
  sh(
56
64
  "cd #{cache_area} && " \
57
- "env BUNDLE_IGNORE_CONFIG=1 bundle install --path #{cache_area}/vendor/gems --without development test"
65
+ "env bundle install --path #{cache_area}/vendor/gems --without development test"
58
66
  )
59
67
  end
60
68
 
@@ -11,6 +11,7 @@ module Jets::Cfn::Builders
11
11
  add_api_gateway_parameters
12
12
  add_functions
13
13
  add_routes
14
+ add_resources
14
15
  end
15
16
 
16
17
  def add_api_gateway_parameters
@@ -50,6 +50,10 @@ module Jets::Cfn::Builders
50
50
  results.join("\n") + "\n"
51
51
  end
52
52
 
53
+ def add_description(desc)
54
+ @template[:Description] = desc
55
+ end
56
+
53
57
  def add_parameters(attributes)
54
58
  attributes.each do |name,value|
55
59
  add_parameter(name.to_s.camelize, Description: value)
@@ -23,6 +23,8 @@ module Jets::Cfn::Builders
23
23
  end
24
24
 
25
25
  def build_minimal_resources
26
+ add_description("Jets: #{Jets.version} Code: #{Util::Source.version}")
27
+
26
28
  # Initial s3 bucket, used to store code zipfile and templates Jets generates
27
29
  resource = Jets::Resource::S3::Bucket.new(logical_id: "s3_bucket")
28
30
  add_resource(resource)
@@ -0,0 +1,21 @@
1
+ module Jets::Cfn::Builders::Util
2
+ class Source
3
+ class << self
4
+ def version
5
+ return '' unless git_installed?
6
+ sha = sh "git rev-parse HEAD 2>/dev/null"
7
+ return '' if sha == '' # if its not a git repo, it'll be an empty string
8
+ sha[0..7]
9
+ end
10
+
11
+ private
12
+ def git_installed?
13
+ system("type git > /dev/null 2>&1")
14
+ end
15
+
16
+ def sh(command)
17
+ `#{command}`.strip
18
+ end
19
+ end
20
+ end
21
+ end
@@ -6,7 +6,6 @@ module Jets::Cfn
6
6
  def initialize(options)
7
7
  @options = options
8
8
  @parent_stack_name = Jets::Naming.parent_stack_name
9
- @template_path = Jets::Naming.parent_template_path
10
9
  end
11
10
 
12
11
  def run
@@ -75,10 +74,13 @@ module Jets::Cfn
75
74
  def stack_options
76
75
  {
77
76
  stack_name: @parent_stack_name,
78
- template_body: IO.read(@template_path),
79
77
  capabilities: capabilities, # ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]
80
78
  # disable_rollback: !@options[:rollback],
81
- }
79
+ }.merge!(template.to_h)
80
+ end
81
+
82
+ def template
83
+ @template ||= TemplateSource.new(Jets::Naming.parent_template_path, @options)
82
84
  end
83
85
 
84
86
  # check for /(_COMPLETE|_FAILED)$/ status
@@ -96,7 +96,7 @@ module Jets::Cfn
96
96
  end
97
97
 
98
98
  return if final
99
- sleep 5 unless ENV['TEST']
99
+ sleep 5 unless Jets.env.test?
100
100
  refresh_events
101
101
  end
102
102
 
@@ -0,0 +1,61 @@
1
+ module Jets::Cfn
2
+ class TemplateSource
3
+ include Jets::AwsServices
4
+
5
+ attr_reader :path
6
+
7
+ def initialize(path, options)
8
+ @path = path
9
+ @options = options
10
+ end
11
+
12
+ def body
13
+ @body ||= IO.read(path)
14
+ end
15
+
16
+ def url
17
+ @url ||= upload_file_to_s3
18
+ end
19
+
20
+ def to_h
21
+ if upload_to_s3?
22
+ from_s3
23
+ else
24
+ from_path
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def upload_to_s3?
31
+ bucket_name.present?
32
+ end
33
+
34
+ def from_s3
35
+ {
36
+ template_url: url
37
+ }
38
+ end
39
+
40
+ def from_path
41
+ {
42
+ template_body: body
43
+ }
44
+ end
45
+
46
+ def upload_file_to_s3
47
+ obj = s3_resource.bucket(bucket_name).object(s3_key)
48
+ obj.upload_file(path)
49
+
50
+ "https://s3.amazonaws.com/#{bucket_name}/#{s3_key}"
51
+ end
52
+
53
+ def bucket_name
54
+ @options[:s3_bucket]
55
+ end
56
+
57
+ def s3_key
58
+ @s3_key ||= "jets/cfn-templates/#{File.basename(path)}"
59
+ end
60
+ end
61
+ end
@@ -20,7 +20,7 @@ class Jets::Commands::Dynamodb::Migrator
20
20
  path = "#{Jets.root}/#{@path}"
21
21
  unless File.exist?(path)
22
22
  puts "Unable to find the migration file: #{path}"
23
- exit 1 unless ENV['TEST']
23
+ exit 1 unless Jets.env.test?
24
24
  end
25
25
 
26
26
  require path
@@ -1,5 +1,5 @@
1
- ENV["TEST"] = "1"
2
- ENV["JETS_ENV"] ||= "test"
1
+ ENV['JETS_TEST'] = "1"
2
+ ENV['JETS_ENV'] ||= "test"
3
3
  # Ensures aws api never called. Fixture home folder does not contain ~/.aws/credentails
4
4
  ENV['HOME'] = "spec/fixtures/home"
5
5
 
@@ -30,7 +30,7 @@ class Jets::Controller
30
30
 
31
31
  # Instance methods
32
32
  def verify_authenticity_token
33
- return true if ENV['TEST'] || request.get? || request.head?
33
+ return true if Jets.env.test? || request.get? || request.head?
34
34
 
35
35
  token = session[:authenticity_token]
36
36
  verified = !token.nil? && (token == params[:authenticity_token] || token == request.headers["x-csrf-token"])
@@ -69,7 +69,7 @@ module Jets::Controller::Middleware
69
69
  end
70
70
 
71
71
  def on_aws?(env)
72
- return false if ENV['TEST'] # usually with test we're passing in full API Gateway fixtures with the HTTP_X_AMZN_TRACE_ID
72
+ return false if Jets.env.test? # usually with test we're passing in full API Gateway fixtures with the HTTP_X_AMZN_TRACE_ID
73
73
  on_cloud9 = !!(env['HTTP_HOST'] =~ /cloud9\..*\.amazonaws\.com/)
74
74
  !!env['HTTP_X_AMZN_TRACE_ID'] && !on_cloud9
75
75
  end
@@ -38,7 +38,7 @@ class Jets::Erb
38
38
  printf("%#{spacing}d %s\n", line_number, line_content)
39
39
  end
40
40
  end
41
- exit 1 unless ENV['TEST']
41
+ exit 1 unless Jets.env.test?
42
42
  end
43
43
  end
44
44
 
@@ -34,7 +34,7 @@ class Jets::PreheatJob < ApplicationJob
34
34
  function_name = "jets-preheat_job-warm"
35
35
  event_json = JSON.dump(event)
36
36
  options = call_options(event[:quiet])
37
- Jets::Commands::Call.new(function_name, event_json, options).run unless ENV['TEST']
37
+ Jets::Commands::Call.new(function_name, event_json, options).run unless Jets.env.test?
38
38
  end
39
39
  end
40
40
  threads.each { |t| t.join }
@@ -23,7 +23,7 @@ module Jets
23
23
 
24
24
  # Makes remote call to the Lambda function.
25
25
  def warm(function_name)
26
- Jets::Commands::Call.new(function_name, '{"_prewarm": "1"}', @options).run unless ENV['TEST']
26
+ Jets::Commands::Call.new(function_name, '{"_prewarm": "1"}', @options).run unless Jets.env.test?
27
27
  end
28
28
 
29
29
  # Loop through all methods for each class and makes special prewarm call to each method.
@@ -43,7 +43,7 @@ class Jets::Processors::MainProcessor
43
43
 
44
44
  result
45
45
  rescue Exception => e
46
- unless ENV['TEST']
46
+ unless Jets.env.test?
47
47
  # Customize error message slightly so nodejs shim can process the
48
48
  # returned error message.
49
49
  # The "RubyError: " is a marker that the javascript shim scans for.
@@ -3,6 +3,7 @@ module Jets::Router::Dsl
3
3
  # The mounted class must be a Rack compatiable class
4
4
  def mount(klass, at:)
5
5
  options = {to: "jets/mount#call", mount_class: klass}
6
+ at = at[1..-1] if at.starts_with?('/') # be more forgiving if / accidentally included
6
7
  at_wildcard = at.blank? ? "*path" : "#{at}/*path"
7
8
 
8
9
  any at, options
@@ -8,7 +8,7 @@ module Jets
8
8
 
9
9
  def initialize(yaml_path=nil)
10
10
  yaml_path ||= "#{Jets.root}/handlers/data.yml"
11
- @data = YAML.load_file(yaml_path)
11
+ @data = YAML.load_file(yaml_path) if File.exist?(yaml_path)
12
12
  @s3_bucket = @data['s3_bucket']
13
13
  @rack_zip = @data['rack_zip']
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "2.3.0"
2
+ VERSION = "2.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jets
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-30 00:00:00.000000000 Z
11
+ date: 2019-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -635,9 +635,11 @@ files:
635
635
  - lib/jets/cfn/builders/parent_builder/stagger.rb
636
636
  - lib/jets/cfn/builders/rule_builder.rb
637
637
  - lib/jets/cfn/builders/shared_builder.rb
638
+ - lib/jets/cfn/builders/util/source.rb
638
639
  - lib/jets/cfn/built_template.rb
639
640
  - lib/jets/cfn/ship.rb
640
641
  - lib/jets/cfn/status.rb
642
+ - lib/jets/cfn/template_source.rb
641
643
  - lib/jets/cfn/upload.rb
642
644
  - lib/jets/cli.rb
643
645
  - lib/jets/commands/base.rb