From 5a5f41246d4f41f3ded634ff3fc92df554f4df1c Mon Sep 17 00:00:00 2001 From: Tobias Quadfasel Date: Thu, 29 Aug 2024 17:35:14 +0200 Subject: [PATCH] feat(base-app): Add docker setup Adding a dockerfile as well as an `entrypoint.sh` file for deployment using `gunicorn`. --- .docker/entrypoint.sh | 5 +++++ Dockerfile | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 .docker/entrypoint.sh create mode 100644 Dockerfile diff --git a/.docker/entrypoint.sh b/.docker/entrypoint.sh new file mode 100644 index 0000000..210c1fe --- /dev/null +++ b/.docker/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +# Start Dash and run in background +echo "Starting Dash app..." +poetry run gunicorn app:server -b 0.0.0.0:8000 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1b4dcf2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +ARG PYTHON_VERSION_TAG=3.12 +ARG PYTHON_VARIANT_TAG=slim + +# Use official Python image as base +# ${PYTHON_VARIANT_TAG:+-${PYTHON_VARIANT_TAG}} is a conditional expansion +# that adds a dash before the variant tag if it is not empty +FROM python:${PYTHON_VERSION_TAG}${PYTHON_VARIANT_TAG:+-${PYTHON_VARIANT_TAG}} + +# Set up poetry environment +ARG POETRY_VERSION=1.8.3 + +ENV POETRY_HOME=/opt/poetry +ENV POETRY_VENV=/opt/poetry-venv +ENV POETRY_CACHE_DIR=/opt/.cache + +# Install poetry separated from system interpreter +RUN python3 -m venv $POETRY_VENV \ + && $POETRY_VENV/bin/pip install -U pip setuptools \ + && $POETRY_VENV/bin/pip install poetry==${POETRY_VERSION} + +# Add `poetry` to PATH +ENV PATH="${POETRY_VENV}/bin:${PATH}" + +RUN poetry config virtualenvs.in-project true + +# Export in first position so that "python" calls are from .venv +ENV PATH="/app/.venv/bin:${PATH}" +ENV PYTHONPATH="/app/:${PYTHONPATH}" + +COPY pyproject.toml . +COPY poetry.lock . +COPY app/ app/ + +RUN poetry install --no-interaction --no-dev + +COPY ./.docker/entrypoint.sh /app/entrypoint.sh +RUN chmod +x /app/entrypoint.sh + +WORKDIR /app + + +EXPOSE 80 +EXPOSE 8000 + +ENTRYPOINT ["./entrypoint.sh"]