2024-03-07 19:46:46 +01:00
|
|
|
# Django impress
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
# ---- base image to inherit from ----
|
2025-05-16 10:21:33 +02:00
|
|
|
FROM python:3.13.3-alpine AS base
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
# Upgrade pip to its latest release to speed up dependencies installation
|
2026-01-16 12:43:02 +01:00
|
|
|
RUN python -m pip install --upgrade pip
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
# Upgrade system packages to install security updates
|
2025-03-17 21:55:14 +08:00
|
|
|
RUN apk update && apk upgrade --no-cache
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
# ---- Back-end builder image ----
|
2024-10-14 21:10:52 +02:00
|
|
|
FROM base AS back-builder
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
WORKDIR /builder
|
|
|
|
|
|
2024-12-27 10:19:16 +01:00
|
|
|
# Install Rust and Cargo using Alpine's package manager
|
|
|
|
|
RUN apk add --no-cache \
|
|
|
|
|
build-base \
|
|
|
|
|
libffi-dev \
|
|
|
|
|
rust \
|
|
|
|
|
cargo
|
|
|
|
|
|
2024-01-09 15:30:36 +01:00
|
|
|
# Copy required python dependencies
|
|
|
|
|
COPY ./src/backend /builder
|
|
|
|
|
|
|
|
|
|
RUN mkdir /install && \
|
|
|
|
|
pip install --prefix=/install .
|
|
|
|
|
|
2024-04-04 14:06:03 +02:00
|
|
|
|
2024-01-09 15:30:36 +01:00
|
|
|
# ---- mails ----
|
2025-05-16 10:21:33 +02:00
|
|
|
FROM node:24 AS mail-builder
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
COPY ./src/mail /mail/app
|
|
|
|
|
|
|
|
|
|
WORKDIR /mail/app
|
|
|
|
|
|
|
|
|
|
RUN yarn install --frozen-lockfile && \
|
2026-02-11 15:17:32 +01:00
|
|
|
yarn build
|
2024-01-09 15:30:36 +01:00
|
|
|
|
2024-04-04 14:06:03 +02:00
|
|
|
|
2024-01-09 15:30:36 +01:00
|
|
|
# ---- static link collector ----
|
2024-10-14 21:10:52 +02:00
|
|
|
FROM base AS link-collector
|
2024-04-11 11:00:50 +02:00
|
|
|
ARG IMPRESS_STATIC_ROOT=/data/static
|
2024-01-09 15:30:36 +01:00
|
|
|
|
2024-09-30 10:37:09 +02:00
|
|
|
# Install pango & rdfind
|
2025-03-17 21:55:14 +08:00
|
|
|
RUN apk add --no-cache \
|
2024-09-30 10:37:09 +02:00
|
|
|
pango \
|
|
|
|
|
rdfind
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
# Copy installed python dependencies
|
|
|
|
|
COPY --from=back-builder /install /usr/local
|
|
|
|
|
|
2024-03-07 19:46:46 +01:00
|
|
|
# Copy impress application (see .dockerignore)
|
2024-01-09 15:30:36 +01:00
|
|
|
COPY ./src/backend /app/
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# collectstatic
|
2025-01-16 15:47:44 +01:00
|
|
|
RUN DJANGO_CONFIGURATION=Build \
|
2026-02-11 15:17:32 +01:00
|
|
|
python manage.py collectstatic --noinput
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
# Replace duplicated file by a symlink to decrease the overall size of the
|
|
|
|
|
# final image
|
2024-03-07 19:46:46 +01:00
|
|
|
RUN rdfind -makesymlinks true -followsymlinks true -makeresultsfile false ${IMPRESS_STATIC_ROOT}
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
# ---- Core application image ----
|
2024-10-14 21:10:52 +02:00
|
|
|
FROM base AS core
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
|
|
2024-04-04 14:06:03 +02:00
|
|
|
# Install required system libs
|
2025-03-17 21:55:14 +08:00
|
|
|
RUN apk add --no-cache \
|
2024-09-30 10:37:09 +02:00
|
|
|
cairo \
|
2024-10-07 20:10:42 +02:00
|
|
|
file \
|
|
|
|
|
font-noto \
|
|
|
|
|
font-noto-emoji \
|
|
|
|
|
gettext \
|
2024-09-30 10:37:09 +02:00
|
|
|
gdk-pixbuf \
|
2024-10-07 20:10:42 +02:00
|
|
|
libffi-dev \
|
|
|
|
|
pango \
|
2024-09-30 10:37:09 +02:00
|
|
|
shared-mime-info
|
2024-04-04 14:06:03 +02:00
|
|
|
|
2026-02-11 15:17:32 +01:00
|
|
|
RUN wget https://raw.githubusercontent.com/suitenumerique/django-lasuite/refs/heads/main/assets/conf/mime.types -O /etc/mime.types
|
2025-01-15 15:58:46 +01:00
|
|
|
|
2024-01-09 15:30:36 +01:00
|
|
|
# Copy entrypoint
|
|
|
|
|
COPY ./docker/files/usr/local/bin/entrypoint /usr/local/bin/entrypoint
|
|
|
|
|
|
|
|
|
|
# Give the "root" group the same permissions as the "root" user on /etc/passwd
|
|
|
|
|
# to allow a user belonging to the root group to add new users; typically the
|
|
|
|
|
# docker user (see entrypoint).
|
|
|
|
|
RUN chmod g=u /etc/passwd
|
|
|
|
|
|
|
|
|
|
# Copy installed python dependencies
|
|
|
|
|
COPY --from=back-builder /install /usr/local
|
|
|
|
|
|
2025-10-08 14:50:31 +02:00
|
|
|
# Link certifi certificate from a static path /cert/cacert.pem to avoid issues
|
|
|
|
|
# when python is upgraded and the path to the certificate changes.
|
|
|
|
|
# The space between print and the ( is intended otherwise the git lint is failing
|
|
|
|
|
RUN mkdir /cert && \
|
2026-02-11 15:17:32 +01:00
|
|
|
path=`python -c 'import certifi;print (certifi.where())'` && \
|
|
|
|
|
mv $path /cert/ && \
|
|
|
|
|
ln -s /cert/cacert.pem $path
|
2025-10-08 14:50:31 +02:00
|
|
|
|
2024-03-07 19:46:46 +01:00
|
|
|
# Copy impress application (see .dockerignore)
|
2024-01-09 15:30:36 +01:00
|
|
|
COPY ./src/backend /app/
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
2025-01-16 15:47:44 +01:00
|
|
|
# Generate compiled translation messages
|
|
|
|
|
RUN DJANGO_CONFIGURATION=Build \
|
2026-02-11 15:17:32 +01:00
|
|
|
python manage.py compilemessages
|
2025-01-16 15:47:44 +01:00
|
|
|
|
|
|
|
|
|
2024-01-09 15:30:36 +01:00
|
|
|
# We wrap commands run in this container by the following entrypoint that
|
|
|
|
|
# creates a user on-the-fly with the container user ID (see USER) and root group
|
|
|
|
|
# ID.
|
|
|
|
|
ENTRYPOINT [ "/usr/local/bin/entrypoint" ]
|
|
|
|
|
|
|
|
|
|
# ---- Development image ----
|
2024-10-14 21:10:52 +02:00
|
|
|
FROM core AS backend-development
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
# Switch back to the root user to install development dependencies
|
|
|
|
|
USER root:root
|
|
|
|
|
|
|
|
|
|
# Install psql
|
2025-03-17 21:55:14 +08:00
|
|
|
RUN apk add --no-cache postgresql-client
|
2024-01-09 15:30:36 +01:00
|
|
|
|
2024-03-07 19:46:46 +01:00
|
|
|
# Uninstall impress and re-install it in editable mode along with development
|
2024-01-09 15:30:36 +01:00
|
|
|
# dependencies
|
2024-03-07 19:46:46 +01:00
|
|
|
RUN pip uninstall -y impress
|
2024-01-09 15:30:36 +01:00
|
|
|
RUN pip install -e .[dev]
|
|
|
|
|
|
|
|
|
|
# Restore the un-privileged user running the application
|
|
|
|
|
ARG DOCKER_USER
|
|
|
|
|
USER ${DOCKER_USER}
|
|
|
|
|
|
|
|
|
|
# Target database host (e.g. database engine following docker compose services
|
|
|
|
|
# name) & port
|
|
|
|
|
ENV DB_HOST=postgresql \
|
2026-02-11 15:17:32 +01:00
|
|
|
DB_PORT=5432
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
# Run django development server
|
2024-04-04 14:06:03 +02:00
|
|
|
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
# ---- Production image ----
|
2024-10-14 21:10:52 +02:00
|
|
|
FROM core AS backend-production
|
2024-01-09 15:30:36 +01:00
|
|
|
|
2025-05-16 10:21:33 +02:00
|
|
|
# Remove apk cache, we don't need it anymore
|
|
|
|
|
RUN rm -rf /var/cache/apk/*
|
|
|
|
|
|
2024-03-07 19:46:46 +01:00
|
|
|
ARG IMPRESS_STATIC_ROOT=/data/static
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
# Gunicorn
|
|
|
|
|
RUN mkdir -p /usr/local/etc/gunicorn
|
2024-03-07 19:46:46 +01:00
|
|
|
COPY docker/files/usr/local/etc/gunicorn/impress.py /usr/local/etc/gunicorn/impress.py
|
2024-01-09 15:30:36 +01:00
|
|
|
|
|
|
|
|
# Un-privileged user running the application
|
|
|
|
|
ARG DOCKER_USER
|
|
|
|
|
USER ${DOCKER_USER}
|
|
|
|
|
|
|
|
|
|
# Copy statics
|
2024-03-07 19:46:46 +01:00
|
|
|
COPY --from=link-collector ${IMPRESS_STATIC_ROOT} ${IMPRESS_STATIC_ROOT}
|
2024-01-09 15:30:36 +01:00
|
|
|
|
2024-03-07 19:46:46 +01:00
|
|
|
# Copy impress mails
|
2024-01-09 15:30:36 +01:00
|
|
|
COPY --from=mail-builder /mail/backend/core/templates/mail /app/core/templates/mail
|
|
|
|
|
|
2024-03-07 19:46:46 +01:00
|
|
|
# The default command runs gunicorn WSGI server in impress's main module
|
2024-04-03 12:34:22 +02:00
|
|
|
CMD ["gunicorn", "-c", "/usr/local/etc/gunicorn/impress.py", "impress.wsgi:application"]
|