1 FROM python:3.10-slim-trixie AS base
7 && apt-get install -y --no-install-recommends \
8 imagemagick tesseract-ocr tesseract-ocr-pol curl \
9 && rm -rf /var/lib/apt/lists/*
11 # Install dart-sass for compiling SCSS.
12 ARG DART_SASS_VERSION=1.108.2
13 RUN arch=$(dpkg --print-architecture | sed 's/amd64/x64/') && \
14 curl -fsSL "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-${arch}.tar.gz" \
17 COPY requirements/requirements.txt requirements.txt
19 RUN --mount=type=cache,target=/root/.cache/pip \
20 pip install -r requirements.txt
22 RUN addgroup --gid $GID app && \
23 adduser --gid $GID --home /app --uid $UID app
35 RUN --mount=type=cache,target=/root/.cache/pip \
36 pip install --no-cache-dir coverage
42 FROM base AS prod-base
46 RUN --mount=type=cache,target=/root/.cache/pip \
47 pip install --no-cache-dir gunicorn
55 FROM prod-base AS static-builder
57 # django-pipeline compiler creates temp dirs in place. Let it.
59 RUN find /app/src/*/static -type d -exec chown app {} +
62 RUN python manage.py collectstatic --noinput
65 FROM nginx:alpine AS nginx
70 COPY scripts/nginx.conf /etc/nginx/conf.d/default.conf
72 RUN addgroup -g $GID app && addgroup nginx app
73 COPY --from=static-builder /app/var/static /app/var/static
77 FROM prod-base AS test
79 COPY requirements/requirements-test.txt /tmp/
80 RUN --mount=type=cache,target=/root/.cache/pip \
81 pip install -r /tmp/requirements-test.txt
83 COPY --from=static-builder /app/var/static/staticfiles.json /app/var/static/staticfiles.json
84 CMD ["./manage.py", "test"]
87 FROM prod-base AS prod
89 COPY --from=static-builder /app/var/static/staticfiles.json /app/var/static/staticfiles.json