Skip to content

Commit 29ff8a7

Browse files
committed
Add Python3 / Flask template for armhf
This template was tested on Kubernetes with RPi3b+ and enables a much faster response time for Python3 on the armhf platform. Signed-off-by: Alex Ellis (VMware) <[email protected]>
1 parent cf65d0a commit 29ff8a7

File tree

7 files changed

+68
-0
lines changed

7 files changed

+68
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM armhf/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.4/of-watchdog-armhf > /usr/bin/fwatchdog \
7+
&& chmod +x /usr/bin/fwatchdog \
8+
&& apk del curl --no-cache
9+
10+
RUN apk --no-cache add musl-dev gcc make openssl-dev libffi-dev
11+
12+
WORKDIR /root/
13+
14+
COPY requirements.txt .
15+
RUN pip install -r requirements.txt
16+
COPY index.py .
17+
18+
RUN mkdir -p function
19+
RUN touch ./function/__init__.py
20+
WORKDIR /root/function/
21+
COPY function/requirements.txt .
22+
RUN pip install -r requirements.txt
23+
24+
WORKDIR /root/
25+
COPY function function
26+
27+
ENV fprocess="python index.py"
28+
29+
ENV cgi_headers="true"
30+
ENV mode="http"
31+
ENV upstream_url="http://127.0.0.1:5000"
32+
33+
34+
HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1
35+
36+
CMD ["fwatchdog"]

template/python3-flask-armhf/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-armhf/function/requirements.txt

Whitespace-only changes.

template/python3-flask-armhf/index.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
#from gevent.wsgi import WSGIServer
7+
from gevent.pywsgi import WSGIServer
8+
9+
app = Flask(__name__)
10+
11+
@app.route("/", methods=["POST", "GET"])
12+
def main_route():
13+
ret = handler.handle(request.get_data())
14+
return ret
15+
16+
if __name__ == '__main__':
17+
#app.run(host='0.0.0.0', port=5000, debug=False)
18+
19+
http_server = WSGIServer(('', 5000), app)
20+
http_server.serve_forever()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
flask
2+
gevent
3+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
language: python3-flask-armhf
2+
fprocess: python index.py

0 commit comments

Comments
 (0)