Skip to content

Commit d276066

Browse files
committed
Add Python3 flask template
Adds Python3 flask template and adds pydoc to the handler for both templates. Signed-off-by: Alex Ellis (VMware) <[email protected]>
1 parent 79ec83f commit d276066

File tree

11 files changed

+82
-9
lines changed

11 files changed

+82
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.pyc
2+
build

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
# python27-flask-template
2-
Python 2.7 OpenFaaS template with Flask
1+
# python-flask-template
32

4-
To try this out:
3+
Python OpenFaaS template with Flask
4+
5+
To try this out with either Python 2.7 or Python 3.6:
56

67
```bash
7-
faas template pull https://github.com/alexellis/python27-flask-template
8-
faas new --lang python27-flask myfunction
9-
mv myfunction.yml stack.yml
8+
faas template pull https://github.com/openfaas-incubator/python-flask-template
9+
faas new --list
10+
Languages available as templates:
11+
- python27-flask
12+
- python3-flask
13+
```
1014

15+
Generate a function with one of the languages:
16+
17+
```bash
18+
faas new --lang python3-flask myfunction
19+
mv myfunction.yml stack.yml
1120
```
1221

1322
Followed by the usual flow:

template/python27-flask/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM python:2.7-alpine
33
# Alternatively use ADD https:// (which will not be cached by Docker builder)
44
RUN apk --no-cache add curl \
55
&& echo "Pulling watchdog binary from Github." \
6-
&& curl -sSLf https://github.com/openfaas-incubator/of-watchdog/releases/download/0.2.1/of-watchdog > /usr/bin/fwatchdog \
6+
&& curl -sSLf https://github.com/openfaas-incubator/of-watchdog/releases/download/0.2.3/of-watchdog > /usr/bin/fwatchdog \
77
&& chmod +x /usr/bin/fwatchdog \
88
&& apk del curl --no-cache
99

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
def handle(st):
2-
return "You said: " + st
1+
def handle(req):
2+
"""handle a request to the function
3+
Args:
4+
req (str): request body
5+
"""
36

7+
return req

template/python3-flask/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM python:3.6-alpine
2+
3+
# Alternatively use ADD https:// (which will not be cached by Docker builder)
4+
RUN apk --no-cache add curl \
5+
&& echo "Pulling watchdog binary from Github." \
6+
&& curl -sSLf https://github.com/openfaas-incubator/of-watchdog/releases/download/0.2.3/of-watchdog > /usr/bin/fwatchdog \
7+
&& chmod +x /usr/bin/fwatchdog \
8+
&& apk del curl --no-cache
9+
10+
WORKDIR /root/
11+
12+
COPY requirements.txt .
13+
RUN pip install -r requirements.txt
14+
COPY index.py .
15+
16+
RUN mkdir -p function
17+
RUN touch ./function/__init__.py
18+
WORKDIR /root/function/
19+
COPY function/requirements.txt .
20+
RUN pip install -r requirements.txt
21+
22+
WORKDIR /root/
23+
COPY function function
24+
25+
ENV fprocess="python index.py"
26+
ENV cgi_headers="true"
27+
ENV mode="http"
28+
ENV upstream_url="http://127.0.0.1:5000"
29+
30+
31+
HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1
32+
33+
CMD ["fwatchdog"]

template/python3-flask/function/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def handle(req):
2+
"""handle a request to the function
3+
Args:
4+
req (str): request body
5+
"""
6+
7+
return req

template/python3-flask/function/requirements.txt

Whitespace-only changes.

template/python3-flask/index.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) Alex Ellis 2017. All rights reserved.
2+
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
from flask import Flask, request
5+
from function import handler
6+
7+
app = Flask(__name__)
8+
9+
@app.route("/", methods=["POST", "GET"])
10+
def main_route():
11+
ret = handler.handle(request.get_data())
12+
return ret
13+
14+
if __name__ == '__main__':
15+
app.run(host='0.0.0.0', port=5000, debug=False)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
flask
2+

0 commit comments

Comments
 (0)