Add OpenFaaS Clear Linux based python3 template

Signed-off-by: Qi Zheng <qi.zheng@intel.com>
This commit is contained in:
Qi Zheng
2019-12-04 01:34:50 +00:00
committed by qzheng527
parent 8304a1e565
commit f5bd2001ba
10 changed files with 128 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
# OpenFaaS template based on Clear Linux
## How to use the template
Assume you already had deployed workable OpenFaaS on top of Kubernetes.
Steps could refer to
[deployment-guide-for-kubernetes](https://docs.openfaas.com/deployment/kubernetes/#deployment-guide-for-kubernetes)
[OpenFaaS workshop](https://github.com/openfaas/workshop)
### python3-clearlinux
1. `mkdir test && cd test`
2. `cp -r "<your-dockerfiles-path>"/FaaS/OpenFaaS/template/. template/`
3. `faas-cli new --lang python3-clearlinux hello-openfaas --prefix="<your-docker-username-here>"`
Files tree as below.
>
├── hello-openfaas
│   ├── bundles.txt
│   ├── handler.py
│   ├── __init__.py
│   └── requirements.txt
├── hello-openfaas.yml
└── template
* Put the required python packages in the "requirements.txt".
For example,
`echo "redis" >> hello-openfaas/requirements.txt`
`echo "flask" >> hello-openfaas/requirements.txt`
* Put the required Clear Linux bundles in the "bundles.txt".
For example,
`echo "openblas" >> hello-openfaas/bundles.txt`
`echo "wget" >> hello-openfaas/bundles.txt`
4. `faas-cli up -f hello-openfaas.yml`
Then you can invoke your python function by OpenFaas UI or faas-cli.
## Proxy and Clear Linux mirror
When working behind a Proxy, you can pass proxy settings to faas-cli commands by "--build-arg".
Also to speed up the Clear Linux bundle install, you could use mirror if you are inside Intel.
For example,
`faas-cli up --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy --build-arg swupd_args="-u $mirror --allow-insecure-http" -f hello-openfaas.yml`
@@ -0,0 +1,46 @@
FROM openfaas/classic-watchdog:0.18.1 as watchdog
FROM clearlinux/python:3
ARG swupd_args
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
RUN chmod +x /usr/bin/fwatchdog
WORKDIR /root/
COPY index.py .
# pip install python packages if required
COPY requirements.txt .
RUN pip install -r requirements.txt
# install bundles if required
# PLEASE input bundle line by line
COPY bundles.txt .
RUN for bundle in $(cat bundles.txt); do \
swupd bundle-add $bundle $swupd_args; \
done
RUN mkdir -p function
RUN touch ./function/__init__.py
WORKDIR /root/function/
# pip install python packages if required
COPY function/requirements.txt .
RUN pip install -r requirements.txt
# install bundles if required
# PLEASE input bundle line by line
COPY function/bundles.txt .
RUN for bundle in $(cat bundles.txt); do \
swupd bundle-add $bundle $swupd_args; \
done
WORKDIR /root/
COPY function function
ENV fprocess="python3 index.py"
EXPOSE 8080
HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1
CMD ["fwatchdog"]
@@ -0,0 +1,7 @@
def handle(req):
"""handle a request to the function
Args:
req (str): request body
"""
return req
@@ -0,0 +1,21 @@
# Copyright (c) Alex Ellis 2017. All rights reserved.
# Copyright (c) OpenFaaS Author(s) 2018. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
import sys
from function import handler
def get_stdin():
buf = ""
while(True):
line = sys.stdin.readline()
buf += line
if line == "":
break
return buf
if __name__ == "__main__":
st = get_stdin()
ret = handler.handle(st)
if ret != None:
print(ret)
@@ -0,0 +1,2 @@
language: python3
fprocess: python3 index.py