File tree Expand file tree Collapse file tree 11 files changed +82
-9
lines changed Expand file tree Collapse file tree 11 files changed +82
-9
lines changed Original file line number Diff line number Diff line change 1
1
* .pyc
2
+ build
Original file line number Diff line number Diff line change 1
- # python27-flask-template
2
- Python 2.7 OpenFaaS template with Flask
1
+ # python-flask-template
3
2
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:
5
6
6
7
``` 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
+ ```
10
14
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
11
20
```
12
21
13
22
Followed by the usual flow:
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ FROM python:2.7-alpine
3
3
# Alternatively use ADD https:// (which will not be cached by Docker builder)
4
4
RUN apk --no-cache add curl \
5
5
&& 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 \
7
7
&& chmod +x /usr/bin/fwatchdog \
8
8
&& apk del curl --no-cache
9
9
Original file line number Diff line number Diff line change 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
+ """
3
6
7
+ return req
Original file line number Diff line number Diff line change
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" ]
Original file line number Diff line number Diff line change
1
+ def handle (req ):
2
+ """handle a request to the function
3
+ Args:
4
+ req (str): request body
5
+ """
6
+
7
+ return req
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
1
+ flask
2
+
You can’t perform that action at this time.
0 commit comments