mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
More doc updates, explanation of serverless. (#228)
* More doc updates, explanation of serverless. * Moved howto directory to examples and some minor doc updates. * Added apps and routes docs. * Fixes for Carlos' comments. * Added bit about importing lambda functions.
This commit is contained in:
@@ -2,7 +2,6 @@ require 'json'
|
||||
|
||||
name = "World"
|
||||
|
||||
|
||||
payload = STDIN.read
|
||||
if payload != ""
|
||||
payload = JSON.parse(payload)
|
||||
|
||||
5
examples/hello/go/.gitignore
vendored
Normal file
5
examples/hello/go/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
vendor/
|
||||
/hello
|
||||
/go
|
||||
/app
|
||||
/__uberscript__
|
||||
6
examples/hello/go/Dockerfile
Normal file
6
examples/hello/go/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM iron/go
|
||||
|
||||
WORKDIR /app
|
||||
ADD . /app
|
||||
|
||||
ENTRYPOINT ["./hello"]
|
||||
40
examples/hello/go/README.md
Normal file
40
examples/hello/go/README.md
Normal file
@@ -0,0 +1,40 @@
|
||||
## Quick Example for a Go Function (3 minutes)
|
||||
|
||||
This example will show you how to test and deploy Go (Golang) code to IronFunctions.
|
||||
|
||||
### 1. Prepare the `functions.yaml` file:
|
||||
|
||||
At functions.yaml you will find:
|
||||
```yml
|
||||
app: goapp
|
||||
route: /hello
|
||||
image: USERNAME/hello:0.0.1
|
||||
build:
|
||||
- docker run --rm -v "$PWD":/go/src/ -w /go/src/ -e "GOPATH=/go/src/vendor:/go" iron/go:dev go build -o hello
|
||||
```
|
||||
|
||||
The important step here is to ensure you replace `USERNAME` with your Docker Hub account name. Some points of note:
|
||||
the application name is `goapp` and the route for incoming requests is `/hello`. These informations are relevant for
|
||||
the moment you try to test this function.
|
||||
|
||||
### 2. Build:
|
||||
|
||||
```sh
|
||||
fnctl publish
|
||||
```
|
||||
|
||||
`-v` is optional, but it allows you to see how this function is being built.
|
||||
|
||||
### 3. Queue jobs for your function
|
||||
|
||||
Now you can start jobs on your function. Let's quickly queue up a job to try it out.
|
||||
|
||||
```sh
|
||||
cat hello.payload.json | fnctl run goapp /hello
|
||||
```
|
||||
|
||||
Here's a curl example to show how easy it is to do in any language:
|
||||
|
||||
```sh
|
||||
curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/goapp/hello
|
||||
```
|
||||
5
examples/hello/go/functions.yaml
Normal file
5
examples/hello/go/functions.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
app: goapp
|
||||
route: /hello
|
||||
image: USERNAME/hello:0.0.1
|
||||
build:
|
||||
- docker run --rm -v "$PWD":/go/src/ -w /go/src/ -e "GOPATH=/go/src/vendor:/go" iron/go:dev go build -o hello
|
||||
17
examples/hello/go/hello.go
Normal file
17
examples/hello/go/hello.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func main() {
|
||||
p := &Person{Name: "World"}
|
||||
json.NewDecoder(os.Stdin).Decode(p)
|
||||
fmt.Println("Hello", p.Name, "!!!")
|
||||
}
|
||||
3
examples/hello/go/hello.payload.json
Normal file
3
examples/hello/go/hello.payload.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "Johnny"
|
||||
}
|
||||
1
examples/hello/node/.gitignore
vendored
Normal file
1
examples/hello/node/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules/
|
||||
6
examples/hello/node/Dockerfile
Normal file
6
examples/hello/node/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM iron/node
|
||||
|
||||
WORKDIR /app
|
||||
ADD . /app
|
||||
|
||||
ENTRYPOINT ["node", "hello.js"]
|
||||
40
examples/hello/node/README.md
Normal file
40
examples/hello/node/README.md
Normal file
@@ -0,0 +1,40 @@
|
||||
## Quick Example for a NodeJS Function (4 minutes)
|
||||
|
||||
This example will show you how to test and deploy Go (Golang) code to IronFunctions.
|
||||
|
||||
### 1. Prepare the `functions.yaml` file:
|
||||
|
||||
At functions.yaml you will find:
|
||||
```yml
|
||||
app: nodeapp
|
||||
route: /hello
|
||||
image: USERNAME/hello:0.0.1
|
||||
build:
|
||||
- docker run --rm -v "$PWD":/worker -w /worker iron/node:dev npm install
|
||||
```
|
||||
|
||||
The important step here is to ensure you replace `USERNAME` with your Docker Hub account name. Some points of note:
|
||||
the application name is `nodeapp` and the route for incoming requests is `/hello`. These informations are relevant for
|
||||
the moment you try to test this function.
|
||||
|
||||
### 2. Build:
|
||||
|
||||
```sh
|
||||
fnctl publish
|
||||
```
|
||||
|
||||
`-v` is optional, but it allows you to see how this function is being built.
|
||||
|
||||
### 3. Queue jobs for your function
|
||||
|
||||
Now you can start jobs on your function. Let's quickly queue up a job to try it out.
|
||||
|
||||
```sh
|
||||
cat hello.payload.json | fnctl run nodeapp /hello
|
||||
```
|
||||
|
||||
Here's a curl example to show how easy it is to do in any language:
|
||||
|
||||
```sh
|
||||
curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/nodeapp/hello
|
||||
```
|
||||
5
examples/hello/node/functions.yaml
Normal file
5
examples/hello/node/functions.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
app: nodeapp
|
||||
route: /hello
|
||||
image: USERNAME/hello:0.0.1
|
||||
build:
|
||||
- docker run --rm -v "$PWD":/worker -w /worker iron/node:dev npm install
|
||||
9
examples/hello/node/hello.js
Normal file
9
examples/hello/node/hello.js
Normal file
@@ -0,0 +1,9 @@
|
||||
name = "World";
|
||||
fs = require('fs');
|
||||
try {
|
||||
obj = JSON.parse(fs.readFileSync('/dev/stdin').toString())
|
||||
if (obj.name != "") {
|
||||
name = obj.name
|
||||
}
|
||||
} catch(e) {}
|
||||
console.log("Hello", name, "from Node!");
|
||||
3
examples/hello/node/hello.payload.json
Normal file
3
examples/hello/node/hello.payload.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "Johnny"
|
||||
}
|
||||
4
examples/hello/node/package.json
Normal file
4
examples/hello/node/package.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
||||
1
examples/hello/php/.gitignore
vendored
Normal file
1
examples/hello/php/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
vendor/
|
||||
6
examples/hello/php/Dockerfile
Normal file
6
examples/hello/php/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM iron/php
|
||||
|
||||
WORKDIR /app
|
||||
ADD . /app
|
||||
|
||||
ENTRYPOINT ["php", "hello.php"]
|
||||
40
examples/hello/php/README.md
Normal file
40
examples/hello/php/README.md
Normal file
@@ -0,0 +1,40 @@
|
||||
## Quick Example for a PHP Function (4 minutes)
|
||||
|
||||
This example will show you how to test and deploy Go (Golang) code to IronFunctions.
|
||||
|
||||
### 1. Prepare the `functions.yaml` file:
|
||||
|
||||
At functions.yaml you will find:
|
||||
```yml
|
||||
app: phpapp
|
||||
route: /hello
|
||||
image: USERNAME/hello:0.0.1
|
||||
build:
|
||||
- docker run --rm -v "$PWD":/worker -w /worker iron/php:dev composer install
|
||||
```
|
||||
|
||||
The important step here is to ensure you replace `USERNAME` with your Docker Hub account name. Some points of note:
|
||||
the application name is `phpapp` and the route for incoming requests is `/hello`. These informations are relevant for
|
||||
the moment you try to test this function.
|
||||
|
||||
### 2. Build:
|
||||
|
||||
```sh
|
||||
fnctl publish
|
||||
```
|
||||
|
||||
`-v` is optional, but it allows you to see how this function is being built.
|
||||
|
||||
### 3. Queue jobs for your function
|
||||
|
||||
Now you can start jobs on your function. Let's quickly queue up a job to try it out.
|
||||
|
||||
```sh
|
||||
cat hello.payload.json | fnctl run phpapp /hello
|
||||
```
|
||||
|
||||
Here's a curl example to show how easy it is to do in any language:
|
||||
|
||||
```sh
|
||||
curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/phpapp/hello
|
||||
```
|
||||
4
examples/hello/php/composer.json
Normal file
4
examples/hello/php/composer.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"require": {
|
||||
}
|
||||
}
|
||||
5
examples/hello/php/functions.yaml
Normal file
5
examples/hello/php/functions.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
app: phpapp
|
||||
route: /hello
|
||||
image: USERNAME/hello:0.0.1
|
||||
build:
|
||||
- docker run --rm -v "$PWD":/worker -w /worker iron/php:dev composer install
|
||||
3
examples/hello/php/hello.payload.json
Normal file
3
examples/hello/php/hello.payload.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "Johnny"
|
||||
}
|
||||
10
examples/hello/php/hello.php
Normal file
10
examples/hello/php/hello.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
stream_set_blocking(STDIN, 0);
|
||||
$payload = json_decode(file_get_contents("php://stdin"), true);
|
||||
if (isset($payload['name'])) {
|
||||
echo "Hello ", $payload['name'],"!\n\n";
|
||||
} else {
|
||||
echo "Hello World!\n\n";
|
||||
}
|
||||
1
examples/hello/python/.gitignore
vendored
Normal file
1
examples/hello/python/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
packages/
|
||||
6
examples/hello/python/Dockerfile
Normal file
6
examples/hello/python/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM iron/python:2
|
||||
|
||||
WORKDIR /app
|
||||
ADD . /app
|
||||
|
||||
ENTRYPOINT ["python", "hello.py"]
|
||||
40
examples/hello/python/README.md
Normal file
40
examples/hello/python/README.md
Normal file
@@ -0,0 +1,40 @@
|
||||
## Quick Example for a Python Function (4 minutes)
|
||||
|
||||
This example will show you how to test and deploy Go (Golang) code to IronFunctions.
|
||||
|
||||
### 1. Prepare the `functions.yaml` file:
|
||||
|
||||
At functions.yaml you will find:
|
||||
```yml
|
||||
app: pythonapp
|
||||
route: /hello
|
||||
image: USERNAME/hello:0.0.1
|
||||
build:
|
||||
- docker run --rm -v "$PWD":/worker -w /worker iron/python:2-dev pip install -t packages -r requirements.txt
|
||||
```
|
||||
|
||||
The important step here is to ensure you replace `USERNAME` with your Docker Hub account name. Some points of note:
|
||||
the application name is `pythonapp` and the route for incoming requests is `/hello`. These informations are relevant for
|
||||
the moment you try to test this function.
|
||||
|
||||
### 2. Build:
|
||||
|
||||
```sh
|
||||
fnctl publish
|
||||
```
|
||||
|
||||
`-v` is optional, but it allows you to see how this function is being built.
|
||||
|
||||
### 3. Queue jobs for your function
|
||||
|
||||
Now you can start jobs on your function. Let's quickly queue up a job to try it out.
|
||||
|
||||
```sh
|
||||
cat hello.payload.json | fnctl run pythonapp /hello
|
||||
```
|
||||
|
||||
Here's a curl example to show how easy it is to do in any language:
|
||||
|
||||
```sh
|
||||
curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/pythonapp/hello
|
||||
```
|
||||
5
examples/hello/python/functions.yaml
Normal file
5
examples/hello/python/functions.yaml
Normal file
@@ -0,0 +1,5 @@
|
||||
app: pythonapp
|
||||
route: /hello
|
||||
image: USERNAME/hello:0.0.1
|
||||
build:
|
||||
- docker run --rm -v "$PWD":/worker -w /worker iron/python:2-dev pip install -t packages -r requirements.txt
|
||||
3
examples/hello/python/hello.payload.json
Normal file
3
examples/hello/python/hello.payload.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "Johnny"
|
||||
}
|
||||
12
examples/hello/python/hello.py
Normal file
12
examples/hello/python/hello.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import sys
|
||||
sys.path.append("packages")
|
||||
import os
|
||||
import json
|
||||
|
||||
name = "World"
|
||||
if not os.isatty(sys.stdin.fileno()):
|
||||
obj = json.loads(sys.stdin.read())
|
||||
if obj["name"] != "":
|
||||
name = obj["name"]
|
||||
|
||||
print "Hello", name, "!!!"
|
||||
0
examples/hello/python/requirements.txt
Normal file
0
examples/hello/python/requirements.txt
Normal file
Reference in New Issue
Block a user