jets 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +2 -2
- data/README.md +10 -8
- data/lib/jets/aws_info.rb +6 -2
- data/lib/jets/booter.rb +31 -10
- data/lib/jets/builders/code_builder.rb +4 -2
- data/lib/jets/builders/node-shim.js +18 -0
- data/lib/jets/commands/build.rb +1 -0
- data/lib/jets/core.rb +2 -2
- data/lib/jets/processors/main_processor.rb +1 -1
- data/lib/jets/ruby_server.rb +13 -7
- data/lib/jets/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99d211e564c05c5406aa02c2524c6c3c31b31ebc8b5887453c6241428318a1cf
|
4
|
+
data.tar.gz: 68fec88d0f05af3763a9fa03be35c2dee56b5d5957195dcc4ff85cd4b092ef50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dad39bb8411c0692e262de6178d41cdacd6293c7dc95672ea7581500801c9bfc500a1394d3325701dc049743e769f4701210df5f5f46b3ff2791eda11fcabb60
|
7
|
+
data.tar.gz: 35a72039c9f9afc6500a5d8317d67d42132b72712f9f12ecf5f30663eace1222ec58f6d36251ec441de675db366e2eca2122340cf9dcab54c8323ea888da7564
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [0.6.3]
|
7
|
+
- fix app logging: pull request #14
|
8
|
+
|
6
9
|
## [0.6.2]
|
7
10
|
- add versions to gemspec dependencies
|
8
11
|
|
data/Gemfile.lock
CHANGED
@@ -11,7 +11,7 @@ GIT
|
|
11
11
|
PATH
|
12
12
|
remote: .
|
13
13
|
specs:
|
14
|
-
jets (0.6.
|
14
|
+
jets (0.6.3)
|
15
15
|
actionpack (>= 5.2.1)
|
16
16
|
actionview (>= 5.2.1)
|
17
17
|
activerecord (>= 5.2.1)
|
@@ -72,7 +72,7 @@ GEM
|
|
72
72
|
aws-partitions (~> 1.0)
|
73
73
|
aws-sigv4 (~> 1.0)
|
74
74
|
jmespath (~> 1.0)
|
75
|
-
aws-sdk-dynamodb (1.
|
75
|
+
aws-sdk-dynamodb (1.11.0)
|
76
76
|
aws-sdk-core (~> 3)
|
77
77
|
aws-sigv4 (~> 1.0)
|
78
78
|
aws-sdk-kms (1.7.0)
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
<div align="center">
|
2
|
-
<
|
2
|
+
<a href="http://rubyonjets.com"><img src="http://rubyonjets.com/img/logos/jets-logo.png" /></a>
|
3
3
|
</div>
|
4
4
|
|
5
|
+
Ruby and Lambda splat out a baby and that child's name is [Jets](http://rubyonjets.com/).
|
6
|
+
|
5
7
|
![Build Status](https://codebuild.us-west-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiUE12K3ljQTFQUjVpRW0reGhGVHVQdkplTHlOdUtENnBya2JhVWVXaFIvTU92MlBtV3hIUE9pb25jWGw0MS9jN2RXMERKRHh5Nzhvd01Za0NyeUs5SCtzPSIsIml2UGFyYW1ldGVyU3BlYyI6IkMybEJFaXdzejJEaHNWVmEiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)
|
6
8
|
[![CircleCI](https://circleci.com/gh/tongueroo/jets.svg?style=svg)](https://circleci.com/gh/tongueroo/jets)
|
7
9
|
|
8
|
-
Ruby and Lambda splat out a baby and that child's name is Jets.
|
9
|
-
|
10
10
|
## What is Jets?
|
11
11
|
|
12
12
|
Jets is a Ruby Serverless Framework. Jets allows you to create serverless applications with a beautiful language: Ruby. It includes everything required to build an application and deploy it to AWS Lambda.
|
@@ -24,7 +24,7 @@ Refer to the official docs for more info, but here's a quick intro.
|
|
24
24
|
|
25
25
|
A Jets controller handles a web request and renders a response. Here's an example:
|
26
26
|
|
27
|
-
|
27
|
+
app/controllers/posts_controller.rb:
|
28
28
|
|
29
29
|
```ruby
|
30
30
|
class PostsController < ApplicationController
|
@@ -48,7 +48,7 @@ Jets creates Lambda functions each the public method in your controller.
|
|
48
48
|
|
49
49
|
You connect Lambda functions to API Gateway URL endpoints with a routes file:
|
50
50
|
|
51
|
-
|
51
|
+
config/routes.rb:
|
52
52
|
|
53
53
|
```ruby
|
54
54
|
Jets.application.routes.draw do
|
@@ -74,9 +74,11 @@ Test your API Gateway endpoints with curl or postman. Note, replace the URL endp
|
|
74
74
|
"action": "index"
|
75
75
|
}
|
76
76
|
|
77
|
-
### Jets
|
77
|
+
### Jets Jobs
|
78
|
+
|
79
|
+
A Jets job handles asynchrous background jobs performed outside of the web request/response cycle. Here's an example:
|
78
80
|
|
79
|
-
|
81
|
+
app/jobs/hard_job.rb:
|
80
82
|
|
81
83
|
```ruby
|
82
84
|
class HardJob < ApplicationJob
|
@@ -92,7 +94,7 @@ class HardJob < ApplicationJob
|
|
92
94
|
end
|
93
95
|
```
|
94
96
|
|
95
|
-
`HardJob#dig`
|
97
|
+
`HardJob#dig` runs every 10 hours and `HardJob#lift` runs every 12 hours.
|
96
98
|
|
97
99
|
### Jets Deployment
|
98
100
|
|
data/lib/jets/aws_info.rb
CHANGED
@@ -5,7 +5,7 @@ module Jets
|
|
5
5
|
include AwsServices
|
6
6
|
|
7
7
|
def region
|
8
|
-
return 'us-east-1' if
|
8
|
+
return 'us-east-1' if test?
|
9
9
|
|
10
10
|
region = nil
|
11
11
|
|
@@ -28,9 +28,13 @@ module Jets
|
|
28
28
|
|
29
29
|
# aws sts get-caller-identity
|
30
30
|
def account
|
31
|
-
return '123456789' if
|
31
|
+
return '123456789' if test?
|
32
32
|
sts.get_caller_identity.account
|
33
33
|
end
|
34
34
|
memoize :account
|
35
|
+
|
36
|
+
def test?
|
37
|
+
ENV['TEST'] || ENV['CIRCLECI']
|
38
|
+
end
|
35
39
|
end
|
36
40
|
end
|
data/lib/jets/booter.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
class Jets::Booter
|
2
2
|
class << self
|
3
3
|
@booted = false
|
4
|
-
def boot!
|
4
|
+
def boot!(options={})
|
5
5
|
return if @booted
|
6
6
|
|
7
|
-
|
7
|
+
redirect_output(options)
|
8
8
|
confirm_jets_project!
|
9
9
|
require_bundle_gems
|
10
10
|
Jets::Dotenv.load!
|
@@ -14,16 +14,37 @@ class Jets::Booter
|
|
14
14
|
@booted = true
|
15
15
|
end
|
16
16
|
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
def
|
17
|
+
# TODO: Reconsider if we should redirect stdout to stderr globally for local request.
|
18
|
+
# Dont think we need to anymore now that we're not using the old shim.
|
19
|
+
#
|
20
|
+
# So for `{stringio: false}` and `jets call --local`, redirecting helps
|
21
|
+
# but we can also just go fix that jets call method. Though there might be a lot
|
22
|
+
# of other places where we might have to fix puts calls.
|
23
|
+
def redirect_output(options={})
|
24
24
|
$stdout.sync = true
|
25
25
|
$stderr.sync = true
|
26
|
-
|
26
|
+
if options[:stringio]
|
27
|
+
# Set both $stdout and $stdout to a StringIO object as a buffer.
|
28
|
+
# At the end of the request, write this buffer to the filesystem.
|
29
|
+
# In the node shim, read it back and write it to AWS Lambda logs.
|
30
|
+
#
|
31
|
+
# This allows using `puts` to write to CloudWatch.
|
32
|
+
$stdout = $stderr = StringIO.new # for ruby_server and AWS Lambda to capture log
|
33
|
+
else
|
34
|
+
# Printing to stdout can mangle up the response if we're piping the value to
|
35
|
+
# jq. For exampe, `jets call --local .. | jq`
|
36
|
+
# By redirecting stderr we can use jq.
|
37
|
+
#
|
38
|
+
$stdout = $stderr # jets call and local jets operation
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Used in ruby_server.rb
|
43
|
+
def flush_output
|
44
|
+
IO.write("/tmp/jets-output.log", $stdout.string)
|
45
|
+
# Thanks: https://stackoverflow.com/questions/28445000/how-can-i-clear-a-stringio-instance
|
46
|
+
$stdout.truncate(0)
|
47
|
+
$stdout.rewind
|
27
48
|
end
|
28
49
|
|
29
50
|
# require_bundle_gems called when environment boots up via Jets.boot. It
|
@@ -342,9 +342,11 @@ EOL
|
|
342
342
|
# When using submodules, bundler leaves old submodules behind. Over time this inflates
|
343
343
|
# the size of the the bundled gems. So we'll clean it up.
|
344
344
|
def clean_old_submodules
|
345
|
-
lockfile = "#{cache_area}/Gemfile.lock"
|
346
345
|
# https://stackoverflow.com/questions/38800129/parsing-a-gemfile-lock-with-bundler
|
347
|
-
|
346
|
+
lockfile = "#{cache_area}/Gemfile.lock"
|
347
|
+
return unless File.exist?(lockfile)
|
348
|
+
|
349
|
+
parser = Bundler::LockfileParser.new(Bundler.read_file(lockfile))
|
348
350
|
specs = parser.specs
|
349
351
|
|
350
352
|
# specs = Bundler.load.specs
|
@@ -2,10 +2,12 @@
|
|
2
2
|
|
3
3
|
const spawn = require('child_process').spawn;
|
4
4
|
const fs = require('fs');
|
5
|
+
const readline = require('readline');
|
5
6
|
const TMP_LOG_PATH = '/tmp/shim-subprocess.log';
|
6
7
|
const subprocess_out = fs.openSync(TMP_LOG_PATH, 'a');
|
7
8
|
const subprocess_err = fs.openSync(TMP_LOG_PATH, 'a');
|
8
9
|
const JETS_DEBUG = process.env.JETS_DEBUG // set JETS_DEBUG=1 to see more debugging info
|
10
|
+
const JETS_OUTPUT = '/tmp/jets-output.log';
|
9
11
|
|
10
12
|
function once() {
|
11
13
|
// Uncomment fake run once locally. No need to do this on real lambda environment.
|
@@ -112,6 +114,22 @@ function request(event, handler, callback) {
|
|
112
114
|
return;
|
113
115
|
}
|
114
116
|
|
117
|
+
if (fs.existsSync(JETS_OUTPUT)) {
|
118
|
+
// Thanks: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
|
119
|
+
var rd = readline.createInterface({
|
120
|
+
input: fs.createReadStream(JETS_OUTPUT),
|
121
|
+
// output: process.stdout,
|
122
|
+
console: false
|
123
|
+
});
|
124
|
+
|
125
|
+
rd.on('line', function(line) {
|
126
|
+
// Important to use console.error in case locally testing shim or we see
|
127
|
+
// stdout "twice", once from here and once from ruby-land and it's confusing.
|
128
|
+
// AWS lambda will write console.error and console.log to CloudWatch.
|
129
|
+
console.error(line); // output to AWS Lambda Logs
|
130
|
+
});
|
131
|
+
}
|
132
|
+
|
115
133
|
var resp = JSON.parse(stdout_buffer);
|
116
134
|
if (resp["errorMessage"]) {
|
117
135
|
// Customize error object for lambda format
|
data/lib/jets/commands/build.rb
CHANGED
@@ -113,6 +113,7 @@ module Jets::Commands
|
|
113
113
|
expression = "#{Jets.root}app/**/**/*.rb"
|
114
114
|
Dir.glob(expression).each do |path|
|
115
115
|
return false unless File.file?(path)
|
116
|
+
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, '')
|
data/lib/jets/core.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'stringio'
|
2
3
|
|
3
4
|
# Node shim calls this class to process both controllers and jobs
|
4
5
|
class Jets::Processors::MainProcessor
|
@@ -59,5 +60,4 @@ class Jets::Processors::MainProcessor
|
|
59
60
|
# $stderr.puts("END OF RUBY OUTPUT") # uncomment for debugging
|
60
61
|
end
|
61
62
|
end
|
62
|
-
|
63
63
|
end
|
data/lib/jets/ruby_server.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'socket'
|
2
2
|
require 'json'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
# Save copy of old stdout, since Jets.boot messes with it.
|
6
|
+
# So we can use $normal_stdout.puts for debugging.
|
7
|
+
$normal_stdout ||= $stdout
|
8
|
+
$normal_stderr ||= $stderr
|
3
9
|
|
4
10
|
# https://ruby-doc.org/stdlib-2.3.0/libdoc/socket/rdoc/TCPServer.html
|
5
11
|
# https://stackoverflow.com/questions/806267/how-to-fire-and-forget-a-subprocess
|
@@ -15,8 +21,7 @@ module Jets
|
|
15
21
|
PORT = 8080
|
16
22
|
|
17
23
|
def run
|
18
|
-
|
19
|
-
Jets.boot # outside of child process for COW
|
24
|
+
Jets.boot(stringio: true) # outside of child process for COW
|
20
25
|
Jets.eager_load!
|
21
26
|
|
22
27
|
# INT - ^C
|
@@ -44,10 +49,11 @@ module Jets
|
|
44
49
|
# child process
|
45
50
|
server = TCPServer.new(8080) # Server bind to port 8080
|
46
51
|
puts "Ruby server started on port #{PORT}" if ENV['FOREGROUND'] || ENV['JETS_DEBUG'] || ENV['C9_USER']
|
47
|
-
|
52
|
+
|
48
53
|
loop do
|
49
|
-
event, handler = nil, nil
|
50
54
|
client = server.accept # Wait for a client to connect
|
55
|
+
|
56
|
+
input_completed, event, handler = nil, nil, nil
|
51
57
|
unless input_completed
|
52
58
|
event = client.gets.strip # text
|
53
59
|
# puts event # uncomment for debugging, Jets has changed stdout to stderr
|
@@ -60,9 +66,10 @@ module Jets
|
|
60
66
|
prewarm_request(event) :
|
61
67
|
standard_request(event, '{}', handler)
|
62
68
|
|
63
|
-
|
69
|
+
Jets::Booter.flush_output # flushing output as soon we dont need it anymore
|
70
|
+
|
71
|
+
client.puts('{"test": 1}')
|
64
72
|
client.close
|
65
|
-
input_completed = false
|
66
73
|
end
|
67
74
|
end
|
68
75
|
|
@@ -90,4 +97,3 @@ module Jets
|
|
90
97
|
end
|
91
98
|
end
|
92
99
|
end
|
93
|
-
|
data/lib/jets/version.rb
CHANGED
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: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|