|
4 | 4 | # |
5 | 5 | # Instructions for building this image from those it depends on is detailed in this guide: |
6 | 6 | # https://github.com/matrix-org/synapse/blob/develop/docker/README-testing.md#testing-with-postgresql-and-single-or-multi-process-synapse |
| 7 | + |
7 | 8 | ARG SYNAPSE_VERSION=latest |
| 9 | + |
| 10 | +# first of all, we create a base image with a postgres server and database, |
| 11 | +# which we can copy into the target image. For repeated rebuilds, this is |
| 12 | +# much faster than apt installing postgres each time. |
| 13 | +# |
| 14 | +# This trick only works because (a) the Synapse image happens to have all the |
| 15 | +# shared libraries that postgres wants, (v) we use a postgres image based on the same |
| 16 | +# debian version as Synapse's docker image (so the versions of the shared libraries |
| 17 | +# match). |
| 18 | + |
| 19 | +FROM postgres:13-bullseye AS postgres_base |
| 20 | + # initialise the database cluster in /var/lib/postgresql |
| 21 | + RUN gosu postgres initdb --locale=C --encoding=UTF-8 --auth-host password |
| 22 | + |
| 23 | + # Configure a password and create a database for Synapse |
| 24 | + RUN echo "ALTER USER postgres PASSWORD 'somesecret'" | gosu postgres postgres --single |
| 25 | + RUN echo "CREATE DATABASE synapse" | gosu postgres postgres --single |
| 26 | + |
8 | 27 | FROM matrixdotorg/synapse-workers:$SYNAPSE_VERSION |
9 | 28 |
|
10 | | -# Install postgresql |
11 | | -RUN apt-get update && \ |
12 | | - DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -yqq postgresql-13 |
13 | | - |
14 | | -# Configure a user and create a database for Synapse |
15 | | -RUN pg_ctlcluster 13 main start && su postgres -c "echo \ |
16 | | - \"ALTER USER postgres PASSWORD 'somesecret'; \ |
17 | | - CREATE DATABASE synapse \ |
18 | | - ENCODING 'UTF8' \ |
19 | | - LC_COLLATE='C' \ |
20 | | - LC_CTYPE='C' \ |
21 | | - template=template0;\" | psql" && pg_ctlcluster 13 main stop |
| 29 | +# copy the postgres installation over from the image we built above |
| 30 | +RUN adduser --system --uid 999 postgres --home /var/lib/postgresql |
| 31 | +COPY --from=postgres_base /var/lib/postgresql /var/lib/postgresql |
| 32 | +COPY --from=postgres_base /usr/lib/postgresql /usr/lib/postgresql |
| 33 | +COPY --from=postgres_base /usr/share/postgresql /usr/share/postgresql |
| 34 | +RUN mkdir /var/run/postgresql && chown postgres /var/run/postgresql |
| 35 | +ENV PATH="${PATH}:/usr/lib/postgresql/13/bin" |
22 | 36 |
|
23 | 37 | # Extend the shared homeserver config to disable rate-limiting, |
24 | 38 | # set Complement's static shared secret, enable registration, amongst other |
|
0 commit comments