Serialize whole quote
[wolnelektury.git] / Dockerfile
1 # Base system and requirements.
2
3 FROM python:3.9-trixie AS base
4
5 ARG UID=8100
6 ARG GID=8100
7
8 RUN     apt-get update && apt-get install -y \
9         git \
10         calibre \
11         texlive-xetex texlive-lang-polish \
12         texlive-extra-utils \
13         texlive-lang-greek \
14         texlive-lang-other \
15         texlive-luatex \
16         texlive-fonts-extra \
17         texlive-fonts-extra-links \
18         fonts-noto-core fonts-noto-extra
19
20
21 COPY requirements/requirements.txt requirements.txt
22
23 RUN pip install --no-cache-dir -r requirements.txt
24 RUN pip install --no-cache-dir \
25     psycopg2-binary \
26     django-debug-toolbar==3.2.2
27
28 RUN addgroup --gid $GID app && \
29     adduser --gid $GID --home /app --uid $UID app
30
31
32 # fonts
33 RUN cp -a /usr/local/lib/python*/site-packages/librarian/fonts /usr/share/fonts
34 RUN fc-cache
35
36 USER app
37
38 WORKDIR /app/src
39
40 RUN mkdir /app/.ipython
41
42
43
44 # dev
45 # Assumes code will be mounted.
46
47 FROM base AS dev
48
49 #RUN pip install --no-cache-dir coverage
50
51
52 # prod-base
53 # Installs code and production requirements.
54
55 FROM base AS prod-base
56
57 USER root
58
59 RUN pip install --no-cache-dir gunicorn
60
61 USER app
62
63 COPY src /app/src
64
65
66 # static-builder
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.
69
70 FROM prod-base AS static-builder
71
72 RUN python manage.py collectstatic --noinput
73
74
75 # nginx
76 # Contains static files and nginx config.
77
78 FROM nginx:alpine AS nginx
79
80 ARG UID=8100
81 ARG GID=8100
82
83 # COPY nginx.conf conf.d/...
84
85 RUN addgroup -g $GID app && addgroup nginx app
86 COPY --from=static-builder /app/var/static /app/var/static
87
88
89
90
91 # Postgres with Polish hunspell dictionary withoud diacritics
92 # to allow full text search without diacritics.
93
94 # --- Stage 1: prepare dictionary files ---
95 FROM python:3.13-slim-trixie AS polish-dict
96
97 RUN apt-get update \
98  && apt-get install -y --no-install-recommends hunspell-pl \
99  && rm -rf /var/lib/apt/lists/*
100
101 COPY scripts/fold_hunspell.py /usr/local/bin/fold_hunspell.py
102
103 RUN set -eu; \
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
111
112 # --- Stage 2: actual Postgres image with the dictionary ---
113 FROM postgres:18 AS postgres
114
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
118
119 COPY scripts/postgres-polish.sql /docker-entrypoint-initdb.d/10-postgres-polish.sql
120
121
122
123 # prod
124 # That's the production image with staticfiles.json manifest file added.
125
126 FROM prod-base AS prod
127
128 COPY --from=static-builder /app/var/static/staticfiles.json /app/var/static/staticfiles.json