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
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
require 'action_view'
|
|
2
|
+
require 'digest'
|
|
3
|
+
|
|
4
|
+
class Jets::Cfn
|
|
5
|
+
class Upload
|
|
6
|
+
include Jets::AwsServices
|
|
7
|
+
include ActionView::Helpers::NumberHelper # number_to_human_size
|
|
8
|
+
|
|
9
|
+
attr_reader :bucket_name
|
|
10
|
+
def initialize(bucket_name)
|
|
11
|
+
@bucket_name = bucket_name
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def upload
|
|
15
|
+
upload_cfn_templates
|
|
16
|
+
upload_zip_files
|
|
17
|
+
upload_assets
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def upload_cfn_templates
|
|
21
|
+
puts "Uploading CloudFormation templates to S3."
|
|
22
|
+
expression = "#{Jets::Naming.template_path_prefix}-*"
|
|
23
|
+
Dir.glob(expression).each do |path|
|
|
24
|
+
next unless File.file?(path)
|
|
25
|
+
|
|
26
|
+
key = "jets/cfn-templates/#{File.basename(path)}"
|
|
27
|
+
obj = s3_resource.bucket(bucket_name).object(key)
|
|
28
|
+
obj.upload_file(path)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def upload_zip_files
|
|
33
|
+
puts "Uploading code zip files to S3."
|
|
34
|
+
zip_area = "#{Jets.build_root}/stage/zips"
|
|
35
|
+
Dir.glob("#{zip_area}/*").each do |file|
|
|
36
|
+
upload_zip_file(file)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def upload_zip_file(path)
|
|
41
|
+
file_size = number_to_human_size(File.size(path))
|
|
42
|
+
|
|
43
|
+
puts "Uploading #{path} (#{file_size}) to S3"
|
|
44
|
+
start_time = Time.now
|
|
45
|
+
s3_key = "jets/code/#{File.basename(path)}"
|
|
46
|
+
obj = s3_resource.bucket(bucket_name).object(s3_key)
|
|
47
|
+
obj.upload_file(path)
|
|
48
|
+
puts "Uploaded to s3://#{bucket_name}/#{s3_key}".colorize(:green)
|
|
49
|
+
puts "Time to upload code to s3: #{pretty_time(Time.now-start_time).colorize(:green)}"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def upload_assets
|
|
53
|
+
puts "Uploading modified public assets to S3."
|
|
54
|
+
start_time = Time.now
|
|
55
|
+
upload_public_assets
|
|
56
|
+
puts "Time to upload public assets to s3: #{pretty_time(Time.now-start_time).colorize(:green)}"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def upload_public_assets
|
|
60
|
+
asset_folders = Jets.config.assets.folders # IE: %w[public]
|
|
61
|
+
asset_folders = add_rack_assets(asset_folders)
|
|
62
|
+
asset_folders.each do |folder|
|
|
63
|
+
upload_asset_folder(folder)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def add_rack_assets(asset_folders)
|
|
68
|
+
return asset_folders unless Jets.rack?
|
|
69
|
+
asset_folders + %w[rack/public]
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def upload_asset_folder(folder)
|
|
73
|
+
expression = "#{Jets.root}#{folder}/**/*"
|
|
74
|
+
group_size = 10
|
|
75
|
+
Dir.glob(expression).each_slice(group_size) do |paths|
|
|
76
|
+
threads = []
|
|
77
|
+
paths.each do |full_path|
|
|
78
|
+
next unless File.file?(full_path)
|
|
79
|
+
|
|
80
|
+
threads << Thread.new do
|
|
81
|
+
upload_to_s3(full_path)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
threads.each(&:join)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def upload_to_s3(full_path)
|
|
89
|
+
return if identical_on_s3?(full_path)
|
|
90
|
+
|
|
91
|
+
key = s3_key(full_path)
|
|
92
|
+
obj = s3_resource.bucket(bucket_name).object(key)
|
|
93
|
+
puts "Uploading s3://#{bucket_name}/#{key}" # uncomment to see and debug
|
|
94
|
+
obj.upload_file(full_path, acl: "public-read", cache_control: cache_control)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def s3_key(full_path)
|
|
98
|
+
relative_path = full_path.sub(Jets.root.to_s, '')
|
|
99
|
+
"jets/#{relative_path}"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def identical_on_s3?(full_path)
|
|
103
|
+
local_md5 = ::Digest::MD5.file(full_path)
|
|
104
|
+
key = s3_key(full_path)
|
|
105
|
+
begin
|
|
106
|
+
resp = s3.head_object(bucket: bucket_name, key: key)
|
|
107
|
+
rescue Aws::S3::Errors::NotFound
|
|
108
|
+
return false
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
remote_md5 = resp.etag.delete_prefix('"').delete_suffix('"')
|
|
112
|
+
local_md5 == remote_md5
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# If cache_control is provided, then it will set the entire cache-control header.
|
|
116
|
+
# If only max_age is provided, then we'll generate a cache_control header.
|
|
117
|
+
# Using max_age is the shorter and simply way of setting the cache_control header.
|
|
118
|
+
def cache_control
|
|
119
|
+
cache_control = Jets.config.assets.cache_control
|
|
120
|
+
unless cache_control
|
|
121
|
+
max_age = Jets.config.assets.max_age # defaults to 3600 in jets/application.rb
|
|
122
|
+
cache_control = "public, max-age=#{max_age}"
|
|
123
|
+
end
|
|
124
|
+
cache_control
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# http://stackoverflow.com/questions/4175733/convert-duration-to-hoursminutesseconds-or-similar-in-rails-3-or-ruby
|
|
128
|
+
def pretty_time(total_seconds)
|
|
129
|
+
minutes = (total_seconds / 60) % 60
|
|
130
|
+
seconds = total_seconds % 60
|
|
131
|
+
if total_seconds < 60
|
|
132
|
+
"#{seconds.to_i}s"
|
|
133
|
+
else
|
|
134
|
+
"#{minutes.to_i}m #{seconds.to_i}s"
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
end
|
|
139
|
+
end
|
data/lib/jets/cfn.rb
CHANGED
data/lib/jets/commands/build.rb
CHANGED
|
@@ -31,16 +31,18 @@ module Jets::Commands
|
|
|
31
31
|
time :build_code
|
|
32
32
|
|
|
33
33
|
def build_templates
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
end
|
|
34
|
+
puts "Building CloudFormation templates."
|
|
35
|
+
clean_templates
|
|
36
|
+
build_minimal_template
|
|
37
|
+
build_all_templates if full?
|
|
39
38
|
end
|
|
40
39
|
time :build_templates
|
|
41
40
|
|
|
41
|
+
def full?
|
|
42
|
+
@options[:templates] || @options[:stack_type] == :full
|
|
43
|
+
end
|
|
44
|
+
|
|
42
45
|
def build_all_templates
|
|
43
|
-
clean_templates
|
|
44
46
|
# CloudFormation templates
|
|
45
47
|
# 1. Shared templates - child templates needs them
|
|
46
48
|
build_api_gateway_templates
|
|
@@ -103,16 +105,15 @@ module Jets::Commands
|
|
|
103
105
|
self.class.app_files
|
|
104
106
|
end
|
|
105
107
|
|
|
106
|
-
# Crucial that the Dir.pwd is in the
|
|
108
|
+
# Crucial that the Dir.pwd is in the tmp_code because for
|
|
107
109
|
# because Jets.boot set ups autoload_paths and this is how project
|
|
108
110
|
# classes are loaded.
|
|
109
|
-
# TODO: rework code so that Dir.pwd does not have to be in
|
|
111
|
+
# TODO: rework code so that Dir.pwd does not have to be in tmp_code for build to work.
|
|
110
112
|
def self.app_files
|
|
111
113
|
paths = []
|
|
112
114
|
expression = "#{Jets.root}app/**/**/*.rb"
|
|
113
115
|
Dir.glob(expression).each do |path|
|
|
114
116
|
return false unless File.file?(path)
|
|
115
|
-
next if path.include?("app/functions") # cannot lazy load these because they are anonymous classes
|
|
116
117
|
next unless app_file?(path)
|
|
117
118
|
|
|
118
119
|
relative_path = path.sub(Jets.root.to_s, '')
|
|
@@ -144,15 +145,9 @@ module Jets::Commands
|
|
|
144
145
|
def self.poly_only?
|
|
145
146
|
# Scans all the app code and look for any methods that are ruby.
|
|
146
147
|
# If any method is written in ruby then we know the app is not a
|
|
147
|
-
#
|
|
148
|
+
# solely polymorphic non-ruby app.
|
|
148
149
|
has_ruby = app_files.detect do |path|
|
|
149
|
-
|
|
150
|
-
# 2. remove .rb extension
|
|
151
|
-
app_file = path.sub(%r{app/\w+/},'').sub(/\.rb$/,'')
|
|
152
|
-
|
|
153
|
-
# Internal jets controllers like Welcome and Public need a different regexp
|
|
154
|
-
app_file = app_file.sub(%r{.*lib/jets/internal/},'')
|
|
155
|
-
app_class = app_file.classify.constantize # IE: PostsController, Jets::PublicController
|
|
150
|
+
app_class = Jets::Klass.from_path(path) # IE: PostsController, Jets::PublicController
|
|
156
151
|
langs = app_class.tasks.map(&:lang)
|
|
157
152
|
langs.include?(:ruby)
|
|
158
153
|
end
|
|
@@ -167,6 +162,9 @@ module Jets::Commands
|
|
|
167
162
|
public_catchall = Jets::Router.has_controller?("Jets::PublicController")
|
|
168
163
|
paths << "#{controllers}/public_controller.rb" if public_catchall
|
|
169
164
|
|
|
165
|
+
rack_catchall = Jets::Router.has_controller?("Jets::RackController")
|
|
166
|
+
paths << "#{controllers}/rack_controller.rb" if rack_catchall
|
|
167
|
+
|
|
170
168
|
jobs = File.expand_path("../../internal/app/jobs/jets", __FILE__)
|
|
171
169
|
paths << "#{jobs}/preheat_job.rb"
|
|
172
170
|
|
|
@@ -194,8 +192,8 @@ module Jets::Commands
|
|
|
194
192
|
false
|
|
195
193
|
end
|
|
196
194
|
|
|
197
|
-
def self.
|
|
198
|
-
full_build_path ? "#{Jets.build_root}/
|
|
195
|
+
def self.tmp_code(full_build_path=false)
|
|
196
|
+
full_build_path ? "#{Jets.build_root}/stage/code" : "stage/code"
|
|
199
197
|
end
|
|
200
198
|
|
|
201
199
|
end
|
data/lib/jets/commands/deploy.rb
CHANGED
|
@@ -21,6 +21,8 @@ module Jets::Commands
|
|
|
21
21
|
exit_unless_updateable! # Stack could be in a weird rollback state or in progress state
|
|
22
22
|
ship(stack_type: :minimal) if first_run?
|
|
23
23
|
|
|
24
|
+
Jets.application.reload_iam_policy!
|
|
25
|
+
|
|
24
26
|
# Build code after the minimal stack because need s3 bucket for assets
|
|
25
27
|
# on_aws? and s3_base_url logic
|
|
26
28
|
build_code
|
|
@@ -15,7 +15,7 @@ This builds the project and deploys it AWS Lambda. The deployment is mainly hand
|
|
|
15
15
|
=> Replacing compiled gems with AWS Lambda Linux compiled versions.
|
|
16
16
|
Creating zip file.
|
|
17
17
|
=> cd /tmp/jets/demo/app_root && zip --symlinks -rq /tmp/jets/demo/code/code-temp.zip .
|
|
18
|
-
Building
|
|
18
|
+
Building CloudFormation templates.
|
|
19
19
|
Deploying CloudFormation stack with jets app!
|
|
20
20
|
Uploading /tmp/jets/demo/code/code-7169d0ac.zip (88.8 MB) to S3
|
|
21
21
|
Time to upload code to s3: 1s
|
|
@@ -27,6 +27,6 @@ This builds the project and deploys it AWS Lambda. The deployment is mainly hand
|
|
|
27
27
|
02:10:03AM UPDATE_COMPLETE AWS::CloudFormation::Stack demo-dev
|
|
28
28
|
Stack success status: UPDATE_COMPLETE
|
|
29
29
|
Time took for stack deployment: 1m 46s.
|
|
30
|
-
Prewarming application
|
|
30
|
+
Prewarming application.
|
|
31
31
|
API Gateway Endpoint: https://ewwnealfk0.execute-api.us-west-2.amazonaws.com/dev/
|
|
32
32
|
$
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Imports a generic Rack application into a Jets project and configures it for [Mega Mode](http://rubyonjets.com/docs/megamode/).
|
|
2
|
+
|
|
3
|
+
Note, generic rack projects will likely need some adjustments to take into account API Gateway stages and logging. For more info refer to [Mega Mode Considerations](http://rubyonjets.com//megamode-considerations/).
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
jets import:rack http://github.com/tongueroo/jets-mega-rails.git
|
|
8
|
+
|
|
9
|
+
## More Examples
|
|
10
|
+
|
|
11
|
+
jets import:rack tongueroo/jets-mega-rails # expands to github
|
|
12
|
+
jets import:rack git@github.com:tongueroo/jets-mega-rails.git
|
|
13
|
+
jets import:rack /path/to/folder/jets-mega-rails
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Imports a Rails application into a Jets project and configures it for [Mega Mode](http://rubyonjets.com/docs/rails-support/).
|
|
2
|
+
|
|
3
|
+
## Example
|
|
4
|
+
|
|
5
|
+
jets import:rails http://github.com/tongueroo/jets-examples-rails.git
|
|
6
|
+
|
|
7
|
+
## More Examples
|
|
8
|
+
|
|
9
|
+
jets import:rails tongueroo/jets-examples-rails # expands to github
|
|
10
|
+
jets import:rails git@github.com:tongueroo/jets-examples-rails.git
|
|
11
|
+
jets import:rails /path/to/folder/jets-examples-rails
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class Jets::Commands::Import
|
|
2
|
+
class Base < Sequence
|
|
3
|
+
# Since setup is public it will automatically run in the subclasses
|
|
4
|
+
def setup
|
|
5
|
+
start_message
|
|
6
|
+
create_rack_folder
|
|
7
|
+
configure_ruby
|
|
8
|
+
create_rackup_wrappers
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
def start_message
|
|
13
|
+
puts "Importing app into the rack folder..."
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def create_rack_folder
|
|
17
|
+
repo? ? clone_project : copy_project
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def configure_ruby
|
|
21
|
+
gsub_file 'rack/Gemfile', /^ruby(.*)/, '# ruby\1' # comment out ruby declaration
|
|
22
|
+
create_file "rack/.ruby-version", RUBY_VERSION, force: true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def create_rackup_wrappers
|
|
26
|
+
path = File.expand_path("../../builders/rackup_wrappers", File.dirname(__FILE__))
|
|
27
|
+
Dir.glob("#{path}/*").each do |p|
|
|
28
|
+
FileUtils.cp(p, "#{rack_folder}/bin/")
|
|
29
|
+
end
|
|
30
|
+
chmod "#{rack_folder}/bin/rackup", 0755
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def bundle_install
|
|
34
|
+
Bundler.with_clean_env do
|
|
35
|
+
run "cd rack && bundle install"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class Jets::Commands::Import
|
|
2
|
+
class Rack < Base
|
|
3
|
+
def install
|
|
4
|
+
bundle_install
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def finish_message
|
|
8
|
+
puts <<~EOL
|
|
9
|
+
#{"="*30}
|
|
10
|
+
Congrats! The Rack project from #{@source} has been imported to the rack folder.
|
|
11
|
+
|
|
12
|
+
Note, generic rack projects will likely need some adjustments to take into account API Gateway stages and logging. For more info refer to [Mega Mode Considerations](http://rubyonjets.com//megamode-considerations/).
|
|
13
|
+
EOL
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
class Jets::Commands::Import
|
|
2
|
+
class Rail < Base
|
|
3
|
+
# We add jets-rails gem even though it's only activated within the megamode
|
|
4
|
+
# rackup wrapper script so user can check run bundle install and determine early
|
|
5
|
+
# if dependencies are met. The jets-rails gem is also added as part of the deploy
|
|
6
|
+
# process but we add it here also so the user gets earlier possible errors and
|
|
7
|
+
# can fix before they hit the deploy phase.
|
|
8
|
+
def configure_gemfile
|
|
9
|
+
append_to_file 'rack/Gemfile' do
|
|
10
|
+
%Q|gem "jets-rails"\n|
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def install
|
|
15
|
+
bundle_install
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def configure_routes
|
|
19
|
+
# comment out current catchall route
|
|
20
|
+
comment_lines("config/routes.rb", 'any[ (][\'"]\*', verbose: true) # any "*catchall", to: ...
|
|
21
|
+
|
|
22
|
+
# Add catchall route for rack
|
|
23
|
+
insert_into_file "config/routes.rb", :before => /^end/ do
|
|
24
|
+
<<-CODE
|
|
25
|
+
# Enables Mega Mode Rails integration
|
|
26
|
+
any "*catchall", to: "jets/rack#process"
|
|
27
|
+
CODE
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def finish_message
|
|
32
|
+
puts <<~EOL
|
|
33
|
+
#{"="*30}
|
|
34
|
+
Congrats! The Rails project from #{@source} has been imported to the rack folder. Here are some next steps:
|
|
35
|
+
|
|
36
|
+
# Local Testing
|
|
37
|
+
|
|
38
|
+
Check out the config/routes.rb file and noticed how a new catchall route has been added. It looks something like this:
|
|
39
|
+
|
|
40
|
+
any "*catchall", to: "jets/rack#process"
|
|
41
|
+
|
|
42
|
+
The catchall route passes any route not handled by the Jets app as a request onto the Rails app. You can modified the route to selectively route what you want.
|
|
43
|
+
|
|
44
|
+
Test the application locally. Test that the Rails app in the rack subfolder works independently. You can start the application up with:
|
|
45
|
+
|
|
46
|
+
cd rack # cd into the imported Rails project
|
|
47
|
+
bundle exec rackup
|
|
48
|
+
|
|
49
|
+
The rack server starts up on http://localhost:9292 You might have to make sure that the database is configured.
|
|
50
|
+
|
|
51
|
+
Once tested, stop that server with CTRL-C.
|
|
52
|
+
|
|
53
|
+
Then you can start the jets server from the main jets project:
|
|
54
|
+
|
|
55
|
+
cd .. # back to the main jets projet
|
|
56
|
+
jets server # starts both jets and rack servers
|
|
57
|
+
|
|
58
|
+
The jets server starts up on http://localhost:8888 You can stop both servers with CTRL-C.
|
|
59
|
+
|
|
60
|
+
# Deploy
|
|
61
|
+
|
|
62
|
+
When you're ready deploy to AWS Lambda with:
|
|
63
|
+
|
|
64
|
+
jets deploy
|
|
65
|
+
EOL
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
require 'colorize'
|
|
3
|
+
require 'active_support/core_ext/string'
|
|
4
|
+
require 'thor'
|
|
5
|
+
require 'bundler'
|
|
6
|
+
|
|
7
|
+
class Jets::Commands::Import::Sequence < Thor::Group
|
|
8
|
+
include Thor::Actions
|
|
9
|
+
argument :source
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
def clone_project
|
|
13
|
+
check_git_installed
|
|
14
|
+
|
|
15
|
+
command = "git clone #{repo_url} #{rack_folder}"
|
|
16
|
+
puts "=> #{command}"
|
|
17
|
+
if File.exist?(rack_folder)
|
|
18
|
+
abort "The folder #{rack_folder} already exists."
|
|
19
|
+
else
|
|
20
|
+
run command
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def copy_project
|
|
25
|
+
puts "Creating rack folder"
|
|
26
|
+
template_path = File.expand_path(@source)
|
|
27
|
+
set_source_paths(template_path)
|
|
28
|
+
directory ".", rack_folder
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def set_source_paths(*paths)
|
|
32
|
+
# Using string with instance_eval because block doesnt have access to
|
|
33
|
+
# path at runtime.
|
|
34
|
+
self.class.instance_eval %{
|
|
35
|
+
def self.source_paths
|
|
36
|
+
#{paths.flatten.inspect}
|
|
37
|
+
end
|
|
38
|
+
}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# normalize repo_url
|
|
42
|
+
def repo_url
|
|
43
|
+
if @source.include?('github.com')
|
|
44
|
+
@source # leave as is, user has provided full github url
|
|
45
|
+
else
|
|
46
|
+
"https://github.com/#{@source}"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def repo?
|
|
51
|
+
@source.include?('github.com')
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def check_git_installed
|
|
55
|
+
return unless repo_url.include?('http') || repo_url.include?('git@')
|
|
56
|
+
unless git_installed?
|
|
57
|
+
abort "Unable to detect git installation on your system. Git needs to be installed in order to clone the project."
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def git_installed?
|
|
62
|
+
system("type git > /dev/null 2>&1")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def rack_folder
|
|
66
|
+
"#{Jets.root}rack"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Jets::Commands
|
|
2
|
+
class Import < Jets::Commands::Base
|
|
3
|
+
autoload :Base, 'jets/commands/import/base'
|
|
4
|
+
autoload :Rack, 'jets/commands/import/rack'
|
|
5
|
+
autoload :Rail, 'jets/commands/import/rail'
|
|
6
|
+
autoload :Sequence, 'jets/commands/import/sequence'
|
|
7
|
+
|
|
8
|
+
long_desc Help.text('import:rails')
|
|
9
|
+
register(Jets::Commands::Import::Rail, "rails", "rails", "Imports rails project in the rack subfolder")
|
|
10
|
+
|
|
11
|
+
long_desc Help.text('import:rack')
|
|
12
|
+
register(Jets::Commands::Import::Rack, "rack", "rack", "Imports rack project in the rack subfolder")
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/jets/commands/main.rb
CHANGED
|
@@ -41,6 +41,7 @@ module Jets::Commands
|
|
|
41
41
|
command = "bundle exec shotgun --port #{o[:port]} --host #{o[:host]}"
|
|
42
42
|
puts "=> #{command}".colorize(:green)
|
|
43
43
|
puts Jets::Booter.message
|
|
44
|
+
Jets::Rack::Server.start unless ENV['JETS_RACK'] == '0' # rack server runs in background by default
|
|
44
45
|
system(command)
|
|
45
46
|
end
|
|
46
47
|
|
|
@@ -108,7 +109,7 @@ module Jets::Commands
|
|
|
108
109
|
|
|
109
110
|
long_desc Help.text(:new)
|
|
110
111
|
Jets::Commands::New.cli_options.each do |args|
|
|
111
|
-
option
|
|
112
|
+
option(*args)
|
|
112
113
|
end
|
|
113
114
|
register(Jets::Commands::New, "new", "new", "Creates a starter skeleton jets project")
|
|
114
115
|
end
|
data/lib/jets/commands/new.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Jets::Commands
|
|
|
9
9
|
def self.cli_options
|
|
10
10
|
[
|
|
11
11
|
[:bootstrap, type: :boolean, default: true, desc: "Install bootstrap css"], # same option in WebpackerTemplate
|
|
12
|
-
[:database, type: :
|
|
12
|
+
[:database, type: :string, default: 'mysql', desc: "Preconfigure database (options: mysql/postgresql)"],
|
|
13
13
|
[:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
|
|
14
14
|
[:git, type: :boolean, default: true, desc: "Git initialize the project"],
|
|
15
15
|
[:mode, default: 'html', desc: "mode: #{VALID_MODES.join(',')}"],
|
|
@@ -39,28 +39,32 @@ private
|
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def copy_options
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
42
|
+
excludes = if @options[:mode] == 'job'
|
|
43
|
+
# For job mode: list of words to include in the exclude pattern and will not be generated.
|
|
44
|
+
%w[
|
|
45
|
+
Procfile
|
|
46
|
+
controllers
|
|
47
|
+
helpers
|
|
48
|
+
javascript
|
|
49
|
+
models/application_
|
|
50
|
+
views
|
|
51
|
+
config.ru
|
|
52
|
+
database.yml
|
|
53
|
+
dynamodb.yml
|
|
54
|
+
routes
|
|
55
|
+
db/
|
|
56
|
+
spec
|
|
57
|
+
yarn
|
|
58
|
+
public
|
|
59
|
+
]
|
|
60
|
+
elsif !@options[:database]
|
|
61
|
+
# Do not even generated the config/database.yml because
|
|
62
|
+
# jets webpacker:install bombs and tries to load the db since it sees a
|
|
63
|
+
# config/database.yml but has there's no database pg gem configured.
|
|
64
|
+
%w[
|
|
65
|
+
database.yml
|
|
66
|
+
models/application_record
|
|
67
|
+
]
|
|
64
68
|
end
|
|
65
69
|
end
|
|
66
70
|
|
|
@@ -6,9 +6,12 @@ gem "jets"
|
|
|
6
6
|
# Include webpacker if you are you are building html pages
|
|
7
7
|
gem "webpacker", git: "https://github.com/tongueroo/webpacker.git", branch: "jets"
|
|
8
8
|
<% end -%>
|
|
9
|
-
<% if @options[:database] %>
|
|
9
|
+
<% if @options[:database] == 'postgresql' %>
|
|
10
10
|
# Include pg gem if you are using ActiveRecord, remove if you are not
|
|
11
|
-
gem "pg", "~>
|
|
11
|
+
gem "pg", "~> 1.1.3"
|
|
12
|
+
<% elsif @options[:database] == 'mysql' %>
|
|
13
|
+
# Include mysql2 gem if you are using ActiveRecord, remove if you are not
|
|
14
|
+
gem "mysql2", "~> 0.5.2"
|
|
12
15
|
<% end %>
|
|
13
16
|
|
|
14
17
|
group :development, :test do
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Jets Project
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This README would normally document whatever steps are necessary to get the application up and running.
|
|
4
4
|
|
|
5
|
+
[](http://badge.fury.io/rb/GEMNAME)
|
|
6
|
+
|
|
7
|
+
Things you might want to cover:
|
|
8
|
+
|
|
9
|
+
* Dependencies
|
|
10
|
+
* Configuration
|
|
11
|
+
* Database setup
|
|
12
|
+
* How to run the test suite
|
|
13
|
+
* Deployment instructions
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<title>Jets App</title>
|
|
9
9
|
<%%= javascript_pack_tag "application" %>
|
|
10
10
|
<%%= stylesheet_pack_tag "theme" %>
|
|
11
|
-
<link rel="shortcut icon" href="<%%= asset_path("/
|
|
11
|
+
<link rel="shortcut icon" href="<%%= asset_path("/favicon.ico") %>">
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<section class="starter">
|
|
@@ -2,6 +2,11 @@ Jets.application.configure do
|
|
|
2
2
|
config.project_name = "<%= @project_name %>"
|
|
3
3
|
config.mode = "<%= @options[:mode] %>"
|
|
4
4
|
|
|
5
|
+
# Lazy loads ruby and gems as part of first request. Prewarming will handles
|
|
6
|
+
# this. This also keeps the code package size small and allows us to use the
|
|
7
|
+
# Lambda console for inline code editing.
|
|
8
|
+
# config.ruby.lazy_load = true # default is true
|
|
9
|
+
|
|
5
10
|
# config.prewarm.enable = true # default is true
|
|
6
11
|
# config.prewarm.rate = '30 minutes' # default is '30 minutes'
|
|
7
12
|
# config.prewarm.concurrency = 2 # default is 2
|
|
@@ -15,9 +20,9 @@ Jets.application.configure do
|
|
|
15
20
|
config.cors = true # for '*''
|
|
16
21
|
# config.cors = '*.mydomain.com' # for specific domain
|
|
17
22
|
|
|
18
|
-
config.function.timeout =
|
|
23
|
+
config.function.timeout = 30
|
|
19
24
|
# config.function.role = "arn:aws:iam::#{Jets.aws.account}:role/service-role/pre-created"
|
|
20
|
-
# config.function.memory_size= 1536
|
|
25
|
+
# config.function.memory_size = 1536
|
|
21
26
|
|
|
22
27
|
config.function.environment = {
|
|
23
28
|
global_app_key1: "global_app_value1",
|
|
@@ -34,8 +39,10 @@ Jets.application.configure do
|
|
|
34
39
|
# Underscored format can be used for keys to make it look more ruby-ish.
|
|
35
40
|
|
|
36
41
|
# Assets settings
|
|
37
|
-
# config.assets.folders
|
|
38
|
-
# config.assets.
|
|
42
|
+
# config.assets.folders files are uploaded to s3 and are set to public-read to be served directly
|
|
43
|
+
# config.assets.folders = %w[public] # defaults to public
|
|
39
44
|
# config.assets.max_age = 3600 # when to expire assets
|
|
40
|
-
# config.assets.cache_control = nil # IE: public, max-age=3600
|
|
45
|
+
# config.assets.cache_control = nil # IE: "public, max-age=3600" # override max_age for more fine-grain control.
|
|
46
|
+
# config.assets.base_url = nil # IE: https://cloudfront.com/my/base/path, defaults to the s3 bucket url
|
|
47
|
+
# IE: https://s3-us-west-2.amazonaws.com/demo-dev-s3bucket-1inlzkvujq8zb
|
|
41
48
|
end
|