From 6ed22c1622a302ab6ee66714cc1e40b334c43e16 Mon Sep 17 00:00:00 2001 From: Jakob Langdal Date: Thu, 21 Jan 2021 09:06:30 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + Dockerfile | 28 ++++++++++++++++++++++++++++ requirements.txt | 1 + src/server.py | 11 +++++++++++ 4 files changed, 41 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 requirements.txt create mode 100644 src/server.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a764a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..62621bb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +# First stage +FROM python:3.9.1 AS builder + +ENV VIRTUAL_ENV=/opt/venv +RUN python3 -m venv ${VIRTUAL_ENV} +ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" + +RUN pip install --upgrade pip && pip install pip-tools + +COPY requirements.txt . +RUN pip install -r requirements.txt + +# Second stage +FROM python:3.9.1-slim +COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} +WORKDIR /code + +# add non-root user +RUN addgroup --system user && adduser --system --no-create-home --group user +RUN chown -R user:user /code && chmod -R 755 /code + +USER user + +COPY src/ /code + +ENV PATH=/opt/venv/bin:${PATH} + +CMD [ "python", "./server.py" ] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7deaf3b --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Flask==1.1.2 \ No newline at end of file diff --git a/src/server.py b/src/server.py new file mode 100644 index 0000000..d162ff4 --- /dev/null +++ b/src/server.py @@ -0,0 +1,11 @@ +from flask import Flask +server = Flask(__name__) + + +@server.route("/") +def hello(): + return "Hello World!" + + +if __name__ == "__main__": + server.run(host='0.0.0.0')