diff --git a/FaaS/OpenFaaS/template/README.md b/FaaS/OpenFaaS/template/README.md new file mode 100644 index 0000000..d07975c --- /dev/null +++ b/FaaS/OpenFaaS/template/README.md @@ -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 ""/FaaS/OpenFaaS/template/. template/` +3. `faas-cli new --lang python3-clearlinux hello-openfaas --prefix=""` + + 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` diff --git a/FaaS/OpenFaaS/template/python3-clearlinux/Dockerfile b/FaaS/OpenFaaS/template/python3-clearlinux/Dockerfile new file mode 100644 index 0000000..a40be1e --- /dev/null +++ b/FaaS/OpenFaaS/template/python3-clearlinux/Dockerfile @@ -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"] diff --git a/FaaS/OpenFaaS/template/python3-clearlinux/bundles.txt b/FaaS/OpenFaaS/template/python3-clearlinux/bundles.txt new file mode 100644 index 0000000..e69de29 diff --git a/FaaS/OpenFaaS/template/python3-clearlinux/function/__init__.py b/FaaS/OpenFaaS/template/python3-clearlinux/function/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/FaaS/OpenFaaS/template/python3-clearlinux/function/bundles.txt b/FaaS/OpenFaaS/template/python3-clearlinux/function/bundles.txt new file mode 100644 index 0000000..e69de29 diff --git a/FaaS/OpenFaaS/template/python3-clearlinux/function/handler.py b/FaaS/OpenFaaS/template/python3-clearlinux/function/handler.py new file mode 100644 index 0000000..a7098fa --- /dev/null +++ b/FaaS/OpenFaaS/template/python3-clearlinux/function/handler.py @@ -0,0 +1,7 @@ +def handle(req): + """handle a request to the function + Args: + req (str): request body + """ + + return req diff --git a/FaaS/OpenFaaS/template/python3-clearlinux/function/requirements.txt b/FaaS/OpenFaaS/template/python3-clearlinux/function/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/FaaS/OpenFaaS/template/python3-clearlinux/index.py b/FaaS/OpenFaaS/template/python3-clearlinux/index.py new file mode 100644 index 0000000..6e1a22f --- /dev/null +++ b/FaaS/OpenFaaS/template/python3-clearlinux/index.py @@ -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) diff --git a/FaaS/OpenFaaS/template/python3-clearlinux/requirements.txt b/FaaS/OpenFaaS/template/python3-clearlinux/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/FaaS/OpenFaaS/template/python3-clearlinux/template.yml b/FaaS/OpenFaaS/template/python3-clearlinux/template.yml new file mode 100644 index 0000000..ea405e8 --- /dev/null +++ b/FaaS/OpenFaaS/template/python3-clearlinux/template.yml @@ -0,0 +1,2 @@ +language: python3 +fprocess: python3 index.py