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"]