Update dockerfile to using bookworm, and to avoid invalidating cache unless updating requirements.

This commit is contained in:
Víðir Valberg Guðmundsson 2024-07-31 23:48:39 +02:00
parent 7a3a629d6f
commit 0cf579c5f6

View file

@ -1,4 +1,4 @@
FROM python:3.12-slim-bullseye FROM python:3.12-slim-bookworm
# PYTHONFAULTHANDLER: Propagate tracebacks from all threads. # PYTHONFAULTHANDLER: Propagate tracebacks from all threads.
# PYTHONUNBUFFERED: Write terminal output straight to docker (to not confuse Docker Compose). # 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_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 PIP_DEFAULT_TIMEOUT=100
ARG BUILD ARG BUILD
ENV BUILD ${BUILD} ENV BUILD=${BUILD}
ARG REQUIREMENTS_FILE=requirements.txt ARG REQUIREMENTS_FILE=requirements.txt
WORKDIR /app WORKDIR /app
RUN groupadd -g 1000 www && useradd -u 1000 -ms /bin/bash -g www www 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 && \ chown www:www /app/src/static && \
apt-get update && \ apt-get update && \
apt-get install -y \ apt-get install -y \
@ -35,8 +38,12 @@ RUN mkdir /app/src/static && \
libffi-dev \ libffi-dev \
shared-mime-info \ shared-mime-info \
gettext && \ gettext && \
pip install --no-cache-dir -r $REQUIREMENTS_FILE && \ pip install --no-cache-dir -r $REQUIREMENTS_FILE
django-admin compilemessages
# Copy the rest of the application
COPY . .
RUN django-admin compilemessages
ENTRYPOINT ["./entrypoint.sh"] ENTRYPOINT ["./entrypoint.sh"]