jets 1.0.4 → 1.0.5

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: ddb22c9d9b8de3f074f3365fb40ce6f0a5aa5e745ae51ae7d295c5b21929b3c2
4
- data.tar.gz: 0d990945082be50bbce002a6c0b0232560f2ea17553b5b642dd96eb17264832e
3
+ metadata.gz: 2caf68ff06e809fb88b76bdfb381aca29ce7f8540989dd775da2b288351b7f28
4
+ data.tar.gz: 566b69b388a24b2d110cd522c410b4be939a4a8e38f2771a69618228ffd8009c
5
5
  SHA512:
6
- metadata.gz: 8d4340fe4a89c7f482a37e6f22161a49edc2cbd6e9c1d3b02279b2a01bd3e4ee44137f2eee93a868623351655a0fb6c7683808a21816bf196b91e9de26f589ec
7
- data.tar.gz: ee828e0a8f06ff7122fc273f854719fe9256150a18d9c418620d4d009b54871fa2f1040bdae3c083022cd80470dce1ae5057b41c4f0e12a4eb4f1122c343faab
6
+ metadata.gz: c76ed8e21738349e7052c01d27bce581afd66a8c32980532e1a2c63fcf597336bb6deabcdea64db75a880b4e055516d33271e543dcae9196b74a22e95685be9c
7
+ data.tar.gz: c753ef10f2c180de87e82305b68195ff591a53f1b3b497144df7ddf43aeb7bce3d779183172984d068458a070512b072920b85986ad3354a5384ee5dead40c09
@@ -3,6 +3,12 @@
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/), even before v1.0.
5
5
 
6
+ ## [1.0.5]
7
+ - change config.lambdagems to config.gems
8
+ - friendly info message when yarn is not installed
9
+ - improve rails:import rack/config/database.yml generation
10
+ - update gems check
11
+
6
12
  ## [1.0.4]
7
13
  - import:rails reconfigure database.yml pull request #56 from tongueroo/database-yml
8
14
 
@@ -11,7 +11,7 @@ GIT
11
11
  PATH
12
12
  remote: .
13
13
  specs:
14
- jets (1.0.4)
14
+ jets (1.0.5)
15
15
  actionpack (>= 5.2.1)
16
16
  actionview (>= 5.2.1)
17
17
  activerecord (>= 5.2.1)
@@ -32,8 +32,8 @@ class Jets::Application
32
32
  config.prewarm.public_ratio = 3
33
33
  config.prewarm.rack_ratio = 5
34
34
 
