diff --git a/README.md b/README.md index dda8a20..7aa5d69 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,22 @@ faas-cli new --lang go \ NAME ``` +## Contents + +In most cases, alternatives have already been provided and are listed int the Function Store, or the [Languages section of the OpenFaaS documentation](https://docs.openfaas.com/languages/overview/). + +| Name | Language | Version | Linux base | Watchdog | Link +|:-----|:---------|:--------|:-----------|:---------|:---- +| go | Go | 1.23 | Alpine Linux | classic | [Legacy Go template (deprecated)](https://github.com/openfaas/templates/tree/master/template/go) +| bun-express | Bun | 1.0 | Alpine Linux | of-watchdog | [NodeJS template](https://github.com/openfaas/templates/tree/master/template/bun-express) +| node | NodeJS | 20 | Alpine Linux | classic | [Legacy NodeJS template (deprecated)](https://github.com/openfaas/templates/tree/master/template/node) +| python3 | Python | 3 | Alpine Linux | classic | [Legacy Python 3 template](https://github.com/openfaas/templates/tree/master/template/python3) +| python3-debian | Python | 3 | Debian Linux | classic | [Legacy Python 3 Debian template](https://github.com/openfaas/templates/tree/master/template/python3-debian) +| python27 | Python | 2.7.18 | Alpine Linux | classic | [Python 2.7 template (deprecated)](https://github.com/openfaas/templates/tree/master/template/python27) +| ruby | Ruby | 3.3 | Alpine Linux | classic| [Ruby template](https://github.com/openfaas/templates/tree/master/template/ruby) +| csharp | C# | N/A | Debian GNU/Linux 9 | classic | [Legacy C# template (deprecated)](https://github.com/openfaas/templates/tree/master/template/csharp) + + ### License This project is part of the OpenFaaS project licensed under the MIT License. diff --git a/template/python27/Dockerfile b/template/python27/Dockerfile new file mode 100644 index 0000000..c209b9b --- /dev/null +++ b/template/python27/Dockerfile @@ -0,0 +1,55 @@ +FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/classic-watchdog:0.3.1 AS watchdog +FROM --platform=${TARGETPLATFORM:-linux/amd64} python:2.7.18-alpine + +ARG TARGETPLATFORM +ARG BUILDPLATFORM + +# Allows you to add additional packages via build-arg +ARG ADDITIONAL_PACKAGE + +COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog +RUN chmod +x /usr/bin/fwatchdog +RUN apk --no-cache add ca-certificates ${ADDITIONAL_PACKAGE} + +# Add non root user +RUN addgroup -S app && adduser app -S -G app + +WORKDIR /home/app/ + +COPY index.py . +COPY requirements.txt . + +RUN chown -R app /home/app && \ + mkdir -p /home/app/python && chown -R app /home/app +USER app +ENV PATH=$PATH:/home/app/.local/bin:/home/app/python/bin/ +ENV PYTHONPATH=$PYTHONPATH:/home/app/python + +RUN pip install -r requirements.txt --target=/home/app/python + +RUN mkdir -p function +RUN touch ./function/__init__.py + +WORKDIR /home/app/function/ +COPY function/requirements.txt . + +RUN pip install -r requirements.txt --target=/home/app/python + +WORKDIR /home/app/ + +USER root + +COPY function function + +# Allow any user-id for OpenShift users. +RUN chown -R app:app ./ && \ + chmod -R 777 /home/app/python + +USER app + +ENV fprocess="python index.py" +EXPOSE 8080 + +HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1 + +CMD ["fwatchdog"] diff --git a/template/python27/function/handler.py b/template/python27/function/handler.py new file mode 100644 index 0000000..a7098fa --- /dev/null +++ b/template/python27/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/template/python27/function/requirements.txt b/template/python27/function/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/template/python27/index.py b/template/python27/index.py new file mode 100644 index 0000000..5c0d24f --- /dev/null +++ b/template/python27/index.py @@ -0,0 +1,18 @@ +# 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 = "" + for line in sys.stdin: + buf = buf + line + return buf + +if __name__ == "__main__": + st = get_stdin() + ret = handler.handle(st) + if ret != None: + print(ret) diff --git a/template/python27/requirements.txt b/template/python27/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/template/python27/template.yml b/template/python27/template.yml new file mode 100644 index 0000000..5502733 --- /dev/null +++ b/template/python27/template.yml @@ -0,0 +1,30 @@ +language: python27 +fprocess: python index.py +build_options: + - name: dev + packages: + - make + - automake + - gcc + - g++ + - subversion + - python3-dev + - musl-dev + - libffi-dev + - git + - name: mysql + packages: + - mysql-client + - mysql-dev + - name: pillow + packages: + - jpeg-dev + - zlib-dev + - freetype-dev + - lcms2-dev + - openjpeg-dev + - tiff-dev + - tk-dev + - tcl-dev + - harfbuzz-dev + - fribidi-dev diff --git a/template/python3-debian/Dockerfile b/template/python3-debian/Dockerfile new file mode 100644 index 0000000..d83355e --- /dev/null +++ b/template/python3-debian/Dockerfile @@ -0,0 +1,58 @@ +ARG PYTHON_VERSION=3 +FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/classic-watchdog:0.3.1 AS watchdog +FROM --platform=${TARGETPLATFORM:-linux/amd64} python:${PYTHON_VERSION} + +ARG TARGETPLATFORM +ARG BUILDPLATFORM + +# Allows you to add additional packages via build-arg +ARG ADDITIONAL_PACKAGE + +COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog +RUN chmod +x /usr/bin/fwatchdog +RUN apt-get update \ + && apt-get install -y ca-certificates ${ADDITIONAL_PACKAGE} \ + && rm -rf /var/lib/apt/lists/ + +# Add non root user +RUN groupadd app && useradd -r -g app app + +WORKDIR /home/app/ + +COPY index.py . +COPY requirements.txt . + +RUN chown -R app /home/app && \ + mkdir -p /home/app/python && chown -R app /home/app +USER app +ENV PATH=$PATH:/home/app/.local/bin:/home/app/python/bin/ +ENV PYTHONPATH=$PYTHONPATH:/home/app/python + +RUN pip install -r requirements.txt --target=/home/app/python + +RUN mkdir -p function +RUN touch ./function/__init__.py + +WORKDIR /home/app/function/ +COPY function/requirements.txt . + +RUN pip install -r requirements.txt --target=/home/app/python + +WORKDIR /home/app/ + +USER root + +COPY function function + +# Allow any user-id for OpenShift users. +RUN chown -R app:app ./ && \ + chmod -R 777 /home/app/python + +USER app + +ENV fprocess="python3 index.py" +EXPOSE 8080 + +HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1 + +CMD ["fwatchdog"] diff --git a/template/python3-debian/function/__init__.py b/template/python3-debian/function/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/template/python3-debian/function/handler.py b/template/python3-debian/function/handler.py new file mode 100644 index 0000000..a7098fa --- /dev/null +++ b/template/python3-debian/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/template/python3-debian/function/requirements.txt b/template/python3-debian/function/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/template/python3-debian/index.py b/template/python3-debian/index.py new file mode 100644 index 0000000..f49caae --- /dev/null +++ b/template/python3-debian/index.py @@ -0,0 +1,20 @@ +# Copyright (c) Alex Ellis 2017. 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/template/python3-debian/requirements.txt b/template/python3-debian/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/template/python3-debian/template.yml b/template/python3-debian/template.yml new file mode 100644 index 0000000..461193f --- /dev/null +++ b/template/python3-debian/template.yml @@ -0,0 +1,2 @@ +language: python3-debian +fprocess: python3 index.py diff --git a/template/python3/Dockerfile b/template/python3/Dockerfile new file mode 100644 index 0000000..3c45558 --- /dev/null +++ b/template/python3/Dockerfile @@ -0,0 +1,57 @@ +ARG PYTHON_VERSION=3 +FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/classic-watchdog:0.3.1 AS watchdog +FROM --platform=${TARGETPLATFORM:-linux/amd64} python:${PYTHON_VERSION}-alpine + +ARG TARGETPLATFORM +ARG BUILDPLATFORM + +# Allows you to add additional packages via build-arg +ARG ADDITIONAL_PACKAGE + +COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog +RUN chmod +x /usr/bin/fwatchdog +RUN apk --no-cache add ca-certificates ${ADDITIONAL_PACKAGE} + + +# Add non root user +RUN addgroup -S app && adduser app -S -G app + +WORKDIR /home/app/ + +COPY index.py . +COPY requirements.txt . + +RUN chown -R app /home/app && \ + mkdir -p /home/app/python && chown -R app /home/app +USER app +ENV PATH=$PATH:/home/app/.local/bin:/home/app/python/bin/ +ENV PYTHONPATH=$PYTHONPATH:/home/app/python + +RUN pip install -r requirements.txt --target=/home/app/python + +RUN mkdir -p function +RUN touch ./function/__init__.py + +WORKDIR /home/app/function/ +COPY function/requirements.txt . + +RUN pip install -r requirements.txt --target=/home/app/python + +WORKDIR /home/app/ + +USER root + +COPY function function + +# Allow any user-id for OpenShift users. +RUN chown -R app:app ./ && \ + chmod -R 777 /home/app/python + +USER app + +ENV fprocess="python3 index.py" +EXPOSE 8080 + +HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1 + +CMD ["fwatchdog"] diff --git a/template/python3/function/__init__.py b/template/python3/function/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/template/python3/function/handler.py b/template/python3/function/handler.py new file mode 100644 index 0000000..a7098fa --- /dev/null +++ b/template/python3/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/template/python3/function/requirements.txt b/template/python3/function/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/template/python3/index.py b/template/python3/index.py new file mode 100644 index 0000000..6e1a22f --- /dev/null +++ b/template/python3/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/template/python3/requirements.txt b/template/python3/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/template/python3/template.yml b/template/python3/template.yml new file mode 100644 index 0000000..5933be9 --- /dev/null +++ b/template/python3/template.yml @@ -0,0 +1,37 @@ +language: python3 +fprocess: python3 index.py +build_options: + - name: dev + packages: + - make + - automake + - gcc + - g++ + - subversion + - python3-dev + - musl-dev + - libffi-dev + - git + - name: mysql + packages: + - mysql-client + - mysql-dev + - name: pillow + packages: + - jpeg-dev + - zlib-dev + - freetype-dev + - lcms2-dev + - openjpeg-dev + - tiff-dev + - tk-dev + - tcl-dev + - harfbuzz-dev + - fribidi-dev +welcome_message: | + You have created a Python3 function using the Classic Watchdog. + + To include third-party dependencies create a requirements.txt file. + + For high-throughput applications, we recommend using the python3-flask + or python3-http templates. diff --git a/template/ruby/Dockerfile b/template/ruby/Dockerfile new file mode 100644 index 0000000..1e52db1 --- /dev/null +++ b/template/ruby/Dockerfile @@ -0,0 +1,42 @@ +FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/classic-watchdog:0.3.1 AS watchdog +FROM --platform=${TARGETPLATFORM:-linux/amd64} ruby:3.3.6-alpine + +ARG TARGETPLATFORM +ARG BUILDPLATFORM + +COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog +RUN chmod +x /usr/bin/fwatchdog + +ARG ADDITIONAL_PACKAGE + +# Alternatively use ADD https:// (which will not be cached by Docker builder) +RUN apk --no-cache add ${ADDITIONAL_PACKAGE} + +WORKDIR /home/app + +COPY Gemfile . +COPY index.rb . +COPY function function + +RUN bundle install \ + && mkdir -p /home/app/function + +WORKDIR /home/app/function + +RUN bundle install + +RUN addgroup -S app \ + && adduser app -S -G app + +RUN chown app:app -R /home/app + +USER app + +WORKDIR /home/app + +ENV fprocess="ruby index.rb" +EXPOSE 8080 + +HEALTHCHECK --interval=2s CMD [ -e /tmp/.lock ] || exit 1 + +CMD ["fwatchdog"] diff --git a/template/ruby/Gemfile b/template/ruby/Gemfile new file mode 100644 index 0000000..20b4d4a --- /dev/null +++ b/template/ruby/Gemfile @@ -0,0 +1 @@ +source 'https://rubygems.org' diff --git a/template/ruby/function/Gemfile b/template/ruby/function/Gemfile new file mode 100644 index 0000000..c9721cb --- /dev/null +++ b/template/ruby/function/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' + diff --git a/template/ruby/function/handler.rb b/template/ruby/function/handler.rb new file mode 100644 index 0000000..1c5f146 --- /dev/null +++ b/template/ruby/function/handler.rb @@ -0,0 +1,5 @@ +class Handler + def run(req) + return "Hello world from the Ruby template" + end +end diff --git a/template/ruby/index.rb b/template/ruby/index.rb new file mode 100644 index 0000000..9016c46 --- /dev/null +++ b/template/ruby/index.rb @@ -0,0 +1,12 @@ +# 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. + +require_relative 'function/handler' + +req = ARGF.read + +handler = Handler.new +res = handler.run req + +puts res diff --git a/template/ruby/template.yml b/template/ruby/template.yml new file mode 100644 index 0000000..ab1e5ac --- /dev/null +++ b/template/ruby/template.yml @@ -0,0 +1,24 @@ +language: ruby +fprocess: ruby index.rb +build_options: + - name: dev + packages: + - make + - automake + - gcc + - g++ + - subversion + - python3-dev + - musl-dev + - libffi-dev + - libssh + - libssh-dev +welcome_message: | + + Warning: + This template is deprecated, use the ruby-http template instead. + + You have created a Ruby function using the Classic Watchdog. + + To include third-party dependencies create a Gemfile. You can also + include developer-dependencies using the "dev" build_option.