jets 0.10.4 → 1.0.0
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 +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile.lock +12 -12
- data/README.md +4 -2
- data/exe/jets +2 -2
- data/lib/jets/application.rb +41 -5
- data/lib/jets/aws_info.rb +20 -0
- data/lib/jets/builders/code_builder.rb +201 -296
- data/lib/jets/builders/gem_replacer.rb +1 -1
- data/lib/jets/builders/handler_generator.rb +62 -43
- data/lib/jets/builders/md5.rb +55 -0
- data/lib/jets/builders/md5_zip.rb +60 -0
- data/lib/jets/builders/rack_packager.rb +29 -0
- data/lib/jets/builders/rackup_wrappers/rackup +23 -0
- data/lib/jets/builders/rackup_wrappers/rackup.rb +7 -0
- data/lib/jets/builders/reconfigure_rails/config/initializers/jets.rb +14 -0
- data/lib/jets/builders/reconfigure_rails.rb +99 -0
- data/lib/jets/builders/ruby_packager.rb +198 -0
- data/lib/jets/builders/{deducer.rb → shim_vars/app.rb} +14 -10
- data/lib/jets/builders/shim_vars/base.rb +24 -0
- data/lib/jets/builders/{shared_deducer.rb → shim_vars/shared.rb} +4 -3
- data/lib/jets/builders/shim_vars.rb +5 -0
- data/lib/jets/builders/templates/handler.js +9 -0
- data/lib/jets/builders/templates/shim.js +271 -0
- data/lib/jets/builders/tidy.rb +80 -0
- data/lib/jets/builders/util.rb +28 -0
- data/lib/jets/builders.rb +8 -2
- data/lib/jets/cfn/builders/function_builder.rb +0 -10
- data/lib/jets/cfn/builders/parent_builder.rb +7 -6
- data/lib/jets/cfn/ship.rb +9 -103
- data/lib/jets/cfn/upload.rb +139 -0
- data/lib/jets/cfn.rb +1 -0
- data/lib/jets/commands/build.rb +17 -19
- data/lib/jets/commands/deploy.rb +2 -0
- data/lib/jets/commands/help/deploy.md +2 -2
- data/lib/jets/commands/help/import/rack.md +13 -0
- data/lib/jets/commands/help/import/rails.md +11 -0
- data/lib/jets/commands/import/base.rb +39 -0
- data/lib/jets/commands/import/rack.rb +16 -0
- data/lib/jets/commands/import/rail.rb +68 -0
- data/lib/jets/commands/import/sequence.rb +68 -0
- data/lib/jets/commands/import.rb +14 -0
- data/lib/jets/commands/main.rb +2 -1
- data/lib/jets/commands/new.rb +1 -1
- data/lib/jets/commands/sequence.rb +26 -22
- data/lib/jets/commands/templates/skeleton/Gemfile.tt +5 -2
- data/lib/jets/commands/templates/skeleton/README.md +11 -2
- data/lib/jets/commands/templates/skeleton/app/jobs/application_job.rb +1 -1
- data/lib/jets/commands/templates/skeleton/app/views/layouts/application.html.erb.tt +1 -1
- data/lib/jets/commands/templates/skeleton/config/application.rb.tt +12 -5
- data/lib/jets/commands/templates/skeleton/config/database.yml.tt +5 -1
- data/lib/jets/commands/templates/skeleton/config/environments/development.rb +3 -0
- data/lib/jets/commands/templates/skeleton/config/environments/production.rb +5 -0
- data/lib/jets/commands/templates/skeleton/public/{images/favicon.ico → favicon.ico} +0 -0
- data/lib/jets/commands/templates/skeleton/spec/controllers/posts_controller_spec.rb +1 -3
- data/lib/jets/commands.rb +1 -0
- data/lib/jets/controller/base.rb +1 -1
- data/lib/jets/controller/layout.rb +3 -0
- data/lib/jets/controller/params.rb +3 -2
- data/lib/jets/controller/request.rb +4 -0
- data/lib/jets/core.rb +20 -18
- data/lib/jets/core_ext/kernel.rb +9 -5
- data/lib/jets/default/application.rb +1 -1
- data/lib/jets/inflections.rb +16 -8
- data/lib/jets/internal/app/controllers/jets/public_controller.rb +17 -22
- data/lib/jets/internal/app/controllers/jets/rack_controller.rb +15 -0
- data/lib/jets/naming.rb +0 -23
- data/lib/jets/rack/hash_converter.rb +25 -0
- data/lib/jets/rack/request.rb +71 -0
- data/lib/jets/rack/server.rb +47 -0
- data/lib/jets/rack.rb +7 -0
- data/lib/jets/rails_overrides/asset_tag_helper.rb +12 -11
- data/lib/jets/resource/function.rb +13 -5
- data/lib/jets/router.rb +1 -1
- data/lib/jets/ruby_server.rb +63 -18
- data/lib/jets/server/api_gateway.rb +1 -1
- data/lib/jets/stack/resource.rb +3 -1
- data/lib/jets/version.rb +1 -1
- data/lib/jets.rb +3 -5
- metadata +34 -9
- data/lib/jets/builders/node-hello.js +0 -73
- data/lib/jets/builders/node-shim.js +0 -182
- data/lib/jets/internal/app/controllers/jets/public_controller/python/show.py +0 -47
- data/lib/jets/internal/app/controllers/jets/public_controller/python/show.pyc +0 -0
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
default: &default
|
|
2
|
-
adapter: postgresql
|
|
2
|
+
adapter: <%= @options[:database] == 'mysql' ? 'mysql2' : 'postgresql' %>
|
|
3
3
|
encoding: utf8
|
|
4
4
|
pool: <%%= ENV["DB_POOL"] || 5 %>
|
|
5
5
|
database: <%%= ENV['DB_NAME'] || '<%= @project_name %>_dev' %>
|
|
6
|
+
<% if @options[:database] == 'mysql' -%>
|
|
7
|
+
username: <%%= ENV['DB_USER'] || 'root' %>
|
|
8
|
+
<% else -%>
|
|
6
9
|
username: <%%= ENV['DB_USER'] || ENV['USER'] %>
|
|
10
|
+
<% end -%>
|
|
7
11
|
password: <%%= ENV['DB_PASS'] %>
|
|
8
12
|
host: <%%= ENV["DB_HOST"] %>
|
|
9
13
|
url: <%%= ENV['DATABASE_URL'] %> # takes higher precedence than other settings
|
|
File without changes
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
1
|
# Example:
|
|
4
|
-
#
|
|
2
|
+
# describe PostsController, type: :controller do
|
|
5
3
|
# it "index returns a success response" do
|
|
6
4
|
# event = payload("posts-index")
|
|
7
5
|
# controller = PostsController.new(event)
|
data/lib/jets/commands.rb
CHANGED
|
@@ -10,6 +10,7 @@ module Jets::Commands
|
|
|
10
10
|
autoload :Deploy, "jets/commands/deploy"
|
|
11
11
|
autoload :Dynamodb, "jets/commands/dynamodb"
|
|
12
12
|
autoload :Help, "jets/commands/help"
|
|
13
|
+
autoload :Import, "jets/commands/import"
|
|
13
14
|
autoload :Main, "jets/commands/main"
|
|
14
15
|
autoload :Markdown, "jets/commands/markdown"
|
|
15
16
|
autoload :New, "jets/commands/new"
|
data/lib/jets/controller/base.rb
CHANGED
|
@@ -18,7 +18,7 @@ class Jets::Controller
|
|
|
18
18
|
controller = new(event, context, meth)
|
|
19
19
|
|
|
20
20
|
Jets.logger.info " Event: #{event.inspect}"
|
|
21
|
-
Jets.logger.info " Parameters: #{controller.params(true).to_h.inspect}"
|
|
21
|
+
Jets.logger.info " Parameters: #{controller.params(raw: true).to_h.inspect}"
|
|
22
22
|
|
|
23
23
|
controller.run_before_actions
|
|
24
24
|
controller.send(meth)
|
|
@@ -9,12 +9,13 @@ class Jets::Controller
|
|
|
9
9
|
# 1. path parameters have highest precdence
|
|
10
10
|
# 2. query string parameters
|
|
11
11
|
# 3. body parameters
|
|
12
|
-
def params(raw
|
|
12
|
+
def params(raw: false, path_parameters: true)
|
|
13
13
|
query_string_params = event["queryStringParameters"] || {}
|
|
14
14
|
path_params = event["pathParameters"] || {}
|
|
15
15
|
params = body_params
|
|
16
16
|
.deep_merge(query_string_params)
|
|
17
|
-
|
|
17
|
+
params = params.deep_merge(path_params) if path_parameters
|
|
18
|
+
|
|
18
19
|
if raw
|
|
19
20
|
params
|
|
20
21
|
else
|
data/lib/jets/core.rb
CHANGED
|
@@ -34,15 +34,6 @@ module Jets::Core
|
|
|
34
34
|
# Ensures trailing slash
|
|
35
35
|
# Useful for appending a './' in front of a path or leaving it alone.
|
|
36
36
|
# Returns: '/path/with/trailing/slash/' or './'
|
|
37
|
-
# @@root = nil
|
|
38
|
-
# def root
|
|
39
|
-
# return @@root if @@root
|
|
40
|
-
# @@root = ENV['JETS_ROOT'].to_s
|
|
41
|
-
# @@root = '.' if @@root == ''
|
|
42
|
-
# @@root = "#{@@root}/" unless @@root.ends_with?('/')
|
|
43
|
-
# @@root = Pathname.new(@@root)
|
|
44
|
-
# end
|
|
45
|
-
|
|
46
37
|
def root
|
|
47
38
|
root = ENV['JETS_ROOT'].to_s
|
|
48
39
|
root = '.' if root == ''
|
|
@@ -107,15 +98,18 @@ module Jets::Core
|
|
|
107
98
|
|
|
108
99
|
# Skip these paths because eager loading doesnt work for them.
|
|
109
100
|
def skip_eager_load_paths?(path)
|
|
110
|
-
path =~ %r{/templates/} ||
|
|
111
|
-
path =~ %r{/version} ||
|
|
112
|
-
path =~ %r{/rails_overrides} ||
|
|
113
|
-
path =~ %r{/default/application} ||
|
|
114
|
-
path =~ %r{/internal/app} ||
|
|
115
|
-
path =~ %r{/webpacker} ||
|
|
116
101
|
path =~ %r{/cli} ||
|
|
117
102
|
path =~ %r{/core_ext} ||
|
|
118
|
-
path =~ %r{/
|
|
103
|
+
path =~ %r{/default/application} ||
|
|
104
|
+
path =~ %r{/functions} ||
|
|
105
|
+
path =~ %r{/internal/app} ||
|
|
106
|
+
path =~ %r{/jets/stack} ||
|
|
107
|
+
path =~ %r{/rackup_wrappers} ||
|
|
108
|
+
path =~ %r{/rails_overrides} ||
|
|
109
|
+
path =~ %r{/reconfigure_rails} ||
|
|
110
|
+
path =~ %r{/templates/} ||
|
|
111
|
+
path =~ %r{/version} ||
|
|
112
|
+
path =~ %r{/webpacker}
|
|
119
113
|
end
|
|
120
114
|
|
|
121
115
|
def class_mappings(class_name)
|
|
@@ -129,7 +123,7 @@ module Jets::Core
|
|
|
129
123
|
def eager_load_app
|
|
130
124
|
Dir.glob("#{Jets.root}app/**/*.rb").select do |path|
|
|
131
125
|
next if !File.file?(path) or path =~ %r{/javascript/} or path =~ %r{/views/}
|
|
132
|
-
next if path.include?('app/shared/functions')
|
|
126
|
+
next if path.include?('app/functions') || path.include?('app/shared/functions')
|
|
133
127
|
|
|
134
128
|
class_name = path
|
|
135
129
|
.sub(/\.rb$/,'') # remove .rb
|
|
@@ -163,7 +157,15 @@ module Jets::Core
|
|
|
163
157
|
end
|
|
164
158
|
|
|
165
159
|
def project_namespace
|
|
166
|
-
[config.project_name, config.short_env, config.env_extra].compact.join('-')
|
|
160
|
+
[config.project_name, config.short_env, config.env_extra].compact.join('-').gsub('_','-')
|
|
167
161
|
end
|
|
168
162
|
|
|
163
|
+
def rack?
|
|
164
|
+
path = "#{Jets.root}rack"
|
|
165
|
+
File.exist?(path) || File.symlink?(path)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def lazy_load?
|
|
169
|
+
config.ruby.lazy_load
|
|
170
|
+
end
|
|
169
171
|
end
|
data/lib/jets/core_ext/kernel.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
# Works with
|
|
1
|
+
# Works with io.rb
|
|
2
|
+
# IO.flush # flush output and write to disk for node shim
|
|
2
3
|
module Kernel
|
|
4
|
+
JETS_OUTPUT = "/tmp/jets-output.log"
|
|
3
5
|
@@io_buffer = []
|
|
4
6
|
|
|
5
7
|
# List from https://ruby-doc.org/core-2.5.1/Kernel.html
|
|
@@ -12,8 +14,8 @@ module Kernel
|
|
|
12
14
|
printf
|
|
13
15
|
putc
|
|
14
16
|
puts
|
|
15
|
-
sprintf
|
|
16
17
|
]
|
|
18
|
+
# NOTE adding sprintf produces #<%s: %s:%s/%s> with puma? So not including sprintf
|
|
17
19
|
OVERRIDE_METHODS.each do |meth|
|
|
18
20
|
# Example of generated code:
|
|
19
21
|
#
|
|
@@ -41,12 +43,14 @@ module Kernel
|
|
|
41
43
|
# Rescue and discard it to keep the process alive.
|
|
42
44
|
def io_flush
|
|
43
45
|
chunk = @@io_buffer.join("\n")
|
|
46
|
+
chunk += "\n" unless chunk == ''
|
|
44
47
|
begin
|
|
45
|
-
|
|
48
|
+
# since we always append to the file, the node shim is responsible for truncating the file
|
|
49
|
+
IO.write(JETS_OUTPUT, chunk, mode: 'a') if chunk
|
|
46
50
|
# Writing to log with binary content will crash the process so rescuing it and writing an info message.
|
|
47
51
|
rescue Encoding::UndefinedConversionError
|
|
48
|
-
IO.write(
|
|
52
|
+
IO.write(JETS_OUTPUT, "[BINARY DATA]\n", mode: 'a')
|
|
49
53
|
end
|
|
50
54
|
@@io_buffer = []
|
|
51
55
|
end
|
|
52
|
-
end
|
|
56
|
+
end
|
|
@@ -15,7 +15,7 @@ Jets.application.configure do
|
|
|
15
15
|
|
|
16
16
|
# function properties defaults
|
|
17
17
|
config.function = ActiveSupport::OrderedOptions.new
|
|
18
|
-
config.function.timeout =
|
|
18
|
+
config.function.timeout = 30
|
|
19
19
|
# default memory setting based on:
|
|
20
20
|
# https://medium.com/epsagon/how-to-make-lambda-faster-memory-performance-benchmark-be6ebc41f0fc
|
|
21
21
|
config.function.memory_size = 1536
|
data/lib/jets/inflections.rb
CHANGED
|
@@ -3,21 +3,29 @@ module Jets
|
|
|
3
3
|
class << self
|
|
4
4
|
def load!
|
|
5
5
|
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
end
|
|
9
|
-
# Users can add custom inflections
|
|
10
|
-
Jets.config.inflections.irregular.each do |k,v|
|
|
11
|
-
inflect.irregular k,v
|
|
12
|
-
end
|
|
6
|
+
load(inflect, base)
|
|
7
|
+
load(inflect, custom)
|
|
13
8
|
end
|
|
14
9
|
end
|
|
15
10
|
|
|
16
|
-
def
|
|
11
|
+
def load(inflect, inflections)
|
|
12
|
+
inflections.each do |k,v|
|
|
13
|
+
inflect.irregular k,v
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# base custom inflections
|
|
18
|
+
def base
|
|
17
19
|
{
|
|
18
20
|
sns: 'sns'
|
|
19
21
|
}
|
|
20
22
|
end
|
|
23
|
+
|
|
24
|
+
# User defined custom inflections
|
|
25
|
+
def custom
|
|
26
|
+
path = "#{Jets.root}config/inflections.yml"
|
|
27
|
+
File.exist?(path) ? YAML.load_file(path) : {}
|
|
28
|
+
end
|
|
21
29
|
end
|
|
22
30
|
end
|
|
23
31
|
end
|
|
@@ -5,32 +5,27 @@ class Jets::PublicController < Jets::Controller::Base
|
|
|
5
5
|
layout false
|
|
6
6
|
internal true
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def show
|
|
13
|
-
catchall = params[:catchall].blank? ? 'index.html' : params[:catchall]
|
|
14
|
-
public_path = Jets.root + "public"
|
|
15
|
-
catchall_path = "#{public_path}/#{catchall}"
|
|
8
|
+
def show
|
|
9
|
+
catchall = params[:catchall].blank? ? 'index.html' : params[:catchall]
|
|
10
|
+
public_path = Jets.root + "public"
|
|
11
|
+
catchall_path = "#{public_path}/#{catchall}"
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
if File.exist?(catchall_path)
|
|
14
|
+
content_type = Rack::Mime.mime_type(File.extname(catchall_path))
|
|
15
|
+
binary = !MimeMagic.by_path(catchall_path).text?
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
else
|
|
29
|
-
render file: catchall_path, content_type: content_type
|
|
30
|
-
end
|
|
17
|
+
# For binary support to work, the client also has to send the right Accept header.
|
|
18
|
+
# And the media type has been to added to api gateway.
|
|
19
|
+
# Cavaet: adding * to as the media type breaks regular form submission.
|
|
20
|
+
# All form submission gets treated as binary.
|
|
21
|
+
if binary
|
|
22
|
+
encoded_content = Base64.encode64(IO.read(catchall_path))
|
|
23
|
+
render plain: encoded_content, content_type: content_type, base64: true
|
|
31
24
|
else
|
|
32
|
-
render file:
|
|
25
|
+
render file: catchall_path, content_type: content_type
|
|
33
26
|
end
|
|
27
|
+
else
|
|
28
|
+
render file: "#{public_path}/404", status: 404
|
|
34
29
|
end
|
|
35
30
|
end
|
|
36
31
|
end
|
data/lib/jets/naming.rb
CHANGED
|
@@ -45,28 +45,5 @@ class Jets::Naming
|
|
|
45
45
|
def gateway_api_name
|
|
46
46
|
"#{Jets.config.project_namespace}"
|
|
47
47
|
end
|
|
48
|
-
|
|
49
|
-
def code_s3_key
|
|
50
|
-
md5_zipfile = File.basename(md5_code_zipfile)
|
|
51
|
-
"jets/code/#{md5_zipfile}"
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# build was already ran and that a file that contains the md5 path exists
|
|
55
|
-
# at Jets.build_root/code/current-md5-filename.txt
|
|
56
|
-
#
|
|
57
|
-
# md5_code_zipfile: /tmp/jets/demo/code/code-2e0e18f6.zip
|
|
58
|
-
def md5_code_zipfile
|
|
59
|
-
path = "#{Jets.build_root}/code/current-md5-filename.txt"
|
|
60
|
-
File.exist?(path) ? IO.read(path) : "current-md5-filename-doesnt-exist"
|
|
61
|
-
end
|
|
62
|
-
# The current-md5-filename.txt gets created as a part of CodeBuilder's build
|
|
63
|
-
# process.
|
|
64
|
-
# And is required to be used much later for cfn/ship and base_child_builder
|
|
65
|
-
# They need set an s3_key which requires the md5_zip_dest.
|
|
66
|
-
# It is a pain to pass this all the way up from the
|
|
67
|
-
# CodeBuilder class.
|
|
68
|
-
# We store the "/tmp/jets/demo/code/code-a8a604aa.zip" into a
|
|
69
|
-
# file that can be read from any places where this is needed.
|
|
70
|
-
# Can also just generate a "fake file" for specs
|
|
71
48
|
end
|
|
72
49
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Thanks https://mensfeld.pl/2012/01/converting-nested-hash-into-http-url-params-hash-version-in-ruby/
|
|
2
|
+
module Jets::Rack
|
|
3
|
+
module HashConverter
|
|
4
|
+
def self.encode(value, key = nil, out_hash = {})
|
|
5
|
+
case value
|
|
6
|
+
when Hash then
|
|
7
|
+
value.each { |k,v| encode(v, append_key(key,k), out_hash) }
|
|
8
|
+
out_hash
|
|
9
|
+
when Array then
|
|
10
|
+
value.each { |v| encode(v, "#{key}[]", out_hash) }
|
|
11
|
+
out_hash
|
|
12
|
+
when nil then ''
|
|
13
|
+
else
|
|
14
|
+
out_hash[key] = value
|
|
15
|
+
out_hash
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def self.append_key(root_key, key)
|
|
22
|
+
root_key.nil? ? :"#{key}" : :"#{root_key}[#{key.to_s}]"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
|
|
3
|
+
module Jets::Rack
|
|
4
|
+
class Request
|
|
5
|
+
def initialize(event, controller)
|
|
6
|
+
@event = event
|
|
7
|
+
@controller = controller # Jets::Controller instance
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def process
|
|
11
|
+
http_method = @event['httpMethod'] # GET, POST, PUT, DELETE, etc
|
|
12
|
+
params = @controller.params(raw: true, path_parameters: false)
|
|
13
|
+
|
|
14
|
+
uri = URI("http://localhost:9292#{@controller.request.path}") # local rack server
|
|
15
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
16
|
+
|
|
17
|
+
# Rails sets _method=patch or _method=put as workaround
|
|
18
|
+
# Falls back to GET when testing in lambda console
|
|
19
|
+
http_class = params['_method'] || http_method || 'GET'
|
|
20
|
+
http_class.capitalize!
|
|
21
|
+
|
|
22
|
+
request_class = "Net::HTTP::#{http_class}".constantize # IE: Net::HTTP::Get
|
|
23
|
+
request = request_class.new(@controller.request.path)
|
|
24
|
+
if %w[Post Patch Put].include?(http_class)
|
|
25
|
+
params = HashConverter.encode(params)
|
|
26
|
+
request.set_form_data(params)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
request = set_headers!(request)
|
|
30
|
+
|
|
31
|
+
# TODO: handle binary
|
|
32
|
+
response = http.request(request)
|
|
33
|
+
{
|
|
34
|
+
status: response.code.to_i,
|
|
35
|
+
headers: response.each_header.to_h,
|
|
36
|
+
body: response.body,
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Set request headers. Forwards original request info from remote API gateway.
|
|
41
|
+
# By this time, the server/api_gateway.rb middleware.
|
|
42
|
+
def set_headers!(request)
|
|
43
|
+
headers = @event['headers'] # from api gateway
|
|
44
|
+
if headers # remote API Gateway
|
|
45
|
+
# Forward headers from API Gateway over to the sub http request.
|
|
46
|
+
# It's important to forward the headers. Here are some examples:
|
|
47
|
+
#
|
|
48
|
+
# "Turbolinks-Referrer"=>"http://localhost:8888/posts/122",
|
|
49
|
+
# "Referer"=>"http://localhost:8888/posts/122",
|
|
50
|
+
# "Accept-Encoding"=>"gzip, deflate",
|
|
51
|
+
# "Accept-Language"=>"en-US,en;q=0.9,pt;q=0.8",
|
|
52
|
+
# "Cookie"=>"_demo_session=...",
|
|
53
|
+
# "If-None-Match"=>"W/\"9fa479205fc6d24ca826d46f1f6cf461\"",
|
|
54
|
+
headers.each do |k,v|
|
|
55
|
+
request[k] = v
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Note by the time headers get to rack later in the they get changed to:
|
|
59
|
+
#
|
|
60
|
+
# request['X-Forwarded-Host'] vs env['HTTP_X_FORWARDED_HOST']
|
|
61
|
+
#
|
|
62
|
+
request['X-Forwarded-For'] = headers['X-Forwarded-For'] # "1.1.1.1, 2.2.2.2" # can be comma separated list
|
|
63
|
+
request['X-Forwarded-Host'] = headers['Host'] # uhghn8z6t1.execute-api.us-east-1.amazonaws.com
|
|
64
|
+
request['X-Forwarded-Port'] = headers['X-Forwarded-Port'] # 443
|
|
65
|
+
request['X-Forwarded-Proto'] = headers['X-Forwarded-Proto'] # https # scheme
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
request
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
|
|
3
|
+
module Jets::Rack
|
|
4
|
+
class Server
|
|
5
|
+
def self.start
|
|
6
|
+
new.start
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def start
|
|
10
|
+
puts "Jets::Rack#start"
|
|
11
|
+
return unless File.exist?("#{rack_project}/config.ru")
|
|
12
|
+
puts "Starting additional rack server for the project under the rack subfolder..." if ENV['JETS_DEBUG']
|
|
13
|
+
|
|
14
|
+
if ENV['FOREGROUND']
|
|
15
|
+
serve
|
|
16
|
+
return
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Reaching here means we'll run the server in the background.
|
|
20
|
+
# Handle daemonzing ourselves because it keeps the stdout of the 2nd
|
|
21
|
+
# rack server. The rackup --daemonize option ends up hiding the output.
|
|
22
|
+
pid = Process.fork
|
|
23
|
+
if pid.nil?
|
|
24
|
+
# we're in the child process
|
|
25
|
+
serve
|
|
26
|
+
else
|
|
27
|
+
# we're in the parent process
|
|
28
|
+
Process.detach(pid) # dettached but still in the "foreground" since bin/rackup runs in the foreground
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Runs in the child process
|
|
33
|
+
def serve
|
|
34
|
+
# Note, looks like stopping jets server with Ctrl-C sends the TERM signal
|
|
35
|
+
# down to the sub bin/rackup command cleans up the child process fine.
|
|
36
|
+
Bundler.with_clean_env do
|
|
37
|
+
command = "cd #{rack_project} && bin/rackup" # leads to the same wrapper rack scripts
|
|
38
|
+
puts "=> #{command}".colorize(:green)
|
|
39
|
+
system(command)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def rack_project
|
|
44
|
+
"#{Jets.root}rack"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
data/lib/jets/rack.rb
ADDED
|
@@ -5,12 +5,12 @@ module Jets::AssetTagHelper
|
|
|
5
5
|
include Jets::AwsServices
|
|
6
6
|
|
|
7
7
|
def javascript_include_tag(*sources, **options)
|
|
8
|
-
sources = sources.map { |s|
|
|
8
|
+
sources = sources.map { |s| s3_public_url(s, :javascripts) }
|
|
9
9
|
super
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def stylesheet_link_tag(*sources, **options)
|
|
13
|
-
sources = sources.map { |s|
|
|
13
|
+
sources = sources.map { |s| s3_public_url(s, :stylesheets) }
|
|
14
14
|
super
|
|
15
15
|
end
|
|
16
16
|
|
|
@@ -26,7 +26,7 @@ module Jets::AssetTagHelper
|
|
|
26
26
|
# mimic original behavior to get /images in source
|
|
27
27
|
source = "/images/#{source}" unless source.starts_with?('/')
|
|
28
28
|
if on_aws?(source)
|
|
29
|
-
source = "#{
|
|
29
|
+
source = "#{s3_public}#{source}"
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
super
|
|
@@ -36,7 +36,7 @@ module Jets::AssetTagHelper
|
|
|
36
36
|
if on_aws?(source) && asset_folder?(source)
|
|
37
37
|
# mimic original behavior to get /images in source
|
|
38
38
|
source = "/images/#{source}" unless source.starts_with?('/')
|
|
39
|
-
source = "#{
|
|
39
|
+
source = "#{s3_public}#{source}"
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
super
|
|
@@ -69,25 +69,26 @@ private
|
|
|
69
69
|
# If there's a / in front then rails will not add the "javascript":
|
|
70
70
|
# So we can add the javascript ourselves and then add the stag with a
|
|
71
71
|
# / in front.
|
|
72
|
-
def
|
|
72
|
+
def s3_public_url(url, asset_type)
|
|
73
73
|
unless url.starts_with?('/') or url.starts_with?('http')
|
|
74
74
|
url = "/#{asset_type}/#{url}" # /javascript/asset/test
|
|
75
75
|
end
|
|
76
|
-
|
|
76
|
+
add_s3_public(url)
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
# Example:
|
|
80
80
|
# Url: /packs/application-e7654c50abd78161b641.js
|
|
81
81
|
# Returns: https://s3-us-west-2.amazonaws.com/demo-dev-s3bucket-1jg5o076egkk4/jets/public/packs/application-e7654c50abd78161b641.js
|
|
82
|
-
def
|
|
82
|
+
def add_s3_public(url)
|
|
83
83
|
return url unless on_aws?(url)
|
|
84
|
-
"#{
|
|
84
|
+
"#{s3_public}#{url}"
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
-
def
|
|
87
|
+
def s3_public
|
|
88
88
|
# s3_base_url.txt is created as part of the build process
|
|
89
|
-
IO.read("#{Jets.root}config/s3_base_url.txt").strip
|
|
89
|
+
s3_base_url = IO.read("#{Jets.root}config/s3_base_url.txt").strip
|
|
90
|
+
"#{s3_base_url}/public"
|
|
90
91
|
end
|
|
91
|
-
memoize :
|
|
92
|
+
memoize :s3_public
|
|
92
93
|
end
|
|
93
94
|
ActionView::Helpers.send(:include, Jets::AssetTagHelper)
|
|
@@ -38,9 +38,16 @@ class Jets::Resource
|
|
|
38
38
|
|
|
39
39
|
def environment
|
|
40
40
|
env = Jets.config.environment ? Jets.config.environment.to_h : {}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
env.deep_merge(jets_env)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# These jets env variables are always included
|
|
45
|
+
def jets_env
|
|
46
|
+
env = {}
|
|
47
|
+
env[:JETS_ENV] = Jets.env.to_s
|
|
48
|
+
env[:JETS_ENV_EXTRA] = Jets.config.env_extra if Jets.config.env_extra
|
|
49
|
+
env[:JETS_STAGE] = Jets::Resource::ApiGateway::Deployment.stage_name
|
|
50
|
+
env
|
|
44
51
|
end
|
|
45
52
|
|
|
46
53
|
# Global properties example:
|
|
@@ -49,7 +56,7 @@ class Jets::Resource
|
|
|
49
56
|
#
|
|
50
57
|
# Jets.application.configure do
|
|
51
58
|
# config.function = ActiveSupport::OrderedOptions.new
|
|
52
|
-
# config.function.timeout =
|
|
59
|
+
# config.function.timeout = 30
|
|
53
60
|
# config.function.runtime = "nodejs8.10"
|
|
54
61
|
# config.function.memory_size = 1536
|
|
55
62
|
# end
|
|
@@ -182,7 +189,8 @@ class Jets::Resource
|
|
|
182
189
|
end
|
|
183
190
|
|
|
184
191
|
def code_s3_key
|
|
185
|
-
Jets::
|
|
192
|
+
checksum = Jets::Builders::Md5.checksums["stage/code"]
|
|
193
|
+
"jets/code/code-#{checksum}.zip" # s3_key
|
|
186
194
|
end
|
|
187
195
|
|
|
188
196
|
# Examples:
|
data/lib/jets/router.rb
CHANGED
|
@@ -30,7 +30,7 @@ module Jets
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def api_mode?
|
|
33
|
-
|
|
33
|
+
if Jets.config.key?(:api_mode) || Jets.config.key?(:api_generator)
|
|
34
34
|
puts <<~EOL.colorize(:yellow)
|
|
35
35
|
DEPRECATED: Jets.config.api_generator
|
|
36
36
|
Instead, please update your config/application.rb to use:
|