Skip to content

Commit

Permalink
Graduate python3-debian from incubator
Browse files Browse the repository at this point in the history
**What**
- Copy the python3-debian template from https://github.com/openfaas-incubator/python3-debian
- Update the dockerfile to be non-root, this adapts the same
  modifications/commands that the alpine dockerfile uses, but ofcourse
  adapted to debian

Resolves openfaas-incubator/python3-debian#10
Resolves openfaas-incubator/python3-debian#7

Signed-off-by: Lucas Roesler <[email protected]>
  • Loading branch information
LucasRoesler authored and alexellis committed Feb 6, 2020
1 parent b9e6b82 commit b0b4dcd
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 0 deletions.
53 changes: 53 additions & 0 deletions template/python3-debian/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM openfaas/classic-watchdog:0.18.1 as watchdog
FROM python:3

# 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

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"]
Empty file.
7 changes: 7 additions & 0 deletions template/python3-debian/function/handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def handle(req):
"""handle a request to the function
Args:
req (str): request body
"""

return req
Empty file.
20 changes: 20 additions & 0 deletions template/python3-debian/index.py
Original file line number Diff line number Diff line change
@@ -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)
Empty file.
2 changes: 2 additions & 0 deletions template/python3-debian/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: python3-debian
fprocess: python3 index.py

0 comments on commit b0b4dcd

Please sign in to comment.