faastruby 0.5.12 → 0.5.13
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/README.md +43 -61
- data/lib/faastruby/cli/base_command.rb +4 -2
- data/lib/faastruby/cli/commands/account/confirm.rb +5 -2
- data/lib/faastruby/cli/commands/account/signup.rb +2 -2
- data/lib/faastruby/cli/commands/function/build.rb +1 -1
- data/lib/faastruby/cli/commands/function/deploy_to.rb +22 -8
- data/lib/faastruby/cli/commands/function/new.rb +2 -2
- data/lib/faastruby/cli/commands/function/remove_from.rb +2 -2
- data/lib/faastruby/cli/commands/function/update_context.rb +2 -2
- data/lib/faastruby/cli/commands/help.rb +1 -1
- data/lib/faastruby/cli/commands/project/deploy.rb +53 -14
- data/lib/faastruby/cli/commands/workspace/create.rb +3 -3
- data/lib/faastruby/cli/commands/workspace/destroy.rb +2 -2
- data/lib/faastruby/cli/commands/workspace/migrate.rb +2 -2
- data/lib/faastruby/cli/commands/workspace/rm.rb +1 -1
- data/lib/faastruby/cli/commands/workspace/update.rb +1 -1
- data/lib/faastruby/local.rb +11 -19
- data/lib/faastruby/local/functions/function.rb +8 -9
- data/lib/faastruby/local/listeners/listener.rb +17 -0
- data/lib/faastruby/local/processors/function.rb +25 -19
- 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: 78ae5a5b233203bdddaf6ba73a83efdb1046020909be4a4e2e4382aef76eedb6
|
4
|
+
data.tar.gz: d5391ab896bf2fb2b6aaa2726f602fd857bc03e99c1bb1f3423e443c9d3c6aa1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44d01a454d491ceb188cd4571c1cfbd7c4424053e4722b9eca08f0ea291b3e4dfb2d2e5852614d7af0bc450a4efc42ddf29a3880e120a40ad3f7ff63dcde96c5
|
7
|
+
data.tar.gz: 13eb59c4aa0ed8ad27f0588701302ea7a94f5dcc0c346ef43b1e09a26e5156d53316d7d71ac4274ef9604c1917e92c0ff6b5e2339ea3d6ad65597dccbe842880
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.5.13 - unreleased
|
4
|
+
- Update help with new spelling
|
5
|
+
- Better handle of deploys when sync is enabled
|
6
|
+
- Fix broken output spinners
|
7
|
+
- Improved console messages
|
8
|
+
- Disable initial compile of crystal functions when starting Local
|
9
|
+
- Fixed output bug when deploying from Local
|
10
|
+
- Clearer message output for the command `confirm-account`
|
11
|
+
- Ignore when Gemfile.lock is added
|
12
|
+
- Don't trigger a deploy when Gemfile is added
|
13
|
+
- Ignore Gemfile changes while initializing it
|
14
|
+
|
3
15
|
## 0.5.12 - Mar 16 2019
|
4
16
|
- Add new branding to Local web templates.
|
5
17
|
- Fix secrets.yml example in comments.
|
data/README.md
CHANGED
@@ -1,111 +1,93 @@
|
|
1
|
+
![faastRuby](https://faastruby.io/wp-content/uploads/2019/03/logo-positive.png)
|
2
|
+
|
1
3
|
[![Gem Version](https://badge.fury.io/rb/faastruby.svg)](https://badge.fury.io/rb/faastruby)
|
2
4
|
[![Build Status](https://travis-ci.org/FaaStRuby/faastruby-cli.svg?branch=master)](https://travis-ci.org/FaaStRuby/faastruby-cli)
|
3
5
|
|
4
|
-
* Looking for help? [
|
6
|
+
* Looking for help? [Join our Slack!](https://faastruby.io/slack).
|
5
7
|
|
6
|
-
* [Changelog](https://github.com/
|
8
|
+
* [Changelog](https://github.com/faastRuby/faastruby-cli/blob/master/CHANGELOG.md)
|
7
9
|
|
8
10
|
# faastruby-cli
|
9
11
|
|
10
|
-
CLI tool for managing workspaces and functions hosted at [
|
12
|
+
Local development kit and CLI tool for managing workspaces and functions hosted at [faastRuby](https://faastruby.io).
|
11
13
|
|
12
|
-
## What is
|
13
|
-
|
14
|
+
## What is faastRuby?
|
15
|
+
faastRuby is a Serverless Software Development Platform for Ruby and Crystal.
|
14
16
|
|
15
|
-
* [
|
17
|
+
* [Documentation](https://faastruby.io/docs/faastruby-local/)
|
16
18
|
|
17
19
|
## Try it
|
18
20
|
|
19
21
|
Getting up and running is quick and easy:
|
20
22
|
|
21
|
-
![Getting up and running](https://s3.amazonaws.com/faastruby/public/create-project.mp4)
|
22
|
-
|
23
23
|
1. Install the gem so `faastruby` is available in your terminal
|
24
24
|
|
25
25
|
```
|
26
26
|
~$ gem install faastruby
|
27
27
|
```
|
28
28
|
|
29
|
-
2. Create a new
|
29
|
+
2. Create a new faastRuby project
|
30
30
|
|
31
31
|
```
|
32
|
-
~$ faastruby new-project
|
33
|
-
+ d ./
|
34
|
-
+ f ./
|
35
|
-
+ f ./
|
36
|
-
+ d ./
|
37
|
-
+ f ./
|
38
|
-
+ f ./
|
39
|
-
+ f ./
|
40
|
-
+ f ./
|
41
|
-
+ d ./
|
42
|
-
+ f ./
|
43
|
-
+ f ./
|
44
|
-
+ f ./
|
45
|
-
+ f ./
|
46
|
-
+ f ./
|
47
|
-
Initialized empty Git repository in /Users/
|
48
|
-
Project '
|
32
|
+
~$ faastruby new-project my-project
|
33
|
+
+ d ./myproject
|
34
|
+
+ f ./myproject/project.yml
|
35
|
+
+ f ./myproject/secrets.yml
|
36
|
+
+ d ./myproject/functions/root
|
37
|
+
+ f ./myproject/functions/root/index.html.erb
|
38
|
+
+ f ./myproject/functions/root/template.rb
|
39
|
+
+ f ./myproject/functions/root/handler.rb
|
40
|
+
+ f ./myproject/functions/root/faastruby.yml
|
41
|
+
+ d ./myproject/functions/catch-all
|
42
|
+
+ f ./myproject/functions/catch-all/404.html
|
43
|
+
+ f ./myproject/functions/catch-all/handler.rb
|
44
|
+
+ f ./myproject/functions/catch-all/faastruby.yml
|
45
|
+
+ f ./myproject/public/faastruby.yml
|
46
|
+
+ f ./myproject/.gitignore
|
47
|
+
Initialized empty Git repository in /Users/DemoUser/myproject/.git/
|
48
|
+
Project 'myproject' initialized.
|
49
49
|
Now run:
|
50
|
-
$ cd
|
50
|
+
$ cd myproject
|
51
51
|
$ faastruby local
|
52
52
|
```
|
53
53
|
|
54
54
|
3. Fire up the local development environment for your new project
|
55
55
|
|
56
56
|
```
|
57
|
-
~$ cd
|
58
|
-
~/
|
57
|
+
~$ cd myproject
|
58
|
+
~/myproject$ faastruby local
|
59
59
|
Puma starting in single mode...
|
60
60
|
* Version 3.12.0 (ruby 2.5.3-p105), codename: Llamas in Pajamas
|
61
61
|
* Min threads: 0, max threads: 32
|
62
62
|
* Environment: production
|
63
|
-
|
64
|
-
|
63
|
+
* Listening on tcp://0.0.0.0:3000
|
64
|
+
Use Ctrl-C to stop
|
65
|
+
2019-03-16 21:09:36 -0300 | Detecting existing functions.
|
65
66
|
---
|
66
|
-
2019-
|
67
|
+
2019-03-16 21:09:36 -0300 | Ruby functions: ["lists/pets", "root", "catch-all", "ruby"]
|
67
68
|
---
|
68
|
-
2019-
|
69
|
+
2019-03-16 21:09:36 -0300 | Crystal functions: []
|
69
70
|
---
|
70
|
-
2019-
|
71
|
+
2019-03-16 21:09:37 -0300 | Listening for changes.
|
71
72
|
---
|
72
|
-
2019-02-27 23:36:03 +0800 (Sentinel) Watching for new Ruby functions...
|
73
73
|
```
|
74
74
|
|
75
75
|
As you can see, this runs with Ruby only. If you want to run Crystal as well (similar to Ruby, but with types and compiled to run very fast), simply [install Crystal](https://crystal-lang.org/reference/installation/) and start `faastruby local` again.
|
76
76
|
|
77
77
|
|
78
|
-
`faastruby local` is very powerful. When you add a new folder with a `handler.rb` or `handler.cr`, it will automatically be detected.
|
79
|
-
|
80
|
-
![How to add a new folder and file](https://s3.amazonaws.com/faastruby/public/new-paths.mp4)
|
78
|
+
`faastruby local` is very powerful. When you add a new folder with a `handler.rb` or `handler.cr`, it will automatically be detected. faastRuby will automatically add the configuration for the function so you can jump straight in.
|
81
79
|
|
82
|
-
Changes to the code will automatically be detected and immediately refreshed for you, making local development easy and comfortable
|
83
|
-
[!How to edit files and refresh them in the browser](https://s3.amazonaws.com/faastruby/public/local-file-refresh.mp4)
|
80
|
+
Changes to the code will automatically be detected and immediately refreshed for you, making local development easy and comfortable.
|
84
81
|
|
85
|
-
4. Deploy it to
|
82
|
+
4. Deploy it to the cloud:
|
86
83
|
|
87
84
|
```
|
88
|
-
~/hello-world$ faastruby deploy
|
89
|
-
◐ Running tests... Passed!
|
85
|
+
~/hello-world$ faastruby deploy
|
90
86
|
...
|
91
|
-
|
92
|
-
Finished in 0.00563 seconds (files took 0.15076 seconds to load)
|
93
|
-
3 examples, 0 failures
|
94
|
-
|
95
|
-
◐ Building package... Done!
|
96
|
-
◐ Deploying to workspace 'awesome-prod'... Done!
|
97
|
-
Endpoint: https://api.tor1.faastruby.io/awesome-prod/hello-world
|
87
|
+
* Project URL: https://myproject-stage-abd123.tor1.faast.cloud
|
98
88
|
```
|
89
|
+
Now visit that url in the browser!
|
99
90
|
|
100
|
-
|
101
|
-
|
102
|
-
```
|
103
|
-
~/hello-world$ curl https://api.tor1.faastruby.io/awesome-prod/hello-world
|
104
|
-
Hello, World!
|
105
|
-
```
|
106
|
-
|
107
|
-
Build lots of functions and share them with fellow Ruby devs!
|
108
|
-
|
109
|
-
## FaaStRuby + Hyperstack = fullstack Ruby apps!
|
91
|
+
## faastRuby + Hyperstack = fullstack Ruby apps!
|
110
92
|
|
111
|
-
Do you think JavaScript is your only option for the front-end? Think again. [Hyperstack](https://hyperstack.org) is a Ruby DSL, compiled by Opal, bundled by Webpack, powered by React.
|
93
|
+
Do you think JavaScript is your only option for the front-end? Think again. [Hyperstack](https://hyperstack.org) is a Ruby DSL, compiled by Opal, bundled by Webpack, powered by React.
|
@@ -3,8 +3,10 @@ require 'yaml'
|
|
3
3
|
module FaaStRuby
|
4
4
|
module Command
|
5
5
|
class BaseCommand
|
6
|
-
def self.spin(message)
|
7
|
-
|
6
|
+
def self.spin(message=nil)
|
7
|
+
s = ":spinner"
|
8
|
+
s += " #{message}" if message
|
9
|
+
spinner = TTY::Spinner.new(s, format: SPINNER_FORMAT)
|
8
10
|
spinner.auto_spin
|
9
11
|
spinner
|
10
12
|
end
|
@@ -14,13 +14,16 @@ module FaaStRuby
|
|
14
14
|
def run
|
15
15
|
user = User.new(email: @options['email'])
|
16
16
|
user.send_confirmation_code
|
17
|
-
puts "\nYou should have received an email with a confirmation token.
|
17
|
+
puts "\nYou should have received an email with a confirmation token."
|
18
|
+
puts "If you didn't receive an email:"
|
19
|
+
puts "- Make sure you sign up with the correct email address"
|
20
|
+
puts "- The system won't send an email if you account status is already 'confirmed'"
|
18
21
|
print "Confirmation Token: "
|
19
22
|
user.confirmation_token = STDIN.gets.chomp
|
20
23
|
spinner = spin("Confirming your account...")
|
21
24
|
user.confirm_account!
|
22
25
|
FaaStRuby::CLI.error(user.errors) if user.errors.any?
|
23
|
-
spinner.
|
26
|
+
spinner.success
|
24
27
|
user.save_credentials
|
25
28
|
puts "Login successful!"
|
26
29
|
migrate
|
@@ -32,10 +32,10 @@ module FaaStRuby
|
|
32
32
|
spinner = spin("Creating your account...")
|
33
33
|
user = User.create(email: email, password: password)
|
34
34
|
if user.errors.any?
|
35
|
-
spinner.
|
35
|
+
spinner.error
|
36
36
|
FaaStRuby::CLI.error(user.errors)
|
37
37
|
end
|
38
|
-
spinner.
|
38
|
+
spinner.success
|
39
39
|
exec("faastruby confirm-account --email #{email}")
|
40
40
|
exit 0
|
41
41
|
end
|
@@ -41,10 +41,21 @@ module FaaStRuby
|
|
41
41
|
def run
|
42
42
|
create_or_use_workspace
|
43
43
|
if @yaml_config['serve_static']
|
44
|
+
if @options['quiet']
|
45
|
+
puts "[#{@function_name}] Deploying static files '#{@function_name}' to workspace '#{@workspace_name}'..."
|
46
|
+
spinner = spin("")
|
47
|
+
else
|
48
|
+
spinner = say("[#{@function_name}] Deploying static files '#{@function_name}' to workspace '#{@workspace_name}'...")
|
49
|
+
end
|
44
50
|
package_file_name = build_package
|
45
|
-
spinner = say("* [#{@function_name}] Deploying static files '#{@function_name}' to workspace '#{@workspace_name}'...", quiet: @options['quiet'])
|
46
51
|
workspace = FaaStRuby::Workspace.new(name: @workspace_name).deploy(package_file_name)
|
47
52
|
else
|
53
|
+
if @options['quiet']
|
54
|
+
puts "[#{@function_name}] Deploying #{runtime_name} function '#{@function_name}' to workspace '#{@workspace_name}'..."
|
55
|
+
spinner = spin("")
|
56
|
+
else
|
57
|
+
spinner = spin("[#{@function_name}] Deploying #{runtime_name} function '#{@function_name}' to workspace '#{@workspace_name}'...")
|
58
|
+
end
|
48
59
|
if ruby_runtime?
|
49
60
|
FaaStRuby::CLI.error('Please fix the problems above and try again') unless bundle_install
|
50
61
|
end
|
@@ -53,15 +64,14 @@ module FaaStRuby
|
|
53
64
|
end
|
54
65
|
FaaStRuby::CLI.error("[#{@function_name}] Deploy aborted because 'test_command' exited non-zero.") unless run_tests
|
55
66
|
package_file_name = build_package
|
56
|
-
spinner = say("* [#{@function_name}] Deploying #{runtime_name} function '#{@function_name}' to workspace '#{@workspace_name}'...", quiet: @options['quiet'])
|
57
67
|
workspace = FaaStRuby::Workspace.new(name: @workspace_name).deploy(package_file_name, root_to: @options['root_to'], catch_all: @options['catch_all'], context: @options['context'])
|
58
68
|
end
|
59
69
|
if workspace.errors.any?
|
60
|
-
puts ' Failed :(' unless spinner&.
|
70
|
+
puts ' Failed :(' unless spinner&.error
|
61
71
|
@package_file.unlink
|
62
72
|
FaaStRuby::CLI.error(workspace.errors)
|
63
73
|
end
|
64
|
-
spinner.
|
74
|
+
spinner.success unless @options['quiet']
|
65
75
|
@package_file.unlink
|
66
76
|
puts "* [#{@function_name}] Deploy OK".green
|
67
77
|
unless @yaml_config['serve_static']
|
@@ -101,20 +111,24 @@ module FaaStRuby
|
|
101
111
|
# for consistency. This is temporary until the API gets patched.
|
102
112
|
spinner = say("[#{@function_name}] Waiting for the workspace '#{@workspace_name}' to be ready...", quiet: @options['quiet'])
|
103
113
|
sleep 2
|
104
|
-
puts ' Done!' unless spinner&.
|
114
|
+
puts ' Done!' unless spinner&.success
|
105
115
|
end
|
106
116
|
end
|
107
117
|
|
108
118
|
def shards_install
|
109
119
|
return true unless File.file?('shard.yml')
|
110
|
-
puts "[#{@function_name}] Verifying dependencies"
|
120
|
+
# puts "[#{@function_name}] Verifying dependencies" unless @options["quiet"]
|
111
121
|
system('shards check > /dev/null') || system('shards install')
|
122
|
+
rescue Errno::EPIPE
|
123
|
+
true
|
112
124
|
end
|
113
125
|
|
114
126
|
def bundle_install
|
115
127
|
return true unless File.file?('Gemfile')
|
116
|
-
puts "* [#{@function_name}] Verifying dependencies"
|
128
|
+
# puts "* [#{@function_name}] Verifying dependencies" unless @options["quiet"]
|
117
129
|
system('bundle check >/dev/null') || system('bundle install')
|
130
|
+
rescue Errno::EPIPE
|
131
|
+
true
|
118
132
|
end
|
119
133
|
|
120
134
|
def missing_args
|
@@ -140,7 +154,7 @@ module FaaStRuby
|
|
140
154
|
@yaml_config['before_build']&.each do |command|
|
141
155
|
puts `#{command}`
|
142
156
|
end
|
143
|
-
spinner&.
|
157
|
+
spinner&.success
|
144
158
|
end
|
145
159
|
require 'faastruby/cli/commands/function/build'
|
146
160
|
FaaStRuby::Command::Function::Build.build(source, output_file, @function_name, true)
|
@@ -186,7 +186,7 @@ module FaaStRuby
|
|
186
186
|
return true unless File.file?("#{@base_dir}/Gemfile")
|
187
187
|
spinner = spin("Installing gems...")
|
188
188
|
system("bundle install --gemfile=#{@base_dir}/Gemfile > /dev/null")
|
189
|
-
spinner.
|
189
|
+
spinner.success
|
190
190
|
end
|
191
191
|
|
192
192
|
def write_shards_file
|
@@ -213,7 +213,7 @@ module FaaStRuby
|
|
213
213
|
return true unless File.file?("#{@base_dir}/shard.yml")
|
214
214
|
spinner = spin("Installing shards...")
|
215
215
|
system("cd #{@base_dir} && shards install > /dev/null")
|
216
|
-
spinner.
|
216
|
+
spinner.success
|
217
217
|
end
|
218
218
|
|
219
219
|
def name_valid?
|
@@ -29,10 +29,10 @@ module FaaStRuby
|
|
29
29
|
function = FaaStRuby::Function.new(name: @function_name, workspace: workspace)
|
30
30
|
function.destroy
|
31
31
|
if function.errors.any?
|
32
|
-
spinner.
|
32
|
+
spinner.error
|
33
33
|
FaaStRuby::CLI.error(function.errors)
|
34
34
|
end
|
35
|
-
spinner.
|
35
|
+
spinner.success
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.help
|
@@ -22,10 +22,10 @@ module FaaStRuby
|
|
22
22
|
function = FaaStRuby::Function.new(name: @function_name, workspace: workspace)
|
23
23
|
function.update(new_context: @options['data'])
|
24
24
|
if function.errors.any?
|
25
|
-
spinner.
|
25
|
+
spinner.error
|
26
26
|
FaaStRuby::CLI.error(function.errors)
|
27
27
|
end
|
28
|
-
spinner.
|
28
|
+
spinner.success
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.help
|
@@ -7,7 +7,7 @@ module FaaStRuby
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def run
|
10
|
-
puts "
|
10
|
+
puts "faastRuby CLI - Manage workspaces and functions hosted at faastruby.io"
|
11
11
|
puts "Version: #{FaaStRuby::VERSION}"
|
12
12
|
puts
|
13
13
|
puts "Usage: faastruby [update] [OPTIONS] COMMAND [--help | -h] [ARGS]"
|
@@ -13,13 +13,19 @@ module FaaStRuby
|
|
13
13
|
@args = args
|
14
14
|
help
|
15
15
|
parse_options
|
16
|
+
@mutex = Mutex.new
|
17
|
+
@failed = {}
|
16
18
|
@options['functions'] += find_functions unless @options['functions'].any?
|
17
19
|
@options['environment'] ||= 'stage'
|
18
20
|
@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?")
|
21
|
+
@project_secrets = YAML.load(File.read(PROJECT_SECRETS_FILE)) rescue {secrets: {}}
|
19
22
|
@project_name = @project_yaml['name']
|
20
23
|
@root_to = @project_yaml['root_to'] || 'root'
|
21
24
|
@catch_all = @project_yaml['catch_all'] || 'catch-all'
|
22
25
|
@project_identifier = "-#{@project_yaml['identifier']}" if @project_yaml['identifier']
|
26
|
+
@workspace = "#{@project_name}-#{@options['environment']}#{@project_identifier}"
|
27
|
+
@spinners = TTY::Spinner::Multi.new("Deploying project '#{@project_name}' to workspace '#{@workspace}'", format: SPINNER_FORMAT)
|
28
|
+
# puts
|
23
29
|
end
|
24
30
|
|
25
31
|
def puts(msg)
|
@@ -33,38 +39,69 @@ module FaaStRuby
|
|
33
39
|
errors = false
|
34
40
|
root_folder = Dir.pwd
|
35
41
|
jobs = []
|
36
|
-
|
37
|
-
spinner = spin "Deploying project '#{@project_name}' to workspace #{workspace}..."
|
38
|
-
|
42
|
+
|
43
|
+
# spinner = spin "Deploying project '#{@project_name}' to workspace #{workspace}..."
|
44
|
+
connect_spinner = @spinners.register "[:spinner] Connecting to workspace '#{@workspace}'"
|
45
|
+
connect_spinner.auto_spin
|
46
|
+
try_workspace(@workspace, connect_spinner)
|
39
47
|
@options['functions'].each do |function_path|
|
40
48
|
jobs << Thread.new do
|
41
|
-
# puts "[#{function_path}] Entering folder '#{function_path}'"
|
42
|
-
# Dir.chdir function_path
|
43
49
|
function_config = YAML.load(File.read("#{function_path}/faastruby.yml"))
|
44
50
|
function_name = function_config['name']
|
45
|
-
|
46
|
-
|
51
|
+
msg = function_name == 'public' ? "Uploading static assets in '#{function_name}'" : "Deploying function '#{function_path}'"
|
52
|
+
spinner = @spinners.register "[:spinner] #{msg}"
|
53
|
+
spinner.auto_spin
|
54
|
+
# puts "[#{function_path}] Entering folder '#{function_path}'"
|
55
|
+
# Dir.chdir function_path
|
56
|
+
cmd = "cd #{function_path} && faastruby deploy-to #{@workspace} --quiet --dont-create-workspace"
|
47
57
|
cmd += " --set-root" if @root_to == function_name
|
48
58
|
cmd += " --set-catch-all" if @catch_all == function_name
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
59
|
+
secrets = secrets_for(function_name)
|
60
|
+
secrets_json = Oj.dump(secrets) if secrets
|
61
|
+
cmd += " --context '#{secrets_json}'" if secrets_json
|
62
|
+
output, status = Open3.capture2e(cmd)
|
63
|
+
if status == 0
|
64
|
+
spinner.success
|
65
|
+
else
|
66
|
+
add_failed(function_name, output)
|
67
|
+
spinner.error
|
54
68
|
end
|
55
69
|
end
|
56
70
|
end
|
57
71
|
jobs.each{|thr| thr.join}
|
58
|
-
|
72
|
+
if @failed.any?
|
73
|
+
puts "\n\nFAILURES:".red
|
74
|
+
@failed.each do |function_name, output|
|
75
|
+
puts "* Function '#{function_name}' deploy failed:".red
|
76
|
+
puts output
|
77
|
+
puts nil
|
78
|
+
end
|
79
|
+
puts "* Project URL: #{FaaStRuby.workspace_host_for(@workspace)}\n".green
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def secrets_for(function_name)
|
84
|
+
secrets = @project_secrets[@options['environment']]
|
85
|
+
return nil unless secrets
|
86
|
+
secrets[function_name]
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_failed(function_name, output)
|
90
|
+
@mutex.synchronize do
|
91
|
+
@failed[function_name] = output
|
92
|
+
end
|
59
93
|
end
|
60
94
|
|
61
|
-
def try_workspace(workspace)
|
95
|
+
def try_workspace(workspace, connect_spinner)
|
96
|
+
return true if @options['skip_create_workspace']
|
62
97
|
try_to_create = Proc.new {system("faastruby create-workspace #{workspace} > /dev/null 2>&1")}
|
63
98
|
has_credentials = system("faastruby list-workspace #{workspace} > /dev/null 2>&1")
|
64
99
|
continue = has_credentials || try_to_create.call
|
65
100
|
unless continue
|
101
|
+
connect_spinner.error
|
66
102
|
FaaStRuby::CLI.error("Unable to deploy project to workspace '#{workspace}'. Make sure you have the credentials, or try a different environment name.\nExample: faastruby deploy --deploy-env #{@options['environment']}-#{(rand * 100).to_i}")
|
67
103
|
end
|
104
|
+
connect_spinner.success
|
68
105
|
true
|
69
106
|
end
|
70
107
|
|
@@ -95,6 +132,8 @@ module FaaStRuby
|
|
95
132
|
while @args.any?
|
96
133
|
option = @args.shift
|
97
134
|
case option
|
135
|
+
when '--skip-create-workspace'
|
136
|
+
@options['skip_create_workspace'] = true
|
98
137
|
when '--function', '-f'
|
99
138
|
@options['functions'] << @args.shift
|
100
139
|
when '--env', '-e'
|
@@ -21,12 +21,12 @@ module FaaStRuby
|
|
21
21
|
spinner = spin("Setting up workspace '#{@workspace_name}'...")
|
22
22
|
workspace = FaaStRuby::Workspace.create(name: @workspace_name, email: @options['email'])
|
23
23
|
if workspace.errors.any?
|
24
|
-
spinner.
|
24
|
+
spinner.error if exit_on_error
|
25
25
|
FaaStRuby::CLI.error(workspace.errors) if exit_on_error
|
26
|
-
spinner.
|
26
|
+
spinner.success
|
27
27
|
return false
|
28
28
|
end
|
29
|
-
spinner.
|
29
|
+
spinner.success
|
30
30
|
end
|
31
31
|
create_dir if @options['create_local_dir'] && create_directory && !dir_exists?
|
32
32
|
true
|
@@ -21,10 +21,10 @@ module FaaStRuby
|
|
21
21
|
spinner = spin("Destroying...")
|
22
22
|
workspace.destroy
|
23
23
|
if workspace.errors.any?
|
24
|
-
spinner.
|
24
|
+
spinner.error
|
25
25
|
FaaStRuby::CLI.error(workspace.errors)
|
26
26
|
end
|
27
|
-
spinner.
|
27
|
+
spinner.success
|
28
28
|
puts "Workspace '#{@workspace_name}' was deleted from the cloud platform."
|
29
29
|
end
|
30
30
|
|
@@ -70,11 +70,11 @@ module FaaStRuby
|
|
70
70
|
response = api.migrate_to_account(workspace_name: workspace_name, api_key: credentials['api_key'], api_secret: credentials['api_secret'])
|
71
71
|
if response.code > 299
|
72
72
|
@failed << workspace_name
|
73
|
-
spinner.
|
73
|
+
spinner.error
|
74
74
|
return false
|
75
75
|
end
|
76
76
|
@migrated << workspace_name
|
77
|
-
spinner.
|
77
|
+
spinner.success
|
78
78
|
return true
|
79
79
|
end
|
80
80
|
|
@@ -19,7 +19,7 @@ module FaaStRuby
|
|
19
19
|
workspace = FaaStRuby::Workspace.new(name: @workspace_name)
|
20
20
|
workspace.delete_file(relative_path: @relative_path)
|
21
21
|
FaaStRuby::CLI.error(workspace.errors) if workspace.errors.any?
|
22
|
-
spinner.
|
22
|
+
spinner.success
|
23
23
|
puts "* [#{@relative_path}] File removed from cloud workspace '#{@workspace_name}'.".green
|
24
24
|
end
|
25
25
|
|
@@ -19,7 +19,7 @@ module FaaStRuby
|
|
19
19
|
workspace = FaaStRuby::Workspace.new(name: @workspace_name)
|
20
20
|
workspace.update_runners(@options['runners_max'])
|
21
21
|
FaaStRuby::CLI.error(workspace.errors) if workspace.errors.any?
|
22
|
-
spinner.
|
22
|
+
spinner.success
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.help
|
data/lib/faastruby/local.rb
CHANGED
@@ -128,10 +128,11 @@ module FaaStRuby
|
|
128
128
|
puts "Crystal functions: #{crystal_functions.inspect}"
|
129
129
|
listen_on_functions_dir
|
130
130
|
listen_on_public_dir if SYNC_ENABLED
|
131
|
-
initial_compile_and_deploy(crystal_functions)
|
132
|
-
puts "Listening for changes."
|
133
131
|
FunctionProcessor.new(FUNCTIONS_EVENT_QUEUE).start
|
134
132
|
StaticFileProcessor.new(PUBLIC_EVENT_QUEUE).start if SYNC_ENABLED
|
133
|
+
# initial_compile
|
134
|
+
puts "Listening for changes."
|
135
|
+
puts "faastRuby Local is ready at http://localhost:3000"
|
135
136
|
sleep
|
136
137
|
ensure
|
137
138
|
puts "Stopping Watchdog..."
|
@@ -139,30 +140,21 @@ module FaaStRuby
|
|
139
140
|
Local::Listener.public_listener.each(&:stop)
|
140
141
|
end
|
141
142
|
|
142
|
-
def self.
|
143
|
-
debug
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
143
|
+
def self.initial_compile
|
144
|
+
debug __method__
|
145
|
+
Thread.new do
|
146
|
+
sleep 1
|
147
|
+
crystal_functions = @@functions.map{|f| f if f.language == "crystal"}.compact
|
148
|
+
puts "Triggering 'compile' on Crystal functions." if crystal_functions.any?
|
149
|
+
crystal_functions.each {|f| FileUtils.touch("#{f.absolute_folder}/faastruby.yml")}
|
148
150
|
end
|
149
|
-
sleep 1
|
150
|
-
@@functions.each {|f| FileUtils.touch("#{f.absolute_folder}/faastruby.yml")}
|
151
151
|
end
|
152
152
|
|
153
153
|
def self.sync_mode_enabled
|
154
154
|
debug __method__
|
155
155
|
puts "Sync mode enabled."
|
156
|
-
print "Connecting to workspace '#{workspace}'... "
|
157
|
-
try_to_create = Proc.new {system("faastruby create-workspace #{workspace}")}
|
158
|
-
has_credentials = system("faastruby list-workspace #{workspace} > /dev/null 2>&1")
|
159
|
-
continue = has_credentials || try_to_create.call
|
160
|
-
unless continue
|
161
|
-
puts "[FATAL] Unable to setup project workspace '#{workspace}'. Make sure you have the credentials, or try a different environment name.\nExample: faastruby local --sync --deploy-env #{DEPLOY_ENVIRONMENT}-#{(rand * 100).to_i}".red
|
162
|
-
exit 1
|
163
|
-
end
|
164
|
-
STDOUT.puts "connected!\n".yellow
|
165
156
|
puts "Your local environment will be synced to https://#{workspace}.tor1.faast.cloud"
|
157
|
+
system("faastruby deploy")
|
166
158
|
true
|
167
159
|
end
|
168
160
|
|
@@ -64,16 +64,15 @@ module FaaStRuby
|
|
64
64
|
debug "deploy"
|
65
65
|
deploy_cmd, deploy_cmd_print = generate_deploy_command
|
66
66
|
puts "Running: #{deploy_cmd_print.join(' ')}".yellow
|
67
|
-
|
68
|
-
i
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
status = nil
|
68
|
+
Open3.popen2(deploy_cmd.join(' ')) do |i, oe, thr|
|
69
|
+
oe.each_line do |line|
|
70
|
+
next if line.chomp == '' || line.chomp == '---'
|
71
|
+
STDOUT.puts "#{Time.now} | #{line}"
|
72
|
+
STDOUT.puts "---"
|
73
|
+
end
|
74
|
+
status = thr.value
|
73
75
|
end
|
74
|
-
thr.join
|
75
|
-
oe.close
|
76
|
-
status = thr.value
|
77
76
|
end
|
78
77
|
|
79
78
|
def language
|
@@ -66,6 +66,18 @@ module FaaStRuby
|
|
66
66
|
debug "EVENT: #{@full_path}"
|
67
67
|
end
|
68
68
|
|
69
|
+
def to_h
|
70
|
+
{
|
71
|
+
listened_directory: @listened_directory,
|
72
|
+
full_path: @full_path,
|
73
|
+
relative_path: @relative_path,
|
74
|
+
relative_path_dirname: @relative_path_dirname,
|
75
|
+
filename: @filename,
|
76
|
+
dirname: @dirname,
|
77
|
+
type: @type
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
69
81
|
def function_created?
|
70
82
|
debug __method__
|
71
83
|
added? && filename.match(/^handler\.(rb|cr)$/)
|
@@ -76,6 +88,11 @@ module FaaStRuby
|
|
76
88
|
filename == 'Gemfile'
|
77
89
|
end
|
78
90
|
|
91
|
+
def file_is_a_gemfile_lock?
|
92
|
+
debug __method__
|
93
|
+
filename == 'Gemfile.lock'
|
94
|
+
end
|
95
|
+
|
79
96
|
def file_is_a_handler?
|
80
97
|
debug __method__
|
81
98
|
filename.match(/^handler\.(rb|cr)$/)
|
@@ -4,7 +4,8 @@ module FaaStRuby
|
|
4
4
|
|
5
5
|
def should_ignore?(event)
|
6
6
|
debug "should_ignore?(#{event.inspect})"
|
7
|
-
if
|
7
|
+
return true if event.file_is_a_gemfile_lock?
|
8
|
+
if present_in_ignore_list?(event.dirname) || present_in_ignore_list?(event.full_path)
|
8
9
|
debug "SKIP #{event}"
|
9
10
|
return true
|
10
11
|
end
|
@@ -36,7 +37,7 @@ module FaaStRuby
|
|
36
37
|
return new_function(event)
|
37
38
|
end
|
38
39
|
init_gemfile(event) if event.file_is_a_gemfile?
|
39
|
-
unless event.file_is_a_function_config?
|
40
|
+
unless event.file_is_a_function_config? || event.file_is_a_gemfile? || event.file_is_a_gemfile_lock?
|
40
41
|
debug "added: a file was added"
|
41
42
|
deploy(event)
|
42
43
|
end
|
@@ -124,7 +125,6 @@ module FaaStRuby
|
|
124
125
|
end
|
125
126
|
|
126
127
|
def deploy(event)
|
127
|
-
debug "deploy(#{event.inspect})"
|
128
128
|
return false unless SYNC_ENABLED
|
129
129
|
# This should run when sync is enabled and:
|
130
130
|
# - added any file but handler
|
@@ -132,11 +132,11 @@ module FaaStRuby
|
|
132
132
|
# - removed any file but handler
|
133
133
|
function = Local::Function.that_has_file(event.full_path, event.type)
|
134
134
|
run(function.name, 'deploy') do
|
135
|
-
debug "+ IGNORE #{function.absolute_folder}"
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
135
|
+
# debug "+ IGNORE #{function.absolute_folder}"
|
136
|
+
# add_ignore(function.absolute_folder)
|
137
|
+
function.deploy
|
138
|
+
# debug "- IGNORE #{function.absolute_folder}"
|
139
|
+
# remove_ignore(function.absolute_folder)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
@@ -150,24 +150,30 @@ module FaaStRuby
|
|
150
150
|
end
|
151
151
|
|
152
152
|
def bundle_install(event)
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
153
|
+
run(event.dirname, 'bundle install') do
|
154
|
+
puts "Running: cd #{event.relative_path_dirname} && bundle install"
|
155
|
+
if system("cd #{event.dirname} && bundle install")
|
156
|
+
STDOUT.puts '---'.yellow
|
157
|
+
puts "Gems from Gemfile '#{event.relative_path}' were installed in your local machine."
|
158
|
+
else
|
159
|
+
STDOUT.puts '---'.red
|
160
|
+
STDOUT.puts "#{Time.now} | Error installing gems in your local machine for Gemfile '#{event.relative_path}'.".red
|
161
|
+
end
|
160
162
|
end
|
161
163
|
end
|
162
164
|
|
163
165
|
def init_gemfile(event)
|
164
166
|
unless File.size(event.full_path) > 0
|
165
|
-
|
166
|
-
|
167
|
-
|
167
|
+
run(event.full_path, "init_gemfile") do
|
168
|
+
puts "Initializing Gemfile '#{event.relative_path}'"
|
169
|
+
add_ignore(event.full_path)
|
170
|
+
sleep 0.2
|
171
|
+
File.write(event.full_path, Local::RubyFunction.default_gemfile)
|
172
|
+
sleep 0.5
|
173
|
+
remove_ignore(event.full_path)
|
174
|
+
end
|
168
175
|
end
|
169
176
|
end
|
170
|
-
|
171
177
|
end
|
172
178
|
end
|
173
179
|
end
|
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.13
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|