jets 1.3.9 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Gemfile.lock +3 -3
  4. data/lib/jets.rb +1 -0
  5. data/lib/jets/booter.rb +12 -1
  6. data/lib/jets/builders/code_builder.rb +39 -35
  7. data/lib/jets/builders/code_size.rb +4 -2
  8. data/lib/jets/builders/gem_replacer.rb +7 -20
  9. data/lib/jets/builders/lambda_layer.rb +55 -37
  10. data/lib/jets/builders/rack_packager.rb +6 -4
  11. data/lib/jets/builders/ruby_packager.rb +8 -27
  12. data/lib/jets/builders/shim_vars/base.rb +0 -4
  13. data/lib/jets/builders/util.rb +6 -7
  14. data/lib/jets/commands/deploy.rb +1 -2
  15. data/lib/jets/commands/import/rail.rb +1 -34
  16. data/lib/jets/core.rb +3 -2
  17. data/lib/jets/turbo.rb +47 -0
  18. data/lib/jets/turbo/database_yaml.rb +41 -0
  19. data/lib/jets/turbo/project/.gitignore +12 -0
  20. data/lib/jets/turbo/project/.jetskeep +1 -0
  21. data/lib/jets/turbo/project/Gemfile +16 -0
  22. data/lib/jets/turbo/project/Gemfile.lock +184 -0
  23. data/lib/jets/turbo/project/Rakefile +2 -0
  24. data/lib/jets/turbo/project/app/controllers/application_controller.rb +2 -0
  25. data/lib/jets/turbo/project/app/helpers/application_helper.rb +2 -0
  26. data/lib/jets/turbo/project/app/jobs/application_job.rb +4 -0
  27. data/lib/jets/turbo/project/config.ru +5 -0
  28. data/lib/jets/turbo/project/config/application.rb +4 -0
  29. data/lib/jets/turbo/project/config/routes.rb +4 -0
  30. data/lib/jets/turbo/rail.rb +113 -0
  31. data/lib/jets/turbo/templates/config/database.yml +26 -0
  32. data/lib/jets/version.rb +1 -1
  33. data/vendor/jets-gems/lib/jets/gems/check.rb +18 -9
  34. data/vendor/jets-gems/lib/jets/gems/extract/gem.rb +1 -1
  35. metadata +17 -2
@@ -6,7 +6,7 @@ class Jets::Builders
6
6
 
7
7
  attr_reader :full_app_root
8
8
  def initialize(relative_app_root)
9
- @full_app_root = full(relative_app_root)
9
+ @full_app_root = "#{build_area}/#{relative_app_root}"
10
10
  end
11
11
 
12
12
  def install
@@ -16,18 +16,12 @@ class Jets::Builders
16
16
  clean_old_submodules
17
17
  bundle_install
18
18
  setup_bundle_config
19
+ copy_cache_gems
19
20
  end
20
21
 
21
22
  # build gems in vendor/gems/ruby/2.5.0 (done in install phase)
22
- # replace_compiled_gems:
23
- # remove binary gems in vendor/gems/ruby/2.5.0
24
- # extract binary gems in opt/ruby/gems/2.5.0
25
- # move binary gems from opt/ruby/gems/2.5.0 to vendor/gems/ruby/2.5.0
26
23
  def finish
27
24
  return unless gemfile_exist?
28
-
29
- copy_cache_gems
30
- replace_compiled_gems
31
25
  tidy
32
26
  end
33
27
 
@@ -53,6 +47,9 @@ class Jets::Builders
53
47
 
54
48
  copy_gemfiles(full_project_path)
55
49
 
50
+ # Uncomment out to always remove the cache/vendor/gems to debug
51
+ # FileUtils.rm_rf("#{cache_area}/vendor/gems")
52
+
56
53
  require "bundler" # dynamically require bundler so user can use any bundler
57
54
  Bundler.with_clean_env do
