faastruby 0.5.9 → 0.5.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +3 -3
- data/lib/faastruby/api.rb +1 -1
- data/lib/faastruby/cli/commands/function/new.rb +4 -0
- data/lib/faastruby/cli/commands/project/base_command.rb +0 -4
- data/lib/faastruby/cli/commands/project/deploy.rb +8 -11
- data/lib/faastruby/cli/commands/project/new.rb +0 -1
- data/lib/faastruby/cli/commands/workspace/create.rb +1 -1
- data/lib/faastruby/cli/commands/workspace/destroy.rb +2 -2
- data/lib/faastruby/local.rb +10 -14
- data/lib/faastruby/local/crystal_runtime.cr +5 -1
- data/lib/faastruby/local/functions/function.rb +4 -0
- data/lib/faastruby/local/listeners/listener.rb +6 -0
- data/lib/faastruby/local/processors/function.rb +1 -1
- data/lib/faastruby/server.rb +7 -1
- data/lib/faastruby/server/response.rb +1 -1
- data/lib/faastruby/server/runner.rb +1 -1
- data/lib/faastruby/server/runner_methods.rb +4 -0
- data/lib/faastruby/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: 8708963b2799676a36e2a8e78424656d9cb415c90d1b94efc75142f7976f7c6a
|
4
|
+
data.tar.gz: 47f5c687fc019a1a124a975a697b76c461dc9f31b141b30c710c20e6d3e17011
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83dfa0ec0f1fed55fe7cdfe894cce2d78dba942668d279f7d83e86e1303204dd695517e1f752fe61fd96e612ab1149e2db788d02aff3c92e2cdcb80453bebd93
|
7
|
+
data.tar.gz: d234ef49f82abee9162b26bb99c5c78099d5b6ff18afe22422de39287316f3af74b478d950fa7c5af3cb4be1cf5f3a10a7386481fbe1fd22cfcaa009724ea64d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.5.10 - unreleased
|
4
|
+
- Fix Watchdog message when a function is removed from the project.
|
5
|
+
- Add method render_nothing to ruby and crystal functions, to make it clear how to send an empty response body
|
6
|
+
- Empty functions will render an empty body
|
7
|
+
- Ensure Watchdog listeners stop when exiting
|
8
|
+
- Fix bug preventing `--create-local-dir` from creating a folder when `create-workspace` is used
|
9
|
+
- Change message confirmation when destroying a workspace
|
10
|
+
- Update YAML template comments with mention to `test_command`
|
11
|
+
- FaaStRuby Local won't start unless it can find `project.yml` in current directory.
|
12
|
+
- Fix command `faastruby deploy`
|
13
|
+
- Fix bug when response headers are empty
|
14
|
+
|
3
15
|
## 0.5.9 - Mar 11 2019
|
4
16
|
- Add Gemfile support to Watchdog. When a `Gemfile` is added to a function, Watchdog will initialize it if the file is empty and run `bundle install` every time you modify it.
|
5
17
|
- Watchdog will stream the output of commands instead of printing everything once it's done.
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
faastruby (0.5.
|
4
|
+
faastruby (0.5.10)
|
5
5
|
colorize (~> 0.8)
|
6
|
-
faastruby-rpc (~> 0.2.
|
6
|
+
faastruby-rpc (~> 0.2.3)
|
7
7
|
listen (~> 3.1)
|
8
8
|
oj (~> 3.6)
|
9
9
|
puma (~> 3.12)
|
@@ -30,7 +30,7 @@ GEM
|
|
30
30
|
unf (>= 0.0.5, < 1.0.0)
|
31
31
|
equatable (0.5.0)
|
32
32
|
erubis (2.7.0)
|
33
|
-
faastruby-rpc (0.2.
|
33
|
+
faastruby-rpc (0.2.3)
|
34
34
|
oj (~> 3.6)
|
35
35
|
ffi (1.10.0)
|
36
36
|
hashdiff (0.3.7)
|
data/lib/faastruby/api.rb
CHANGED
@@ -204,7 +204,7 @@ module FaaStRuby
|
|
204
204
|
end
|
205
205
|
|
206
206
|
def parse(response)
|
207
|
-
if latest_version = response.headers[:x_update_available]
|
207
|
+
if response.headers && latest_version = response.headers[:x_update_available]
|
208
208
|
puts "########### FaaStRuby Update Available ###########"
|
209
209
|
puts "# Latest version: #{latest_version} #"
|
210
210
|
puts "# Please run 'faastruby update' #"
|
@@ -106,6 +106,10 @@ module FaaStRuby
|
|
106
106
|
|
107
107
|
def yaml_comments
|
108
108
|
[
|
109
|
+
'## To run tests before each deploy, uncomment the line below',
|
110
|
+
'## and change the command if you are not using Rspec.',
|
111
|
+
'# test_command: rspec',
|
112
|
+
'',
|
109
113
|
'## You can add commands to run locally before building the deployment package.',
|
110
114
|
"## Some use cases are:",
|
111
115
|
"## * minifying Javascript/CSS",
|
@@ -3,11 +3,7 @@ module FaaStRuby
|
|
3
3
|
module Project
|
4
4
|
PROJECT_YAML_FILE = 'project.yml'
|
5
5
|
PROJECT_SECRETS_FILE = 'secrets.yml'
|
6
|
-
PROJECT_CREDENTIALS_FILE = '.credentials.yml'
|
7
6
|
class ProjectBaseCommand < BaseCommand
|
8
|
-
def read_credentials_file
|
9
|
-
File.file?(PROJECT_CREDENTIALS_FILE)
|
10
|
-
end
|
11
7
|
end
|
12
8
|
end
|
13
9
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
STDOUT.sync
|
1
2
|
require 'open3'
|
2
3
|
module FaaStRuby
|
3
4
|
module Command
|
@@ -16,9 +17,9 @@ module FaaStRuby
|
|
16
17
|
@options['environment'] ||= 'stage'
|
17
18
|
@project_yaml = YAML.load(File.read(PROJECT_YAML_FILE))['project'] rescue FaaStRuby::CLI.error("Could not find file 'project.yml'. Are you running this command from the project's folder?")
|
18
19
|
@project_name = @project_yaml['name']
|
20
|
+
@root_to = @project_yaml['root_to'] || 'root'
|
21
|
+
@catch_all = @project_yaml['catch_all'] || 'catch-all'
|
19
22
|
@project_identifier = "-#{@project_yaml['identifier']}" if @project_yaml['identifier']
|
20
|
-
@options['root_to'] ||= @project_yaml['root_to']
|
21
|
-
@options['catch_all'] ||= @project_yaml['catch_all']
|
22
23
|
end
|
23
24
|
|
24
25
|
def puts(msg)
|
@@ -33,17 +34,18 @@ module FaaStRuby
|
|
33
34
|
root_folder = Dir.pwd
|
34
35
|
jobs = []
|
35
36
|
workspace = "#{@project_name}-#{@options['environment']}#{@project_identifier}"
|
37
|
+
spinner = spin "Deploying project '#{@project_name}' to workspace #{workspace}..."
|
36
38
|
try_workspace(workspace)
|
37
|
-
spinner = spin("Deploying project '#{@project_name}'...")
|
38
39
|
@options['functions'].each do |function_path|
|
39
40
|
jobs << Thread.new do
|
40
41
|
# puts "[#{function_path}] Entering folder '#{function_path}'"
|
41
42
|
# Dir.chdir function_path
|
42
43
|
function_config = YAML.load(File.read("#{function_path}/faastruby.yml"))
|
43
44
|
function_name = function_config['name']
|
44
|
-
|
45
|
-
cmd
|
46
|
-
cmd += " --set-
|
45
|
+
|
46
|
+
cmd = "cd #{function_path} && faastruby deploy-to #{workspace} --quiet --dont-create-workspace"
|
47
|
+
cmd += " --set-root" if @root_to == function_name
|
48
|
+
cmd += " --set-catch-all" if @catch_all == function_name
|
47
49
|
Open3.popen2(cmd) do |stdin, stdout, status_thread|
|
48
50
|
stdout.each_line do |line|
|
49
51
|
puts line
|
@@ -53,7 +55,6 @@ module FaaStRuby
|
|
53
55
|
end
|
54
56
|
end
|
55
57
|
jobs.each{|thr| thr.join}
|
56
|
-
spinner.stop(" Done!")
|
57
58
|
puts "* Project URL: #{FaaStRuby.workspace_host_for(workspace)}\n\n".green
|
58
59
|
end
|
59
60
|
|
@@ -94,10 +95,6 @@ module FaaStRuby
|
|
94
95
|
while @args.any?
|
95
96
|
option = @args.shift
|
96
97
|
case option
|
97
|
-
when '--root-to'
|
98
|
-
@options['root_to'] = @args.shift
|
99
|
-
when '--catch-all'
|
100
|
-
@options['catch_all'] = @args.shift
|
101
98
|
when '--function', '-f'
|
102
99
|
@options['functions'] << @args.shift
|
103
100
|
when '--env', '-e'
|
@@ -26,7 +26,6 @@ module FaaStRuby
|
|
26
26
|
FaaStRuby::CLI.error("The project name must have between 3 and 15 characters, and can only have letters, numbers and dashes.") unless name_valid?
|
27
27
|
@base_dir = "./#{@project_name}"
|
28
28
|
parse_options
|
29
|
-
@options['credentials_file'] ||= PROJECT_CREDENTIALS_FILE
|
30
29
|
@options['project_type'] ||= 'web'
|
31
30
|
end
|
32
31
|
|
@@ -25,14 +25,14 @@ module FaaStRuby
|
|
25
25
|
FaaStRuby::CLI.error(workspace.errors)
|
26
26
|
end
|
27
27
|
spinner.stop("Done!")
|
28
|
-
puts "Workspace '#{@workspace_name}' was deleted from the
|
28
|
+
puts "Workspace '#{@workspace_name}' was deleted from the cloud platform."
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def warning
|
34
34
|
print "WARNING: ".red
|
35
|
-
puts "This action will permanently remove the workspace '#{@workspace_name}' and all its functions from the
|
35
|
+
puts "This action will permanently remove the workspace '#{@workspace_name}' and all its functions from the cloud platform."
|
36
36
|
print "Are you sure? [y/N] "
|
37
37
|
@options['force'] = STDIN.gets.chomp
|
38
38
|
end
|
data/lib/faastruby/local.rb
CHANGED
@@ -101,16 +101,6 @@ module FaaStRuby
|
|
101
101
|
@@functions ||= []
|
102
102
|
end
|
103
103
|
|
104
|
-
def self.functions_listener
|
105
|
-
debug "self.functions_listener"
|
106
|
-
@@functions_listener
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.public_listener
|
110
|
-
debug "self.public_listener"
|
111
|
-
@@public_listener
|
112
|
-
end
|
113
|
-
|
114
104
|
def self.secrets_for_function(function_name)
|
115
105
|
debug "self.secrets_for_function(#{function_name.inspect})"
|
116
106
|
deploy_environment_secrets[function_name] || {}
|
@@ -143,6 +133,10 @@ module FaaStRuby
|
|
143
133
|
FunctionProcessor.new(FUNCTIONS_EVENT_QUEUE).start
|
144
134
|
StaticFileProcessor.new(PUBLIC_EVENT_QUEUE).start if SYNC_ENABLED
|
145
135
|
sleep
|
136
|
+
ensure
|
137
|
+
puts "Stopping Watchdog..."
|
138
|
+
Local::Listener.functions_listener.each(&:stop)
|
139
|
+
Local::Listener.public_listener.each(&:stop)
|
146
140
|
end
|
147
141
|
|
148
142
|
def self.initial_compile_and_deploy(crystal_functions)
|
@@ -175,15 +169,17 @@ module FaaStRuby
|
|
175
169
|
def self.listen_on_functions_dir
|
176
170
|
debug "self.listen_on_functions_dir"
|
177
171
|
debug "Listening for changes in '#{functions_dir}'"
|
178
|
-
|
179
|
-
|
172
|
+
listener = Listener.new(directory: functions_dir, queue: FUNCTIONS_EVENT_QUEUE)
|
173
|
+
listener.start
|
174
|
+
Local::Listener.functions_listener << listener
|
180
175
|
end
|
181
176
|
|
182
177
|
def self.listen_on_public_dir
|
183
178
|
debug "self.listen_on_public_dir"
|
184
179
|
debug "Listening for changes in '#{public_dir}'"
|
185
|
-
|
186
|
-
|
180
|
+
listener = Listener.new(directory: public_dir, queue: PUBLIC_EVENT_QUEUE)
|
181
|
+
listener.start
|
182
|
+
Local::Listener.public_listener << listener
|
187
183
|
end
|
188
184
|
end
|
189
185
|
end
|
@@ -123,6 +123,10 @@ def render(icon : String? = nil, jpeg : String? = nil, gif : String? = nil, png
|
|
123
123
|
FaaStRuby::Response.new(body: resp_body, status: status, headers: headers, binary: bin)
|
124
124
|
end
|
125
125
|
|
126
|
+
def render_nothing(status : Int32 = 200, headers : Hash(String, String) = {} of String => String)
|
127
|
+
FaaStRuby::Response.new(body: nil, status: status, headers: headers, binary: false)
|
128
|
+
end
|
129
|
+
|
126
130
|
def redirect_to(function : String, status : Int32 = 303)
|
127
131
|
headers = {"Location" => function}
|
128
132
|
FaaStRuby::Response.new(body: nil, status: status, headers: headers)
|
@@ -160,7 +164,7 @@ rescue e
|
|
160
164
|
exit 1
|
161
165
|
end
|
162
166
|
spawn do
|
163
|
-
response = FaaStRuby::Function.run(event: payload.event)
|
167
|
+
response = FaaStRuby::Function.run(event: payload.event) || render_nothing
|
164
168
|
puts "R,#{Base64.urlsafe_encode(response.payload.to_json)}"
|
165
169
|
exit 0
|
166
170
|
end
|
@@ -148,6 +148,10 @@ module FaaStRuby
|
|
148
148
|
|
149
149
|
def yaml_comments
|
150
150
|
[
|
151
|
+
'## To run tests before each deploy, uncomment the line test_command below',
|
152
|
+
'## and change the command if you are not using Rspec.',
|
153
|
+
'# test_command: rspec',
|
154
|
+
'',
|
151
155
|
'## You can add commands to run locally before building the deployment package.',
|
152
156
|
"## Some use cases are:",
|
153
157
|
"## * minifying Javascript/CSS",
|
@@ -1,6 +1,12 @@
|
|
1
1
|
module FaaStRuby
|
2
2
|
module Local
|
3
3
|
class Listener
|
4
|
+
def self.functions_listener
|
5
|
+
@@functions_listener ||= []
|
6
|
+
end
|
7
|
+
def self.public_listener
|
8
|
+
@@public_listener ||= []
|
9
|
+
end
|
4
10
|
include Local::Logger
|
5
11
|
attr_accessor :listener, :directory, :queue
|
6
12
|
def initialize(directory:, queue:)
|
@@ -60,7 +60,7 @@ module FaaStRuby
|
|
60
60
|
# - Remove from workspace
|
61
61
|
if event.file_is_a_function_config?
|
62
62
|
debug "removed: the file is a function_config"
|
63
|
-
function_name = event.
|
63
|
+
function_name = event.relative_path_dirname
|
64
64
|
puts "Function '#{function_name}' was removed."
|
65
65
|
return remove_from_workspace(event)
|
66
66
|
end
|
data/lib/faastruby/server.rb
CHANGED
@@ -24,7 +24,13 @@ module FaaStRuby
|
|
24
24
|
exit 1
|
25
25
|
end
|
26
26
|
SERVER_ROOT = Dir.pwd
|
27
|
-
PROJECT_YAML_FILE =
|
27
|
+
PROJECT_YAML_FILE = "#{SERVER_ROOT}/project.yml"
|
28
|
+
unless File.file?(PROJECT_YAML_FILE)
|
29
|
+
puts "\nERROR: Project configuration file not in current directory."
|
30
|
+
puts "You can only run 'faastruby local' inside a Project directory."
|
31
|
+
puts "To create a project, run 'faastruby new-project project-name'.\n\n"
|
32
|
+
exit 1
|
33
|
+
end
|
28
34
|
SECRETS_FILE = ENV['FAASTRUBY_PROJECT_SECRETS_FILE'] || "#{SERVER_ROOT}/secrets.yml"
|
29
35
|
PROJECT_NAME = YAML.load(File.read(PROJECT_YAML_FILE))['project']['name']
|
30
36
|
SYNC_ENABLED = ENV['FAASTRUBY_PROJECT_SYNC_ENABLED']
|
@@ -25,7 +25,7 @@ module FaaStRuby
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def self.invalid_response
|
28
|
-
body = {'error' => "Your function must render a response. For example, render text: \"Hello World!\""}
|
28
|
+
body = {'error' => "Your function must render a response. For example, render text: \"Hello World!\". If you want to respond with an empty body, use 'render_nothing'."}
|
29
29
|
body = Oj.dump(body)
|
30
30
|
new(
|
31
31
|
body: body,
|
@@ -70,7 +70,7 @@ module FaaStRuby
|
|
70
70
|
begin
|
71
71
|
function = load_function("#{@function_folder}/handler.rb")
|
72
72
|
function_object.extend(function)
|
73
|
-
response = function_object.handler(event, *args)
|
73
|
+
response = function_object.handler(event, *args) || function_object.render_nothing
|
74
74
|
response = FaaStRuby::Response.invalid_response unless response.is_a?(FaaStRuby::Response)
|
75
75
|
rescue Exception => e
|
76
76
|
error = Oj.dump({
|
@@ -84,6 +84,10 @@ module FaaStRuby
|
|
84
84
|
respond_with(resp_body, status: status, headers: headers, binary: bin)
|
85
85
|
end
|
86
86
|
|
87
|
+
def render_nothing(status: 200, headers: {})
|
88
|
+
respond_with(nil, status: status, headers: headers, binary: false)
|
89
|
+
end
|
90
|
+
|
87
91
|
def redirect_to(function: nil, url: nil, status: 303)
|
88
92
|
headers = {"Location" => function || url}
|
89
93
|
respond_with(nil, status: status, headers: headers, binary: false)
|
data/lib/faastruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faastruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paulo Arruda
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|