35
- config.lambdagems = ActiveSupport::OrderedOptions.new
36
- config.lambdagems.sources = [
35
+ config.gems = ActiveSupport::OrderedOptions.new
36
+ config.gems.sources = [
37
37
  'https://gems.lambdagems.com'
38
38
  ]
39
39
 
@@ -8,15 +8,7 @@ class Jets::Builders
8
8
 
9
9
  def run
10
10
  check = Jets::Gems::Check.new
11
- found_gems = check.run
12
- if check.missing?
13
- # Exits early if not all the linux gems are available.
14
- # Better to error now than deploy a broken package to AWS Lambda.
15
- # Provide users with message about using their own lambdagems source.
16
- puts check.missing_message
17
- Jets::Gems::Report.missing(check.missing_gems)
18
- exit 1
19
- end
11
+ found_gems = check.run! # exits early if missing gems found
20
12
 
21
13
  # Reaching here means its safe to download and extract the gems
22
14
  found_gems.each do |gem_name, source|
@@ -4,20 +4,16 @@ module Jets::Commands
4
4
  long_desc Help.text("gems:check")
5
5
  def check
6
6
  check = Jets::Gems::Check.new(cli: true)
7
- check.run
8
- if check.missing?
9
- puts check.missing_message
10
- Jets::Gems::Report.missing(check.missing_gems)
11
- else
12
- puts "Congrats! All gems are available in as pre-built Lambda gems 👍"
13
- end
7
+ check.run! # exits early if missing gems found
8
+ # If reach here, means all gems are ok.
9
+ puts "Congrats! All gems are available in as pre-built Lambda gems 👍"
14
10
  end
15
-
16
- desc "sources", "List configured sources", hide: true
11
+
12
+ desc "sources", "List pre-built Lambda gem sources"
17
13
  long_desc Help.text("gems:sources")
18
14
  def sources
19
- puts "Your pre-built lambda gem sources are:"
20
- Jets.config.lambdagems.sources.each do |source|
15
+ puts "Your pre-built Lambda gem sources are:"
16
+ Jets.config.gems.sources.each do |source|
21
17
  puts " #{source}"
22
18
  end
23
19
  end
@@ -1,7 +1,8 @@
1
1
  You can configure additional gem sources in config/application.rb:
2
2
 
3
+ # Sources for check for pre-compiled Lambda gems. Checks the list in order.
3
4
  Jets.application.configure do
4
- config.lambdagems.sources = [
5
+ config.gems.sources = [
5
6
  "https://gems.lambdagems.com"
6
7
  ]
7
8
  end
@@ -33,12 +33,10 @@ CODE
33
33
  return unless File.exist?(current_yaml)
34
34
 
35
35
  vars = {}
36
- data = YAML.load_file(current_yaml)
37
- # Grab values from current database.yml
38
- %w[development test production].each do |env|
39
- vars["database_#{env}"] = data[env]['database']
40
- end
41
- vars['adapter'] = data['development']['adapter']
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']
42
40
 
43
41
  path = File.expand_path("templates/config/database.yml", File.dirname(__FILE__))
44
42
  content = Jets::Erb.result(path, vars)
@@ -82,10 +80,28 @@ CODE
82
80
 
83
81
  # Deploy
84
82
 
85
- When you're ready deploy to AWS Lambda with:
83
+ When you are ready deploy to AWS Lambda with:
86
84
 
87
85
  jets deploy
88
- EOL
86
+ EOL
87
+ 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
89
105
  end
90
106
  end
91
107
  end
@@ -40,7 +40,7 @@ class Jets::Commands::Import
40
40
  puts "Creating rack folder"
41
41
  template_path = File.expand_path(@source)
42
42
  set_source_paths(template_path)
43
- directory ".", rack_folder
43
+ directory ".", rack_folder, exclude_pattern: %r{.git}
44
44
  end
45
45
 
46
46
  def set_source_paths(*paths)
@@ -60,6 +60,21 @@ module Jets::Commands
60
60
 
61
61
  def webpacker_install
62
62
  return unless @webpacker
63
+ unless yarn_installed?
64
+ puts "Yarn is not installed or has not been detected. Please double check that yarn has been installed.".colorize(:red)
65
+ puts <<~EOL
66
+ To check:
67
+
68
+ which yarn
69
+
70
+ If it is not installed, you can usually install it with:
71
+
72
+ npm install -g yarn
73
+
74
+ Refer to the install docs for more info: http://rubyonjets.com/docs/install/
75
+ EOL
76
+ exit 1
77
+ end
63
78
 
64
79
  command = "jets webpacker:install"
65
80
  command += " FORCE=1" if options[:force]
@@ -69,6 +69,10 @@ private
69
69
  end
70
70
 
71
71
  def git_installed?
72
- system("type git > /dev/null")
72
+ system("type git > /dev/null 2>&1")
73
+ end
74
+
75
+ def yarn_installed?
76
+ system("type yarn > /dev/null 2>&1")
73
77
  end
74
78
  end
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -20,13 +20,13 @@ module Jets::Gems
20
20
  # "pg-0.21.0" => "https://anothersource.com",
21
21
  # }
22
22
  #
23
- def run
23
+ def run!
24
24
  puts "Checking projects gems for pre-built Lambda gems..."
25
25
  found_gems = {}
26
26
  compiled_gems.each do |gem_name|
27
27
  puts "Checking #{gem_name}..." if @options[:cli]
28
28
  gem_exists = false
29
- Jets.config.lambdagems.sources.each do |source|
29
+ Jets.config.gems.sources.each do |source|
30
30
  exist = Jets::Gems::Exist.new(source_url: source)
31
31
  found = exist.check(gem_name)
32
32
  # gem exists on at least of the lambdagem sources
@@ -40,6 +40,16 @@ module Jets::Gems
40
40
  @missing_gems << gem_name
41
41
  end
42
42
  end
43
+
44
+ unless @missing_gems.empty?
45
+ # Exits early if not all the linux gems are available.
46
+ # Better to error now than deploy a broken package to AWS Lambda.
47
+ # Provide users with message about using their own lambdagems source.
48
+ puts missing_message
49
+ Report.missing(@missing_gems)
50
+ exit 1
51
+ end
52
+
43
53
  found_gems
44
54
  end
45
55
 
@@ -55,7 +65,7 @@ Your project requires compiled gems were not available in any of your lambdagems
55
65
  <% end %>
56
66
 
57
67
  Your current lambdagems sources:
58
- <% Jets.config.lambdagems.sources.map do |source| %>
68
+ <% Jets.config.gems.sources.map do |source| %>
59
69
  * <%= source -%>
60
70
  <% end %>
61
71
 
@@ -65,7 +75,7 @@ Jets is unable to build a deployment package that will work on AWS Lambda withou
65
75
  * Wait until it added to lambdagems.com. No need to report this to us, as we've already been notified.
66
76
  * Use another gem that does not require compilation.
67
77
 
68
- Compiled gems usually take some time to figure out how to build as they each depend on different libraries and packages. We make an effort add new gems as soon as we can.
78
+ Compiled gems usually take some time to figure out how to build as they each depend on different libraries and packages.
69
79
  EOL
70
80
  erb = ERB.new(template, nil, '-') # trim mode https://stackoverflow.com/questions/4632879/erb-template-removing-the-trailing-line
71
81
  erb.result(binding)
@@ -1,3 +1,5 @@
1
+ require 'open-uri'
2
+
1
3
  module Jets::Gems
2
4
  class Exist
3
5
  def initialize(options)
@@ -31,7 +33,7 @@ module Jets::Gems
31
33
  end
32
34
  res = req.request_head(url.path)
33
35
  res.code == "200"
34
- rescue SocketError, OpenURI::HTTPError
36
+ rescue SocketError, OpenURI::HTTPError, OpenSSL::SSL::SSLError
35
37
  false
36
38
  end
37
39
 
@@ -2,6 +2,8 @@ require "net/http"
2
2
 
3
3
  module Jets::Gems
4
4
  class Report
5
+ # For local testing, example:
6
+ # LAMBDAGEM_API_URL=localhost:8888/api/v1 jets gems:check
5
7
  LAMBDAGEM_API_URL = ENV["LAMBDAGEM_API_URL"] || "https://api.lambdagems.com/api/v1"
6
8
 
7
9
  def self.missing(gems)
@@ -19,7 +21,7 @@ module Jets::Gems
19
21
  if md = gem_name.match(version_pattern)
20
22
  name, version = md[1], md[2]
21
23
  threads << Thread.new do
22
- call_api("report/missing?name=#{name}&version=#{version}")
24
+ call_api("report/missing?name=#{name}&version=#{version}", async: true)
23
25
  end
24
26
  else
25
27
  puts "WARN: Unable to extract the version from the gem name."
@@ -31,16 +33,30 @@ module Jets::Gems
31
33
  end
32
34
 
33
35
  def api_url(path)
34
- "#{LAMBDAGEM_API_URL}/#{path}"
36
+ url = "#{LAMBDAGEM_API_URL}/#{path}"
37
+ url.include?("http") ? url : "http://#{url}" # ensure http or https has been provided
35
38
  end
36
39
 
37
- def call_api(path)
38
- # raise "HI"
40
+ def call_api(path, async: false)
39
41
  uri = URI(api_url(path))
40
42
  http = Net::HTTP.new(uri.host, uri.port)
41
43
  http.use_ssl = uri.scheme == "https"
44
+ # Abusing read_timeout to mimic async fire and forget behavior.
45
+ # This makes the code continue and return very quickly and we ignore the response
46
+ # Thanks: https://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/
47
+ # https://github.com/ankane/the-ultimate-guide-to-ruby-timeouts/issues/8
48
+ http.max_retries = 0 # Fix http retries, read_timeout will cause retries immediately, we want to disable this behavior
49
+ http.read_timeout = 0.01 if async
42
50
  request = Net::HTTP::Get.new(uri)
43
- response = http.request(request)
51
+ begin
52
+ response = http.request(request)
53
+ rescue Net::ReadTimeout
54
+ # Abusing read_timeout to mimic async fire and forget behavior
55
+ end
56
+ return nil if async # always return nil if async behavior requested.
57
+ # In theory we can sometimes get back a response if it returns before
58
+ # the read timeout but that's a confusing interface.
59
+
44
60
  resp = {
45
61
  status: response.code.to_i,
46
62
  headers: response.each_header.to_h,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen