From ce1d597040179038553242d2df976c5df8b8ca0c Mon Sep 17 00:00:00 2001 From: Qi Zheng Date: Mon, 9 Dec 2019 07:05:57 +0000 Subject: [PATCH] Add OpenFaaS dockerfile template Signed-off-by: Qi Zheng --- FaaS/OpenFaaS/template/README.md | 23 ++++++++++++ .../template/dockerfile-clearlinux/Dockerfile | 37 +++++++++++++++++++ .../dockerfile-clearlinux/function/Dockerfile | 36 ++++++++++++++++++ .../function/bundles.txt | 0 .../dockerfile-clearlinux/template.yml | 1 + 5 files changed, 97 insertions(+) create mode 100644 FaaS/OpenFaaS/template/dockerfile-clearlinux/Dockerfile create mode 100644 FaaS/OpenFaaS/template/dockerfile-clearlinux/function/Dockerfile create mode 100644 FaaS/OpenFaaS/template/dockerfile-clearlinux/function/bundles.txt create mode 100644 FaaS/OpenFaaS/template/dockerfile-clearlinux/template.yml diff --git a/FaaS/OpenFaaS/template/README.md b/FaaS/OpenFaaS/template/README.md index d07975c..79c549b 100644 --- a/FaaS/OpenFaaS/template/README.md +++ b/FaaS/OpenFaaS/template/README.md @@ -10,6 +10,29 @@ Steps could refer to [OpenFaaS workshop](https://github.com/openfaas/workshop) +### dockerfile-clearlinux +1. `mkdir test && cd test` +2. `cp -r ""/FaaS/OpenFaaS/template/. template/` +3. `faas-cli new --lang dockerfile-clearlinux hello-dockerfile --prefix=""` + + Files tree as below. +> + ├── hello-dockerfile + │   ├── bundles.txt + │   └── Dockerfile + ├── hello-dockerfile.yml + + * Put the required Clear Linux bundles in the "bundles.txt". + For example, + + `echo "openblas" >> hello-dockerfile/bundles.txt` + `echo "wget" >> hello-dockerfile/bundles.txt` +4. Replace the "cat" in the Dockerfile line below per your requirement. + ENV fprocess="cat" +5. `faas-cli up -f hello-dockerfile.yml` + + Then you can invoke your python function by OpenFaas UI or faas-cli. + ### python3-clearlinux 1. `mkdir test && cd test` 2. `cp -r ""/FaaS/OpenFaaS/template/. template/` diff --git a/FaaS/OpenFaaS/template/dockerfile-clearlinux/Dockerfile b/FaaS/OpenFaaS/template/dockerfile-clearlinux/Dockerfile new file mode 100644 index 0000000..5c6b245 --- /dev/null +++ b/FaaS/OpenFaaS/template/dockerfile-clearlinux/Dockerfile @@ -0,0 +1,37 @@ +FROM openfaas/classic-watchdog:0.18.1 as watchdog + +FROM clearlinux:base + +ARG swupd_args + +COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog +RUN chmod +x /usr/bin/fwatchdog + +# Add non root user +RUN useradd app + +RUN mkdir -p /root/function +WORKDIR /root/function/ + +# 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 /home/app + +USER app + +# Populate example here - i.e. "cat", "sha512sum" or "node index.js" +ENV fprocess="cat" +# Set to true to see request in function logs +ENV write_debug="false" + +EXPOSE 8080 + +HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1 + +CMD ["fwatchdog"] diff --git a/FaaS/OpenFaaS/template/dockerfile-clearlinux/function/Dockerfile b/FaaS/OpenFaaS/template/dockerfile-clearlinux/function/Dockerfile new file mode 100644 index 0000000..3fdbd29 --- /dev/null +++ b/FaaS/OpenFaaS/template/dockerfile-clearlinux/function/Dockerfile @@ -0,0 +1,36 @@ +FROM openfaas/classic-watchdog:0.18.1 as watchdog + +FROM clearlinux:base + +ARG swupd_args + +COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog +RUN chmod +x /usr/bin/fwatchdog + +# Add non root user +RUN useradd app + +WORKDIR /root/function/ + +# 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 /home/app + +USER app + +# Populate example here - i.e. "cat", "sha512sum" or "node index.js" +ENV fprocess="cat" +# Set to true to see request in function logs +ENV write_debug="false" + +EXPOSE 8080 + +HEALTHCHECK --interval=5s CMD [ -e /tmp/.lock ] || exit 1 + +CMD ["fwatchdog"] diff --git a/FaaS/OpenFaaS/template/dockerfile-clearlinux/function/bundles.txt b/FaaS/OpenFaaS/template/dockerfile-clearlinux/function/bundles.txt new file mode 100644 index 0000000..e69de29 diff --git a/FaaS/OpenFaaS/template/dockerfile-clearlinux/template.yml b/FaaS/OpenFaaS/template/dockerfile-clearlinux/template.yml new file mode 100644 index 0000000..b4b5138 --- /dev/null +++ b/FaaS/OpenFaaS/template/dockerfile-clearlinux/template.yml @@ -0,0 +1 @@ +language: dockerfile-clearlinux