diff --git a/examples/hello/python3/.gitignore b/examples/hello/python3/.gitignore new file mode 100644 index 00000000..44536cce --- /dev/null +++ b/examples/hello/python3/.gitignore @@ -0,0 +1,2 @@ +packages/ +func.yaml diff --git a/examples/hello/python3/Dockerfile b/examples/hello/python3/Dockerfile new file mode 100644 index 00000000..5c742a27 --- /dev/null +++ b/examples/hello/python3/Dockerfile @@ -0,0 +1,6 @@ +FROM iron/python:3 + +WORKDIR /app +ADD . /app + +ENTRYPOINT ["python3", "hello.py"] diff --git a/examples/hello/python3/README.md b/examples/hello/python3/README.md new file mode 100644 index 00000000..6e88b9cc --- /dev/null +++ b/examples/hello/python3/README.md @@ -0,0 +1,49 @@ +## Quick Example for a Python3 Function (4 minutes) + +This example will show you how to test and deploy Python3 code to IronFunctions. + +### 1. Prepare the `func.yaml` file: + +At func.yaml you will find: + +```yml +name: USERNAME/hellopy3 +version: 0.0.1 +path: /hellopy3 +build: +- docker run --rm -v "$PWD":/worker -w /worker iron/python:3-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 `python3app` and the route for incoming requests is `/hellopy3`. 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 IronFunctions +fn routes create python3app /hellopy3 +``` + +`-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 python3app /hellopy3 +``` + +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/python3app/hellopy3 +``` diff --git a/examples/hello/python3/hello.payload.json b/examples/hello/python3/hello.payload.json new file mode 100644 index 00000000..97e136b6 --- /dev/null +++ b/examples/hello/python3/hello.payload.json @@ -0,0 +1,3 @@ +{ + "name": "Johnny" +} diff --git a/examples/hello/python3/hello.py b/examples/hello/python3/hello.py new file mode 100644 index 00000000..986ef379 --- /dev/null +++ b/examples/hello/python3/hello.py @@ -0,0 +1,16 @@ +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, "!!!", + " from python version", + str(sys.version_info.major) + '.' + + str(sys.version_info.minor) + '.' + + str(sys.version_info.micro)) diff --git a/examples/hello/python3/requirements.txt b/examples/hello/python3/requirements.txt new file mode 100644 index 00000000..e69de29b