1 # Base system and requirements.
3 FROM python:3.9-trixie AS base
8 RUN apt-get update && apt-get install -y \
11 texlive-xetex texlive-lang-polish \
17 texlive-fonts-extra-links \
18 fonts-noto-core fonts-noto-extra
21 COPY requirements/requirements.txt requirements.txt
23 RUN pip install --no-cache-dir -r requirements.txt
24 RUN pip install --no-cache-dir \
26 django-debug-toolbar==3.2.2
28 RUN addgroup --gid $GID app && \
29 adduser --gid $GID --home /app --uid $UID app
33 RUN cp -a /usr/local/lib/python*/site-packages/librarian/fonts /usr/share/fonts
40 RUN mkdir /app/.ipython
45 # Assumes code will be mounted.
49 #RUN pip install --no-cache-dir coverage
53 # Installs code and production requirements.
55 FROM base AS prod-base
59 RUN pip install --no-cache-dir gunicorn
67 # Static files are collected here. Statics are then copied into an Nginx image,
68 # and staticfiles.json manifest file is copied back into production image.
70 FROM prod-base AS static-builder
72 RUN python manage.py collectstatic --noinput
76 # Contains static files and nginx config.
78 FROM nginx:alpine AS nginx
83 # COPY nginx.conf conf.d/...
85 RUN addgroup -g $GID app && addgroup nginx app
86 COPY --from=static-builder /app/var/static /app/var/static
91 # Postgres with Polish hunspell dictionary withoud diacritics
92 # to allow full text search without diacritics.
94 # --- Stage 1: prepare dictionary files ---
95 FROM python:3.13-slim-trixie AS polish-dict
98 && apt-get install -y --no-install-recommends hunspell-pl \
99 && rm -rf /var/lib/apt/lists/*
101 COPY scripts/fold_hunspell.py /usr/local/bin/fold_hunspell.py
104 mkdir /out; cd /tmp; \
105 enc="$(sed -n 's/^SET[[:space:]]*//p' /usr/share/hunspell/pl_PL.aff | tr -d '\r')"; \
106 iconv -f "${enc:-UTF-8}" -t UTF-8 /usr/share/hunspell/pl_PL.dic > pl.dict; \
107 iconv -f "${enc:-UTF-8}" -t UTF-8 /usr/share/hunspell/pl_PL.aff > pl.affix; \
108 python3 /usr/local/bin/fold_hunspell.py pl.dict pl.affix \
109 /out/polish.dict /out/polish.affix; \
110 dpkg-query -W -f='hunspell-pl ${Version}\n' hunspell-pl > /out/polish.version
112 # --- Stage 2: actual Postgres image with the dictionary ---
113 FROM postgres:18 AS postgres
115 COPY --from=polish-dict /out/ /tmp/polish-dict/
116 RUN mv /tmp/polish-dict/* "/usr/share/postgresql/$PG_MAJOR/tsearch_data/" \
117 && rmdir /tmp/polish-dict
119 COPY scripts/postgres-polish.sql /docker-entrypoint-initdb.d/10-postgres-polish.sql
124 # That's the production image with staticfiles.json manifest file added.
126 FROM prod-base AS prod
128 COPY --from=static-builder /app/var/static/staticfiles.json /app/var/static/staticfiles.json