Skip to content

Commit 9c59aba

Browse files
committed
Move over Python and ruby templates
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent c9ded39 commit 9c59aba

27 files changed

+421
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ faas-cli new --lang go \
2121
NAME
2222
```
2323

24+
## Contents
25+
26+
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/).
27+
28+
| Name | Language | Version | Linux base | Watchdog | Link
29+
|:-----|:---------|:--------|:-----------|:---------|:----
30+
| go | Go | 1.23 | Alpine Linux | classic | [Legacy Go template (deprecated)](https://github.com/openfaas/templates/tree/master/template/go)
31+
| bun-express | Bun | 1.0 | Alpine Linux | of-watchdog | [NodeJS template](https://github.com/openfaas/templates/tree/master/template/bun-express)
32+
| node | NodeJS | 20 | Alpine Linux | classic | [Legacy NodeJS template (deprecated)](https://github.com/openfaas/templates/tree/master/template/node)
33+
| python3 | Python | 3 | Alpine Linux | classic | [Legacy Python 3 template](https://github.com/openfaas/templates/tree/master/template/python3)
34+
| python3-debian | Python | 3 | Debian Linux | classic | [Legacy Python 3 Debian template](https://github.com/openfaas/templates/tree/master/template/python3-debian)
35+
| python27 | Python | 2.7.18 | Alpine Linux | classic | [Python 2.7 template (deprecated)](https://github.com/openfaas/templates/tree/master/template/python27)
36+
| ruby | Ruby | 3.3 | Alpine Linux | classic| [Ruby template](https://github.com/openfaas/templates/tree/master/template/ruby)
37+
| csharp | C# | N/A | Debian GNU/Linux 9 | classic | [Legacy C# template (deprecated)](https://github.com/openfaas/templates/tree/master/template/csharp)
38+
39+
2440
### License
2541

2642
This project is part of the OpenFaaS project licensed under the MIT License.

template/python27/Dockerfile

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/classic-watchdog:0.3.1 AS watchdog
2+
FROM --platform=${TARGETPLATFORM:-linux/amd64} python:2.7.18-alpine
3+
4+
ARG TARGETPLATFORM
5+
ARG BUILDPLATFORM
6+
7+
# Allows you to add additional packages via build-arg
8+
ARG ADDITIONAL_PACKAGE
9+
10+
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
11+
RUN chmod +x /usr/bin/fwatchdog
12+
RUN apk --no-cache add ca-certificates ${ADDITIONAL_PACKAGE}
13+
14+
# Add non root user
15+
RUN addgroup -S app && adduser app -S -G app
16+
17+
WORKDIR /home/app/
18+
19+
COPY index.py .
20+
COPY requirements.txt .
21+
22+
RUN chown -R app /home/app && \
23+
mkdir -p /home/app/python && chown -R app /home/app
24+
USER app
25+
ENV PATH=$PATH:/home/app/.local/bin:/home/app/python/bin/
26+
ENV PYTHONPATH=$PYTHONPATH:/home/app/python
27+
28+
RUN pip install -r requirements.txt --target=/home/app/python
29+
30+
RUN mkdir -p function
31+
RUN touch ./function/__init__.py
32+
33+
WORKDIR /home/app/function/
34+
COPY function/requirements.txt .
35+
36+
RUN pip install -r requirements.txt --target=/home/app/python
37+
38+
WORKDIR /home/app/
39+
40+
USER root
41+
42+
COPY function function
43+
44+
# Allow any user-id for OpenShift users.
45+
RUN chown -R app:app ./ && \
46+
chmod -R 777 /home/app/python
47+
48+
USER app
49+
50+
ENV fprocess="python index.py"
51+
EXPOSE 8080
52+
53+
HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1
54+
55+
CMD ["fwatchdog"]

template/python27/function/handler.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def handle(req):
2+
"""handle a request to the function
3+
Args:
4+
req (str): request body
5+
"""
6+
7+
return req

template/python27/function/requirements.txt

Whitespace-only changes.

template/python27/index.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) Alex Ellis 2017. All rights reserved.
2+
# Copyright (c) OpenFaaS Author(s) 2018. All rights reserved.
3+
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
5+
import sys
6+
from function import handler
7+
8+
def get_stdin():
9+
buf = ""
10+
for line in sys.stdin:
11+
buf = buf + line
12+
return buf
13+
14+
if __name__ == "__main__":
15+
st = get_stdin()
16+
ret = handler.handle(st)
17+
if ret != None:
18+
print(ret)

template/python27/requirements.txt

Whitespace-only changes.

template/python27/template.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
language: python27
2+
fprocess: python index.py
3+
build_options:
4+
- name: dev
5+
packages:
6+
- make
7+
- automake
8+
- gcc
9+
- g++
10+
- subversion
11+
- python3-dev
12+
- musl-dev
13+
- libffi-dev
14+
- git
15+
- name: mysql
16+
packages:
17+
- mysql-client
18+
- mysql-dev
19+
- name: pillow
20+
packages:
21+
- jpeg-dev
22+
- zlib-dev
23+
- freetype-dev
24+
- lcms2-dev
25+
- openjpeg-dev
26+
- tiff-dev
27+
- tk-dev
28+
- tcl-dev
29+
- harfbuzz-dev
30+
- fribidi-dev

template/python3-debian/Dockerfile

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
ARG PYTHON_VERSION=3
2+
FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/classic-watchdog:0.3.1 AS watchdog
3+
FROM --platform=${TARGETPLATFORM:-linux/amd64} python:${PYTHON_VERSION}
4+
5+
ARG TARGETPLATFORM
6+
ARG BUILDPLATFORM
7+
8+
# Allows you to add additional packages via build-arg
9+
ARG ADDITIONAL_PACKAGE
10+
11+
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
12+
RUN chmod +x /usr/bin/fwatchdog
13+
RUN apt-get update \
14+
&& apt-get install -y ca-certificates ${ADDITIONAL_PACKAGE} \
15+
&& rm -rf /var/lib/apt/lists/
16+
17+
# Add non root user
18+
RUN groupadd app && useradd -r -g app app
19+
20+
WORKDIR /home/app/
21+
22+
COPY index.py .
23+
COPY requirements.txt .
24+
25+
RUN chown -R app /home/app && \
26+
mkdir -p /home/app/python && chown -R app /home/app
27+
USER app
28+
ENV PATH=$PATH:/home/app/.local/bin:/home/app/python/bin/
29+
ENV PYTHONPATH=$PYTHONPATH:/home/app/python
30+
31+
RUN pip install -r requirements.txt --target=/home/app/python
32+
33+
RUN mkdir -p function
34+
RUN touch ./function/__init__.py
35+
36+
WORKDIR /home/app/function/
37+
COPY function/requirements.txt .
38+
39+
RUN pip install -r requirements.txt --target=/home/app/python
40+
41+
WORKDIR /home/app/
42+
43+
USER root
44+
45+
COPY function function
46+
47+
# Allow any user-id for OpenShift users.
48+
RUN chown -R app:app ./ && \
49+
chmod -R 777 /home/app/python
50+
51+
USER app
52+
53+
ENV fprocess="python3 index.py"
54+
EXPOSE 8080
55+
56+
HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1
57+
58+
CMD ["fwatchdog"]

template/python3-debian/function/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def handle(req):
2+
"""handle a request to the function
3+
Args:
4+
req (str): request body
5+
"""
6+
7+
return req

template/python3-debian/function/requirements.txt

Whitespace-only changes.

template/python3-debian/index.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
import sys
5+
from function import handler
6+
7+
def get_stdin():
8+
buf = ""
9+
while(True):
10+
line = sys.stdin.readline()
11+
buf += line
12+
if line=="":
13+
break
14+
return buf
15+
16+
if(__name__ == "__main__"):
17+
st = get_stdin()
18+
ret = handler.handle(st)
19+
if ret != None:
20+
print(ret)

template/python3-debian/requirements.txt

Whitespace-only changes.

template/python3-debian/template.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
language: python3-debian
2+
fprocess: python3 index.py

template/python3/Dockerfile

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
ARG PYTHON_VERSION=3
2+
FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/classic-watchdog:0.3.1 AS watchdog
3+
FROM --platform=${TARGETPLATFORM:-linux/amd64} python:${PYTHON_VERSION}-alpine
4+
5+
ARG TARGETPLATFORM
6+
ARG BUILDPLATFORM
7+
8+
# Allows you to add additional packages via build-arg
9+
ARG ADDITIONAL_PACKAGE
10+
11+
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
12+
RUN chmod +x /usr/bin/fwatchdog
13+
RUN apk --no-cache add ca-certificates ${ADDITIONAL_PACKAGE}
14+
15+
16+
# Add non root user
17+
RUN addgroup -S app && adduser app -S -G app
18+
19+
WORKDIR /home/app/
20+
21+
COPY index.py .
22+
COPY requirements.txt .
23+
24+
RUN chown -R app /home/app && \
25+
mkdir -p /home/app/python && chown -R app /home/app
26+
USER app
27+
ENV PATH=$PATH:/home/app/.local/bin:/home/app/python/bin/
28+
ENV PYTHONPATH=$PYTHONPATH:/home/app/python
29+
30+
RUN pip install -r requirements.txt --target=/home/app/python
31+
32+
RUN mkdir -p function
33+
RUN touch ./function/__init__.py
34+
35+
WORKDIR /home/app/function/
36+
COPY function/requirements.txt .
37+
38+
RUN pip install -r requirements.txt --target=/home/app/python
39+
40+
WORKDIR /home/app/
41+
42+
USER root
43+
44+
COPY function function
45+
46+
# Allow any user-id for OpenShift users.
47+
RUN chown -R app:app ./ && \
48+
chmod -R 777 /home/app/python
49+
50+
USER app
51+
52+
ENV fprocess="python3 index.py"
53+
EXPOSE 8080
54+
55+
HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1
56+
57+
CMD ["fwatchdog"]

template/python3/function/__init__.py

Whitespace-only changes.

template/python3/function/handler.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def handle(req):
2+
"""handle a request to the function
3+
Args:
4+
req (str): request body
5+
"""
6+
7+
return req

template/python3/function/requirements.txt

Whitespace-only changes.

template/python3/index.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) Alex Ellis 2017. All rights reserved.
2+
# Copyright (c) OpenFaaS Author(s) 2018. All rights reserved.
3+
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
5+
import sys
6+
from function import handler
7+
8+
def get_stdin():
9+
buf = ""
10+
while(True):
11+
line = sys.stdin.readline()
12+
buf += line
13+
if line == "":
14+
break
15+
return buf
16+
17+
if __name__ == "__main__":
18+
st = get_stdin()
19+
ret = handler.handle(st)
20+
if ret != None:
21+
print(ret)

template/python3/requirements.txt

Whitespace-only changes.

template/python3/template.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
language: python3
2+
fprocess: python3 index.py
3+
build_options:
4+
- name: dev
5+
packages:
6+
- make
7+
- automake
8+
- gcc
9+
- g++
10+
- subversion
11+
- python3-dev
12+
- musl-dev
13+
- libffi-dev
14+
- git
15+
- name: mysql
16+
packages:
17+
- mysql-client
18+
- mysql-dev
19+
- name: pillow
20+
packages:
21+
- jpeg-dev
22+
- zlib-dev
23+
- freetype-dev
24+
- lcms2-dev
25+
- openjpeg-dev
26+
- tiff-dev
27+
- tk-dev
28+
- tcl-dev
29+
- harfbuzz-dev
30+
- fribidi-dev
31+
welcome_message: |
32+
You have created a Python3 function using the Classic Watchdog.
33+
34+
To include third-party dependencies create a requirements.txt file.
35+
36+
For high-throughput applications, we recommend using the python3-flask
37+
or python3-http templates.

template/ruby/Dockerfile

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
FROM --platform=${TARGETPLATFORM:-linux/amd64} ghcr.io/openfaas/classic-watchdog:0.3.1 AS watchdog
2+
FROM --platform=${TARGETPLATFORM:-linux/amd64} ruby:3.3.6-alpine
3+
4+
ARG TARGETPLATFORM
5+
ARG BUILDPLATFORM
6+
7+
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
8+
RUN chmod +x /usr/bin/fwatchdog
9+
10+
ARG ADDITIONAL_PACKAGE
11+
12+
# Alternatively use ADD https:// (which will not be cached by Docker builder)
13+
RUN apk --no-cache add ${ADDITIONAL_PACKAGE}
14+
15+
WORKDIR /home/app
16+
17+
COPY Gemfile .
18+
COPY index.rb .
19+
COPY function function
20+
21+
RUN bundle install \
22+
&& mkdir -p /home/app/function
23+
24+
WORKDIR /home/app/function
25+
26+
RUN bundle install
27+
28+
RUN addgroup -S app \
29+
&& adduser app -S -G app
30+
31+
RUN chown app:app -R /home/app
32+
33+
USER app
34+
35+
WORKDIR /home/app
36+
37+
ENV fprocess="ruby index.rb"
38+
EXPOSE 8080
39+
40+
HEALTHCHECK --interval=2s CMD [ -e /tmp/.lock ] || exit 1
41+
42+
CMD ["fwatchdog"]

template/ruby/Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source 'https://rubygems.org'

0 commit comments

Comments
 (0)