mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
more tutorial
This commit is contained in:
2
examples/tutorial/hello/python/.gitignore
vendored
Normal file
2
examples/tutorial/hello/python/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
packages/
|
||||
func.yaml
|
||||
6
examples/tutorial/hello/python/Dockerfile
Normal file
6
examples/tutorial/hello/python/Dockerfile
Normal file
@@ -0,0 +1,6 @@
|
||||
FROM funcy/python:2
|
||||
|
||||
WORKDIR /app
|
||||
ADD . /app
|
||||
|
||||
ENTRYPOINT ["python", "hello.py"]
|
||||
48
examples/tutorial/hello/python/README.md
Normal file
48
examples/tutorial/hello/python/README.md
Normal file
@@ -0,0 +1,48 @@
|
||||
## Quick Example for a Python Function (4 minutes)
|
||||
|
||||
This example will show you how to test and deploy Go (Golang) code to Oracle Functions.
|
||||
|
||||
### 1. Prepare the `func.yaml` file:
|
||||
|
||||
At func.yaml you will find:
|
||||
|
||||
```yml
|
||||
name: USERNAME/hello
|
||||
version: 0.0.1
|
||||
path: /hello
|
||||
build:
|
||||
- docker run --rm -v "$PWD":/worker -w /worker funcy/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
|
||||
# build the function
|
||||
fn build
|
||||
# test it
|
||||
cat hello.payload.json | fn run
|
||||
# push it to Docker Hub
|
||||
fn push
|
||||
# Create a route to this function on Oracle Functions
|
||||
fn routes create pythonapp /hello
|
||||
```
|
||||
|
||||
`-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 | fn call 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
|
||||
```
|
||||
3
examples/tutorial/hello/python/hello.payload.json
Normal file
3
examples/tutorial/hello/python/hello.payload.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "Johnny"
|
||||
}
|
||||
12
examples/tutorial/hello/python/hello.py
Normal file
12
examples/tutorial/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/tutorial/hello/python/requirements.txt
Normal file
0
examples/tutorial/hello/python/requirements.txt
Normal file
Reference in New Issue
Block a user