1 # Wolne Lektury images.
3 # Stages marked with ##### are build targets:
4 # deps dev image (docker-compose.yml, code mounted)
5 # test docker-compose.test.yml
6 # prod production app image (default, last stage)
7 # nginx production nginx with static files
8 # postgres Postgres with Polish dictionary
9 # Stages marked with ===== are intermediate.
12 # Global build arguments. Stages using UID/GID must redeclare them
13 # (bare `ARG UID`) to bring them into scope; the defaults are set here.
15 ARG PYTHON_IMAGE=python:3.9-trixie
21 # deps #############################################################
23 # Base system and requirements.
24 # Used directly as the dev image, with code mounted.
26 FROM ${PYTHON_IMAGE} AS deps
31 RUN apt-get update && apt-get install -y \
34 texlive-xetex texlive-lang-polish \
40 texlive-fonts-extra-links \
41 fonts-noto-core fonts-noto-extra
44 COPY requirements/requirements.txt requirements.txt
46 RUN pip install --no-cache-dir -r requirements.txt
47 RUN pip install --no-cache-dir \
49 django-debug-toolbar==3.2.2
51 RUN addgroup --gid $GID app && \
52 adduser --gid $GID --home /app --uid $UID app
56 RUN cp -a /usr/local/lib/python*/site-packages/librarian/fonts /usr/share/fonts
63 RUN mkdir /app/.ipython
67 # app #=============================================================
69 # Code and production requirements. Not production yet: needs
70 # staticfiles.json manifest from static-builder.
76 RUN pip install --no-cache-dir gunicorn
84 # static-builder #==================================================
86 # Static files are collected here. Statics are then copied into
87 # the nginx image, and staticfiles.json manifest is copied back
88 # into the test and prod images.
90 FROM app AS static-builder
92 RUN python manage.py collectstatic --noinput
96 # nginx ############################################################
98 # Static files for production nginx. Config is mounted.
100 FROM nginx:alpine AS nginx
105 # COPY nginx.conf conf.d/...
107 RUN addgroup -g $GID app && addgroup nginx app
108 COPY --from=static-builder /app/var/static /app/var/static
112 # polish-dict #=====================================================
114 # Polish hunspell dictionary without diacritics, to allow
115 # full text search without diacritics.
117 FROM ${PYTHON_IMAGE} AS polish-dict
120 && apt-get install -y --no-install-recommends hunspell-pl \
121 && rm -rf /var/lib/apt/lists/*
123 COPY scripts/fold_hunspell.py /usr/local/bin/fold_hunspell.py
126 mkdir /out; cd /tmp; \
127 enc="$(sed -n 's/^SET[[:space:]]*//p' /usr/share/hunspell/pl_PL.aff | tr -d '\r')"; \
128 iconv -f "${enc:-UTF-8}" -t UTF-8 /usr/share/hunspell/pl_PL.dic > pl.dict; \
129 iconv -f "${enc:-UTF-8}" -t UTF-8 /usr/share/hunspell/pl_PL.aff > pl.affix; \
130 python3 /usr/local/bin/fold_hunspell.py pl.dict pl.affix \
131 /out/polish.dict /out/polish.affix; \
132 dpkg-query -W -f='hunspell-pl ${Version}\n' hunspell-pl > /out/polish.version
136 # postgres #########################################################
138 # Postgres with the dictionary from polish-dict.
140 FROM postgres:18 AS postgres
142 COPY --from=polish-dict /out/ /tmp/polish-dict/
143 RUN mv /tmp/polish-dict/* "/usr/share/postgresql/$PG_MAJOR/tsearch_data/" \
144 && rmdir /tmp/polish-dict
146 COPY scripts/postgres-polish.sql /docker-entrypoint-initdb.d/10-postgres-polish.sql
150 # test #############################################################
152 # Production image plus test requirements. Defined before `prod`,
153 # so that `prod` stays the default (last) stage.
158 COPY requirements/requirements-test.txt /tmp/
159 RUN pip install --no-cache-dir -r /tmp/requirements-test.txt
161 RUN mkdir -p /app/var/counters
162 COPY --from=static-builder /app/var/static/staticfiles.json /app/var/static/staticfiles.json
163 CMD ["./manage.py", "test"]
167 # prod #############################################################
169 # Production image: app + staticfiles.json manifest.
173 COPY --from=static-builder /app/var/static/staticfiles.json /app/var/static/staticfiles.json