Handle some deprecations
[redakcja.git] / Dockerfile
1 FROM python:3.10-slim-trixie AS base
2
3 ARG UID=8200
4 ARG GID=8200
5
6 RUN apt-get update \
7  && apt-get install -y --no-install-recommends \
8     imagemagick tesseract-ocr tesseract-ocr-pol curl \
9  && rm -rf /var/lib/apt/lists/*
10
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" \
15     | tar xz -C /opt
16
17 COPY requirements/requirements.txt requirements.txt
18
19 RUN --mount=type=cache,target=/root/.cache/pip \
20     pip install -r requirements.txt
21
22 RUN addgroup --gid $GID app && \
23     adduser --gid $GID --home /app --uid $UID app
24
25 USER app
26
27 WORKDIR /app/src
28
29
30
31
32 FROM base AS dev
33
34 USER root
35 RUN --mount=type=cache,target=/root/.cache/pip \
36     pip install --no-cache-dir coverage
37 USER app
38
39
40
41
42 FROM base AS prod-base
43
44 USER root
45
46 RUN --mount=type=cache,target=/root/.cache/pip \
47     pip install --no-cache-dir gunicorn
48
49 USER app
50
51 COPY src /app/src
52
53
54
55 FROM prod-base AS static-builder
56
57 # django-pipeline compiler creates temp dirs in place. Let it.
58 USER root
59 RUN find /app/src/*/static -type d -exec chown app {} +
60 USER app
61
62 RUN python manage.py collectstatic --noinput
63
64
65 FROM nginx:alpine AS nginx
66
67 ARG UID=8200
68 ARG GID=8200
69
70 COPY scripts/nginx.conf /etc/nginx/conf.d/default.conf
71
72 RUN addgroup -g $GID app && addgroup nginx app
73 COPY --from=static-builder /app/var/static /app/var/static
74
75
76
77 FROM prod-base AS test
78 USER root
79 COPY requirements/requirements-test.txt /tmp/
80 RUN --mount=type=cache,target=/root/.cache/pip \
81     pip install -r /tmp/requirements-test.txt
82 USER app
83 COPY --from=static-builder /app/var/static/staticfiles.json /app/var/static/staticfiles.json
84 CMD ["./manage.py", "test"]
85
86
87 FROM prod-base AS prod
88
89 COPY --from=static-builder /app/var/static/staticfiles.json /app/var/static/staticfiles.json