fdk 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +42 -32
- data/lib/fdk/runner.rb +1 -1
- data/lib/fdk/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd1f63ae8fc93bda3870e3ce780994e84b99e386
|
4
|
+
data.tar.gz: 045eebb796bd9eaae7a190dbd10c3bbb390c61a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31677d766e3ae7d1dff6ccca614e5be549e5704dd2747406206496f3c2ec886fa48735d3fde66989b4840606b692f6b4cc2bde95da5c717f7ab5dedd2b70da57
|
7
|
+
data.tar.gz: 7a4d3a7d572e94f752ec2be0eacc44bcc49936643d7c9a63faf7ee57d4a832fa362a95c2daf095d5ad4718a06e469a853f1f2442bac21d6434157928983af2c3
|
data/README.md
CHANGED
@@ -1,19 +1,17 @@
|
|
1
1
|
# Ruby Function Developer Kit (FDK)
|
2
|
-
|
3
|
-
This provides a Ruby framework for deleloping functions for us with [Fn](https://fnproject.github.io).
|
2
|
+
This provides a Ruby framework for developing functions for use with [Fn](https://fnproject.github.io).
|
4
3
|
|
5
4
|
## Function Handler
|
6
|
-
|
7
5
|
To use this FDK, you simply need to require this gem.
|
8
6
|
|
9
7
|
```ruby
|
10
|
-
require 'fdk
|
8
|
+
require 'fdk'
|
11
9
|
```
|
12
10
|
|
13
11
|
Then create a function with with the following syntax:
|
14
12
|
|
15
13
|
```ruby
|
16
|
-
def
|
14
|
+
def myfunction(context:, input:)
|
17
15
|
# Do some work here
|
18
16
|
return output
|
19
17
|
end
|
@@ -22,16 +20,22 @@ end
|
|
22
20
|
* context - provides runtime information for your function, such as configuration values, headers, etc.
|
23
21
|
* input – This parameter is a string containing body of the request.
|
24
22
|
* output - is where you can return data back to the caller. Whatever you return will be sent back to the caller. If `async`, this value is ignored.
|
25
|
-
|
26
|
-
|
23
|
+
* Default output format should be in JSON, as Content-Type header will be `application/json` by default. You can be more flexible if you create and return
|
24
|
+
an FDK::Response object instead of a string.
|
27
25
|
|
28
26
|
Then simply pass that function to the FDK:
|
29
27
|
|
30
28
|
```ruby
|
31
|
-
FDK.handle(myfunction)
|
29
|
+
FDK.handle(:myfunction)
|
32
30
|
```
|
33
31
|
|
34
|
-
##
|
32
|
+
## Examples
|
33
|
+
|
34
|
+
See the [examples](examples) folder of this repo for code examples.
|
35
|
+
|
36
|
+
### Hello World Example
|
37
|
+
|
38
|
+
In the [hello-ruby](examples/hello-ruby) folder there is a traditional "Hello World" example. The code is found in [func.rb](examples/hello-ruby/func.rb):
|
35
39
|
|
36
40
|
```ruby
|
37
41
|
require 'fdk'
|
@@ -45,44 +49,50 @@ end
|
|
45
49
|
FDK.handle(function: :myfunction)
|
46
50
|
```
|
47
51
|
|
48
|
-
##
|
52
|
+
## Deploying functions
|
49
53
|
|
50
|
-
|
51
|
-
$ echo '{"name":"coolio"}' | fn run
|
52
|
-
{"message":"Hello coolio!"}
|
53
|
-
```
|
54
|
+
To use a function we need to deploy it to an fn server.
|
54
55
|
|
55
|
-
|
56
|
+
In fn an _app_ consist of one or more functions and each function is
|
57
|
+
deployed as part of an app.
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
{"message":"Hello coolio!"}
|
60
|
-
```
|
59
|
+
We're going to deploy the hello world example as part of the app
|
60
|
+
`examples`.
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
```sh
|
65
|
-
$ echo 'coolio' | fn run --format default
|
66
|
-
{"message":"Hello coolio!"}
|
67
|
-
```
|
62
|
+
With an fn server running (see
|
63
|
+
[Quickstart](https://github.com/fnproject/fn/blob/master/README.md) if you need instructions):
|
68
64
|
|
69
|
-
|
65
|
+
`cd` to the [hello-ruby](examples/hello-ruby) folder and run:
|
70
66
|
|
71
67
|
```sh
|
72
|
-
fn deploy --app
|
68
|
+
fn deploy --app examples --local
|
73
69
|
```
|
74
70
|
|
75
|
-
|
71
|
+
The `--app examples` option tells fn to deploy the function as part of
|
72
|
+
the _app_ named _examples_.
|
73
|
+
|
74
|
+
The `--local` option tells fn not to push the function image to Docker
|
75
|
+
Hub.
|
76
76
|
|
77
|
-
|
77
|
+
## Invoking functions
|
78
|
+
Once we have deployed a function we can invoke it using `fn invoke`.
|
78
79
|
|
80
|
+
Running the [Hello World](examples/hello-ruby) example:
|
79
81
|
```sh
|
80
|
-
|
82
|
+
$ fn invoke examples hello
|
83
|
+
{"message":"Hello World!"}
|
84
|
+
```
|
85
|
+
To get a more personal message, send a name in a JSON format and set the
|
86
|
+
`content-type 'application/json'`:
|
87
|
+
```
|
88
|
+
echo '{"name":"Joe"}' | fn invoke examples hello --content-type
|
89
|
+
'application/json'
|
90
|
+
{"message":"Hello Joe!"}
|
81
91
|
```
|
82
92
|
|
83
|
-
## Compare cold and hot
|
93
|
+
## Compare cold and hot functions
|
84
94
|
|
85
|
-
Run
|
95
|
+
Run [loop.rb](examples/loop.rb)
|
86
96
|
|
87
97
|
```sh
|
88
98
|
ruby loop.rb
|
data/lib/fdk/runner.rb
CHANGED
@@ -63,7 +63,7 @@ module FDK
|
|
63
63
|
'type' => 'http',
|
64
64
|
'request_url' => ENV['FN_REQUEST_URL']
|
65
65
|
}
|
66
|
-
output_stream.puts FDK.single_event(function: function, context: Context.new(event), input: input_stream.read).to_json
|
66
|
+
output_stream.puts FDK.single_event(function: function, context: Context.new(event), input: input_stream.read.chomp).to_json
|
67
67
|
else
|
68
68
|
raise "Format '#{format}' not supported in Ruby FDK."
|
69
69
|
end
|
data/lib/fdk/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Reeder
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-09-
|
12
|
+
date: 2018-09-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|