58
55
  sh(
@@ -131,7 +128,9 @@ class Jets::Builders
131
128
  def copy_gemfiles(full_project_path)
132
129
  FileUtils.mkdir_p(cache_area)
133
130
  FileUtils.cp("#{full_project_path}/Gemfile", "#{cache_area}/Gemfile")
134
- FileUtils.cp("#{full_project_path}/Gemfile.lock", "#{cache_area}/Gemfile.lock")
131
+
132
+ gemfile_lock = "#{full_project_path}/Gemfile.lock"
133
+ FileUtils.cp(gemfile_lock, "#{cache_area}/Gemfile.lock") if File.exist?(gemfile_lock)
135
134
  end
136
135
 
137
136
  def setup_bundle_config
@@ -163,19 +162,6 @@ EOL
163
162
  IO.write(bundle_config, text)
164
163
  end
165
164
 
166
- def gems_options
167
- {
168
- s3: "lambdagems",
169
- build_root: cache_area, # used in lambdagem
170
- project_root: @full_app_root, # used in gem_replacer and lambdagem
171
- }
172
- end
173
-
174
- def replace_compiled_gems
175
- headline "Replacing compiled gems with AWS Lambda Linux compiled versions."
176
- GemReplacer.new(Jets::RUBY_VERSION, gems_options).run
177
- end
178
-
179
165
  def copy_cache_gems
180
166
  vendor_bundle = "#{@full_app_root}/vendor/gems"
181
167
  if File.exist?(vendor_bundle)
@@ -188,10 +174,5 @@ EOL
188
174
  FileUtils.cp_r("#{cache_area}/vendor/gems", vendor_bundle)
189
175
  end
190
176
  end
191
-
192
- private
193
- def cache_area
194
- "#{Jets.build_root}/cache" # cleaner to use full path for this setting
195
- end
196
177
  end
197
178
  end
@@ -21,9 +21,5 @@ module Jets::Builders::ShimVars
21
21
  return unless checksum
22
22
  "#{name}-#{checksum}.zip"
23
23
  end
24
-
25
- def stage_area
26
- "#{Jets.build_root}/stage"
27
- end
28
24
  end
29
25
  end
@@ -1,5 +1,6 @@
1
1
  class Jets::Builders
2
2
  module Util
3
+ private
3
4
  def sh(command)
4
5
  puts "=> #{command}".colorize(:green)
5
6
  success = system(command)
@@ -15,18 +16,16 @@ class Jets::Builders
15
16
  puts "=> #{message}".colorize(:cyan)
16
17
  end
17
18
 
18
- # Provide pretty clear way to desinate full path.
19
- # full("bundled") => /tmp/jets/demo/bundled
20
- def full(relative_path)
21
- "#{Jets.build_root}/#{relative_path}"
19
+ def build_area
20
+ Jets.build_root
22
21
  end
23
22
 
24
23
  def stage_area
25
- "#{Jets.build_root}/stage"
24
+ "#{build_area}/stage"
26
25
  end
27
26
 
28
- def code_area
29
- "#{stage_area}/code"
27
+ def cache_area
28
+ "#{build_area}/cache" # cleaner to use full path for this setting
30
29
  end
31
30
  end
32
31
  end
@@ -2,7 +2,6 @@ module Jets::Commands
2
2
  class Deploy
3
3
  extend Memoist
4
4
  include StackInfo
5
-
6
5
  def initialize(options)
7
6
  @options = options
8
7
  end
@@ -15,6 +14,7 @@ module Jets::Commands
15
14
  check_dev_mode
16
15
  validate_routes!
17
16
 
17
+ # deploy full nested stack when stack already exists
18
18
  # Delete existing rollback stack from previous bad minimal deploy
19
19
  delete_minimal_stack if minimal_rollback_complete?
20
20
  exit_unless_updateable! # Stack could be in a weird rollback state or in progress state
@@ -28,7 +28,6 @@ module Jets::Commands
28
28
  # on_aws? and s3_base_url logic
29
29
  build_code
30
30
 
31
- # deploy full nested stack when stack already exists
32
31
  ship(stack_type: :full, s3_bucket: s3_bucket)
33
32
  end
34
33
 
@@ -29,22 +29,7 @@ CODE
29
29
  end
30
30
 
31
31
  def reconfigure_database_yml
32
- current_yaml = "#{Jets.root}rack/config/database.yml"
33
- return unless File.exist?(current_yaml)
34
-
35
- vars = {}
36
- current_database = YAML.load_file(current_yaml)
37
- database_names = infer_database_name(current_database)
38
- vars.merge!(database_names)
39
- vars['adapter'] = current_database['development']['adapter']
40
-
41
- path = File.expand_path("templates/config/database.yml", File.dirname(__FILE__))
42
- content = Jets::Erb.result(path, vars)
43
- IO.write(current_yaml, content)
44
- puts "Reconfigured #{current_yaml}"
45
- rescue Exception
46
- # If unable to copy the database.yml settings just slightly fail.
47
- # Do this because really unsure what is in the current database.yml
32
+ Jets::Turbo::DatabaseYaml.new.reconfigure
48
33
  end
49
34
 
50
35
  def finish_message
@@ -85,23 +70,5 @@ CODE
85
70
  jets deploy
86
71
  EOL
87
72
  end
88
-
89
- private
90
- def infer_database_name(current_database)
91
- vars = {}
92
- %w[development test production].each do |env|
93
- if !current_database[env]['database'].include?('<%') # already has ERB
94
- vars["database_#{env}"] = current_database[env]['database']
95
- else
96
- lines = IO.readlines("#{Jets.root}rack/config/application.rb")
97
- module_line = lines.find { |l| l =~ /^module / }
98
- app_module = module_line.gsub(/^module /,'').strip
99
- app_name = app_module.underscore
100
- vars["database_#{env}"] = "#{app_name}_#{env}"
101
- end
102
- end
103
-
104
- vars
105
- end
106
73
  end
107
74
  end
@@ -22,12 +22,12 @@ module Jets::Core
22
22
  # Useful for appending a './' in front of a path or leaving it alone.
23
23
  # Returns: '/path/with/trailing/slash/' or './'
24
24
  def root
25
+ # Do not memoize this method. Turbo mode can change it
25
26
  root = ENV['JETS_ROOT'].to_s
26
27
  root = '.' if root == ''
27
28
  root = "#{root}/" unless root.ends_with?('/')
28
29
  Pathname.new(root)
29
30
  end
30
- memoize :root
31
31
 
32
32
  def env
33
33
  env = ENV['JETS_ENV'] || 'development'
@@ -91,10 +91,11 @@ module Jets::Core
91
91
  path =~ %r{/functions} ||
92
92
  path =~ %r{/internal/app} ||
93
93
  path =~ %r{/jets/stack} ||
94
- path =~ %r{/rackup_wrappers} ||
95
94
  path =~ %r{/overrides} ||
95
+ path =~ %r{/rackup_wrappers} ||
96
96
  path =~ %r{/reconfigure_rails} ||
97
97
  path =~ %r{/templates/} ||
98
+ path =~ %r{/turbo/project/} ||
98
99
  path =~ %r{/version} ||
99
100
  path =~ %r{/webpacker}
100
101
  end
@@ -0,0 +1,47 @@
1
+ require 'fileutils'
2
+
3
+ module Jets
4
+ class Turbo
5
+ autoload :DatabaseYaml, 'jets/turbo/database_yaml'
6
+ autoload :Rail, 'jets/turbo/rail'
7
+
8
+ # Turbo charge mode
9
+ def charge
10
+ framework = detect
11
+ case framework
12
+ when :jets
13
+ # do nothing
14
+ when :rails
15
+ Rail.new.setup
16
+ else
17
+ # should never get here
18
+ end
19
+ end
20
+
21
+ def detect
22
+ if rails?
23
+ :rails
24
+ elsif jets?
25
+ :jets
26
+ else
27
+ :unknown_framework
28
+ end
29
+ end
30
+
31
+ def rails?
32
+ config_ru_contains?('run Rails.application')
33
+ end
34
+
35
+ def jets?
36
+ config_ru_contains?('run Jets.application')
37
+ end
38
+
39
+ def config_ru_contains?(value)
40
+ config_ru = "#{Dir.pwd}/config.ru"
41
+ return false unless File.exist?(config_ru)
42
+
43
+ lines = ::IO.readlines(config_ru)
44
+ lines.detect { |l| l.include?(value) }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,41 @@
1
+ class Jets::Turbo
2
+ class DatabaseYaml
3
+ def reconfigure
4
+ current_yaml = "#{Jets.root}rack/config/database.yml"
5
+ return unless File.exist?(current_yaml)
6
+
7
+ vars = {}
8
+ current_database = YAML.load_file(current_yaml)
9
+ database_names = infer_database_name(current_database)
10
+ vars.merge!(database_names)
11
+ vars['adapter'] = current_database['development']['adapter']
12
+
13
+ path = File.expand_path("templates/config/database.yml", File.dirname(__FILE__))
14
+ content = Jets::Erb.result(path, vars)
15
+ IO.write(current_yaml, content)
16
+ # puts "Reconfigured #{current_yaml}" # uncomment to inspect and debug
17
+ rescue Exception => e
18
+ puts "WARNING: Was not able to generate a database.yml. Leaving your current one in place"
19
+ puts e.message
20
+ # If unable to copy the database.yml settings just slightly fail.
21
+ # Do this because really unsure what is in the current database.yml
22
+ end
23
+
24
+ def infer_database_name(current_database)
25
+ vars = {}
26
+ %w[development test production].each do |env|
27
+ if !current_database[env]['database'].include?('<%') # already has ERB
28
+ vars["database_#{env}"] = current_database[env]['database']
29
+ else
30
+ lines = IO.readlines("#{Jets.root}rack/config/application.rb")
31
+ module_line = lines.find { |l| l =~ /^module / }
32
+ app_module = module_line.gsub(/^module /,'').strip
33
+ app_name = app_module.underscore
34
+ vars["database_#{env}"] = "#{app_name}_#{env}"
35
+ end
36
+ end
37
+
38
+ vars
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,12 @@
1
+ *.gem
2
+ .bundle
3
+ .byebug_history
4
+ .DS_Store
5
+ .env.*
6
+ /node_modules
7
+ /public/packs
8
+ /public/packs-test
9
+ bundled
10
+ coverage
11
+ pkg
12
+ tmp
@@ -0,0 +1 @@
1
+ pack
@@ -0,0 +1,16 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "jets"
4
+
5
+ group :development, :test do
6
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
7
+ gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
8
+ gem 'shotgun'
9
+ gem 'rack'
10
+ end
11
+
12
+ group :test do
13
+ gem 'rspec' # rspec test group only or we get the "irb: warn: can't alias context from irb_context warning" when starting jets console
14
+ gem 'launchy'
15
+ gem 'capybara'
16
+ end
@@ -0,0 +1,184 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actionpack (5.2.2)
5
+ actionview (= 5.2.2)
6
+ activesupport (= 5.2.2)
7
+ rack (~> 2.0)
8
+ rack-test (>= 0.6.3)
9
+ rails-dom-testing (~> 2.0)
10
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
11
+ actionview (5.2.2)
12
+ activesupport (= 5.2.2)
13
+ builder (~> 3.1)
14
+ erubi (~> 1.4)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
17
+ activemodel (5.2.2)
18
+ activesupport (= 5.2.2)
19
+ activerecord (5.2.2)
20
+ activemodel (= 5.2.2)
21
+ activesupport (= 5.2.2)
22
+ arel (>= 9.0)
23
+ activesupport (5.2.2)
24
+ concurrent-ruby (~> 1.0, >= 1.0.2)
25
+ i18n (>= 0.7, < 2)
26
+ minitest (~> 5.1)
27
+ tzinfo (~> 1.1)
28
+ addressable (2.5.2)
29
+ public_suffix (>= 2.0.2, < 4.0)
30
+ arel (9.0.0)
31
+ aws-eventstream (1.0.1)
32
+ aws-partitions (1.126.0)
33
+ aws-sdk-apigateway (1.23.0)
34
+ aws-sdk-core (~> 3, >= 3.39.0)
35
+ aws-sigv4 (~> 1.0)
36
+ aws-sdk-cloudformation (1.14.0)
37
+ aws-sdk-core (~> 3, >= 3.39.0)
38
+ aws-sigv4 (~> 1.0)
39
+ aws-sdk-cloudwatchlogs (1.12.0)
40
+ aws-sdk-core (~> 3, >= 3.39.0)
41
+ aws-sigv4 (~> 1.0)
42
+ aws-sdk-core (3.44.1)
43
+ aws-eventstream (~> 1.0)
44
+ aws-partitions (~> 1.0)
45
+ aws-sigv4 (~> 1.0)
46
+ jmespath (~> 1.0)
47
+ aws-sdk-dynamodb (1.18.1)
48
+ aws-sdk-core (~> 3, >= 3.39.0)
49
+ aws-sigv4 (~> 1.0)
50
+ aws-sdk-kms (1.13.0)
51
+ aws-sdk-core (~> 3, >= 3.39.0)
52
+ aws-sigv4 (~> 1.0)
53
+ aws-sdk-lambda (1.16.0)
54
+ aws-sdk-core (~> 3, >= 3.39.0)
55
+ aws-sigv4 (~> 1.0)
56
+ aws-sdk-s3 (1.30.0)
57
+ aws-sdk-core (~> 3, >= 3.39.0)
58
+ aws-sdk-kms (~> 1)
59
+ aws-sigv4 (~> 1.0)
60
+ aws-sdk-sns (1.9.0)
61
+ aws-sdk-core (~> 3, >= 3.39.0)
62
+ aws-sigv4 (~> 1.0)
63
+ aws-sdk-sqs (1.10.0)
64
+ aws-sdk-core (~> 3, >= 3.39.0)
65
+ aws-sigv4 (~> 1.0)
66
+ aws-sigv4 (1.0.3)
67
+ builder (3.2.3)
68
+ byebug (10.0.2)
69
+ capybara (3.12.0)
70
+ addressable
71
+ mini_mime (>= 0.1.3)
72
+ nokogiri (~> 1.8)
73
+ rack (>= 1.6.0)
74
+ rack-test (>= 0.6.3)
75
+ regexp_parser (~> 1.2)
76
+ xpath (~> 3.2)
77
+ colorize (0.8.1)
78
+ concurrent-ruby (1.1.4)
79
+ crass (1.0.4)
80
+ diff-lcs (1.3)
81
+ dotenv (2.5.0)
82
+ erubi (1.8.0)
83
+ gems (1.1.1)
84
+ json
85
+ hashie (3.6.0)
86
+ i18n (1.3.0)
87
+ concurrent-ruby (~> 1.0)
88
+ jets (1.3.9)
89
+ actionpack (>= 5.2.1)
90
+ actionview (>= 5.2.1)
91
+ activerecord (>= 5.2.1)
92
+ activesupport (>= 5.2.1)
93
+ aws-sdk-apigateway
94
+ aws-sdk-cloudformation
95
+ aws-sdk-cloudwatchlogs
96
+ aws-sdk-dynamodb
97
+ aws-sdk-lambda
98
+ aws-sdk-s3
99
+ aws-sdk-sns
100
+ aws-sdk-sqs
101
+ colorize
102
+ dotenv
103
+ gems
104
+ hashie
105
+ json
106
+ kramdown
107
+ memoist
108
+ mimemagic
109
+ rack
110
+ railties (>= 5.2.1)
111
+ recursive-open-struct
112
+ text-table
113
+ thor
114
+ jmespath (1.4.0)
115
+ json (2.1.0)
116
+ kramdown (1.17.0)
117
+ launchy (2.4.3)
118
+ addressable (~> 2.3)
119
+ loofah (2.2.3)
120
+ crass (~> 1.0.2)
121
+ nokogiri (>= 1.5.9)
122
+ memoist (0.16.0)
123
+ method_source (0.9.2)
124
+ mimemagic (0.3.3)
125
+ mini_mime (1.0.1)
126
+ mini_portile2 (2.4.0)
127
+ minitest (5.11.3)
128
+ nokogiri (1.9.1)
129
+ mini_portile2 (~> 2.4.0)
130
+ public_suffix (3.0.3)
131
+ rack (2.0.6)
132
+ rack-test (1.1.0)
133
+ rack (>= 1.0, < 3)
134
+ rails-dom-testing (2.0.3)
135
+ activesupport (>= 4.2.0)
136
+ nokogiri (>= 1.6)
137
+ rails-html-sanitizer (1.0.4)
138
+ loofah (~> 2.2, >= 2.2.2)
139
+ railties (5.2.2)
140
+ actionpack (= 5.2.2)
141
+ activesupport (= 5.2.2)
142
+ method_source
143
+ rake (>= 0.8.7)
144
+ thor (>= 0.19.0, < 2.0)
145
+ rake (12.3.2)
146
+ recursive-open-struct (1.1.0)
147
+ regexp_parser (1.3.0)
148
+ rspec (3.8.0)
149
+ rspec-core (~> 3.8.0)
150
+ rspec-expectations (~> 3.8.0)
151
+ rspec-mocks (~> 3.8.0)
152
+ rspec-core (3.8.0)
153
+ rspec-support (~> 3.8.0)
154
+ rspec-expectations (3.8.2)
155
+ diff-lcs (>= 1.2.0, < 2.0)
156
+ rspec-support (~> 3.8.0)
157
+ rspec-mocks (3.8.0)
158
+ diff-lcs (>= 1.2.0, < 2.0)
159
+ rspec-support (~> 3.8.0)
160
+ rspec-support (3.8.0)
161
+ shotgun (0.9.2)
162
+ rack (>= 1.0)
163
+ text-table (1.2.4)
164
+ thor (0.20.3)
165
+ thread_safe (0.3.6)
166
+ tzinfo (1.2.5)
167
+ thread_safe (~> 0.1)
168
+ xpath (3.2.0)
169
+ nokogiri (~> 1.8)
170
+
171
+ PLATFORMS
172
+ ruby
173
+
174
+ DEPENDENCIES
175
+ byebug
176
+ capybara
177
+ jets
178
+ launchy
179
+ rack
180
+ rspec
181
+ shotgun
182
+
183
+ BUNDLED WITH
184
+ 1.17.2