From 0cf579c5f6e70b837c487e254532987d7186a56f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Wed, 31 Jul 2024 23:48:39 +0200 Subject: [PATCH] Update dockerfile to using bookworm, and to avoid invalidating cache unless updating requirements. --- Dockerfile | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index fc8aa79..9b7c01b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.12-slim-bullseye +FROM python:3.12-slim-bookworm # PYTHONFAULTHANDLER: Propagate tracebacks from all threads. # PYTHONUNBUFFERED: Write terminal output straight to docker (to not confuse Docker Compose). @@ -13,14 +13,17 @@ ENV PYTHONFAULTHANDLER=1 \ PIP_DISABLE_PIP_VERSION_CHECK=on \ PIP_DEFAULT_TIMEOUT=100 ARG BUILD -ENV BUILD ${BUILD} +ENV BUILD=${BUILD} ARG REQUIREMENTS_FILE=requirements.txt WORKDIR /app RUN groupadd -g 1000 www && useradd -u 1000 -ms /bin/bash -g www www -COPY --chown=www:www . . -RUN mkdir /app/src/static && \ + +# Only copy the requirements file first to leverage Docker cache +COPY $REQUIREMENTS_FILE . + +RUN mkdir -p /app/src/static && \ chown www:www /app/src/static && \ apt-get update && \ apt-get install -y \ @@ -35,8 +38,12 @@ RUN mkdir /app/src/static && \ libffi-dev \ shared-mime-info \ gettext && \ - pip install --no-cache-dir -r $REQUIREMENTS_FILE && \ - django-admin compilemessages + pip install --no-cache-dir -r $REQUIREMENTS_FILE + +# Copy the rest of the application +COPY . . + +RUN django-admin compilemessages ENTRYPOINT ["./entrypoint.sh"]