Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 67f51c8

Browse files
reivilibrerichvdh
andauthored
Merge the Complement testing Docker images into a single, multi-purpose image. (#12881)
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
1 parent c316fe8 commit 67f51c8

18 files changed

+276
-371
lines changed

changelog.d/12881.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Merge the Complement testing Docker images into a single, multi-purpose image.

docker/Dockerfile-workers

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Inherit from the official Synapse docker image
2-
FROM matrixdotorg/synapse
2+
ARG SYNAPSE_VERSION=latest
3+
FROM matrixdotorg/synapse:$SYNAPSE_VERSION
34

45
# Install deps
56
RUN \

docker/README-testing.md

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,79 +8,50 @@ docker images that can be run inside Complement for testing purposes.
88

99
Note that running Synapse's unit tests from within the docker image is not supported.
1010

11-
## Testing with SQLite and single-process Synapse
11+
## Using the Complement launch script
1212

13-
> Note that `scripts-dev/complement.sh` is a script that will automatically build
14-
> and run an SQLite-based, single-process of Synapse against Complement.
13+
`scripts-dev/complement.sh` is a script that will automatically build
14+
and run Synapse against Complement.
15+
Consult the [contributing guide][guideComplementSh] for instructions on how to use it.
1516

16-
The instructions below will set up Complement testing for a single-process,
17-
SQLite-based Synapse deployment.
1817

19-
Start by building the base Synapse docker image. If you wish to run tests with the latest
20-
release of Synapse, instead of your current checkout, you can skip this step. From the
21-
root of the repository:
22-
23-
```sh
24-
docker build -t matrixdotorg/synapse -f docker/Dockerfile .
25-
```
26-
27-
This will build an image with the tag `matrixdotorg/synapse`.
28-
29-
Next, build the Synapse image for Complement.
18+
[guideComplementSh]: https://matrix-org.github.io/synapse/latest/development/contributing_guide.html#run-the-integration-tests-complement
3019

31-
```sh
32-
docker build -t complement-synapse -f "docker/complement/Dockerfile" docker/complement
33-
```
20+
## Building and running the images manually
3421

35-
This will build an image with the tag `complement-synapse`, which can be handed to
36-
Complement for testing via the `COMPLEMENT_BASE_IMAGE` environment variable. Refer to
37-
[Complement's documentation](https://github.com/matrix-org/complement/#running) for
38-
how to run the tests, as well as the various available command line flags.
39-
40-
## Testing with PostgreSQL and single or multi-process Synapse
22+
Under some circumstances, you may wish to build the images manually.
23+
The instructions below will lead you to doing that.
4124

42-
The above docker image only supports running Synapse with SQLite and in a
43-
single-process topology. The following instructions are used to build a Synapse image for
44-
Complement that supports either single or multi-process topology with a PostgreSQL
45-
database backend.
46-
47-
As with the single-process image, build the base Synapse docker image. If you wish to run
48-
tests with the latest release of Synapse, instead of your current checkout, you can skip
49-
this step. From the root of the repository:
25+
Start by building the base Synapse docker image. If you wish to run tests with the latest
26+
release of Synapse, instead of your current checkout, you can skip this step. From the
27+
root of the repository:
5028

5129
```sh
5230
docker build -t matrixdotorg/synapse -f docker/Dockerfile .
5331
```
5432

55-
This will build an image with the tag `matrixdotorg/synapse`.
56-
57-
Next, we build a new image with worker support based on `matrixdotorg/synapse:latest`.
58-
Again, from the root of the repository:
33+
Next, build the workerised Synapse docker image, which is a layer over the base
34+
image.
5935

6036
```sh
6137
docker build -t matrixdotorg/synapse-workers -f docker/Dockerfile-workers .
6238
```
6339

64-
This will build an image with the tag` matrixdotorg/synapse-workers`.
65-
66-
It's worth noting at this point that this image is fully functional, and
67-
can be used for testing against locally. See instructions for using the container
68-
under
69-
[Running the Dockerfile-worker image standalone](#running-the-dockerfile-worker-image-standalone)
70-
below.
71-
72-
Finally, build the Synapse image for Complement, which is based on
73-
`matrixdotorg/synapse-workers`.
40+
Finally, build the multi-purpose image for Complement, which is a layer over the workers image.
7441

7542
```sh
76-
docker build -t matrixdotorg/complement-synapse-workers -f docker/complement/SynapseWorkers.Dockerfile docker/complement
43+
docker build -t complement-synapse -f docker/complement/Dockerfile docker/complement
7744
```
7845

79-
This will build an image with the tag `complement-synapse-workers`, which can be handed to
46+
This will build an image with the tag `complement-synapse`, which can be handed to
8047
Complement for testing via the `COMPLEMENT_BASE_IMAGE` environment variable. Refer to
8148
[Complement's documentation](https://github.com/matrix-org/complement/#running) for
8249
how to run the tests, as well as the various available command line flags.
8350

51+
See [the Complement image README](./complement/README.md) for information about the
52+
expected environment variables.
53+
54+
8455
## Running the Dockerfile-worker image standalone
8556

8657
For manual testing of a multi-process Synapse instance in Docker,
@@ -113,6 +84,9 @@ docker run -d --name synapse \
11384
...substituting `POSTGRES*` variables for those that match a postgres host you have
11485
available (usually a running postgres docker container).
11586

87+
88+
### Workers
89+
11690
The `SYNAPSE_WORKER_TYPES` environment variable is a comma-separated list of workers to
11791
use when running the container. All possible worker names are defined by the keys of the
11892
`WORKERS_CONFIG` variable in [this script](configure_workers_and_start.py), which the
@@ -125,8 +99,11 @@ type, simply specify the type multiple times in `SYNAPSE_WORKER_TYPES`
12599
(e.g `SYNAPSE_WORKER_TYPES=event_creator,event_creator...`).
126100

127101
Otherwise, `SYNAPSE_WORKER_TYPES` can either be left empty or unset to spawn no workers
128-
(leaving only the main process). The container is configured to use redis-based worker
129-
mode.
102+
(leaving only the main process).
103+
The container will only be configured to use Redis-based worker mode if there are
104+
workers enabled.
105+
106+
### Logging
130107

131108
Logs for workers and the main process are logged to stdout and can be viewed with
132109
standard `docker logs` tooling. Worker logs contain their worker name
@@ -136,3 +113,21 @@ Setting `SYNAPSE_WORKERS_WRITE_LOGS_TO_DISK=1` will cause worker logs to be writ
136113
`<data_dir>/logs/<worker_name>.log`. Logs are kept for 1 week and rotate every day at 00:
137114
00, according to the container's clock. Logging for the main process must still be
138115
configured by modifying the homeserver's log config in your Synapse data volume.
116+
117+
118+
### Application Services
119+
120+
Setting the `SYNAPSE_AS_REGISTRATION_DIR` environment variable to the path of
121+
a directory (within the container) will cause the configuration script to scan
122+
that directory for `.yaml`/`.yml` registration files.
123+
Synapse will be configured to load these configuration files.
124+
125+
126+
### TLS Termination
127+
128+
Nginx is present in the image to route requests to the appropriate workers,
129+
but it does not serve TLS by default.
130+
131+
You can configure `SYNAPSE_TLS_CERT` and `SYNAPSE_TLS_KEY` to point to a
132+
TLS certificate and key (respectively), both in PEM (textual) format.
133+
In this case, Nginx will additionally serve using HTTPS on port 8448.

docker/complement/Dockerfile

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
1-
# A dockerfile which builds an image suitable for testing Synapse under
2-
# complement.
3-
1+
# This dockerfile builds on top of 'docker/Dockerfile-workers' in matrix-org/synapse
2+
# by including a built-in postgres instance, as well as setting up the homeserver so
3+
# that it is ready for testing via Complement.
4+
#
5+
# Instructions for building this image from those it depends on is detailed in this guide:
6+
# https://github.com/matrix-org/synapse/blob/develop/docker/README-testing.md#testing-with-postgresql-and-single-or-multi-process-synapse
47
ARG SYNAPSE_VERSION=latest
8+
FROM matrixdotorg/synapse-workers:$SYNAPSE_VERSION
9+
10+
# Install postgresql
11+
RUN apt-get update && \
12+
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y 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
22+
23+
# Extend the shared homeserver config to disable rate-limiting,
24+
# set Complement's static shared secret, enable registration, amongst other
25+
# tweaks to get Synapse ready for testing.
26+
# To do this, we copy the old template out of the way and then include it
27+
# with Jinja2.
28+
RUN mv /conf/shared.yaml.j2 /conf/shared-orig.yaml.j2
29+
COPY conf/workers-shared-extra.yaml.j2 /conf/shared.yaml.j2
530

6-
FROM matrixdotorg/synapse:${SYNAPSE_VERSION}
7-
8-
ENV SERVER_NAME=localhost
9-
10-
COPY conf/* /conf/
31+
WORKDIR /data
1132

12-
# generate a signing key
13-
RUN generate_signing_key -o /conf/server.signing.key
33+
COPY conf/postgres.supervisord.conf /etc/supervisor/conf.d/postgres.conf
1434

15-
WORKDIR /data
35+
# Copy the entrypoint
36+
COPY conf/start_for_complement.sh /
1637

38+
# Expose nginx's listener ports
1739
EXPOSE 8008 8448
1840

19-
ENTRYPOINT ["/conf/start.sh"]
41+
ENTRYPOINT ["/start_for_complement.sh"]
2042

43+
# Update the healthcheck to have a shorter check interval
2144
HEALTHCHECK --start-period=5s --interval=1s --timeout=1s \
22-
CMD curl -fSs http://localhost:8008/health || exit 1
45+
CMD /bin/sh /healthcheck.sh

docker/complement/README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
1-
Stuff for building the docker image used for testing under complement.
1+
# Unified Complement image for Synapse
2+
3+
This is an image for testing Synapse with [the *Complement* integration test suite][complement].
4+
It contains some insecure defaults that are only suitable for testing purposes,
5+
so **please don't use this image for a production server**.
6+
7+
This multi-purpose image is built on top of `Dockerfile-workers` in the parent directory
8+
and can be switched using environment variables between the following configurations:
9+
10+
- Monolithic Synapse with SQLite (`SYNAPSE_COMPLEMENT_DATABASE=sqlite`)
11+
- Monolithic Synapse with Postgres (`SYNAPSE_COMPLEMENT_DATABASE=postgres`)
12+
- Workerised Synapse with Postgres (`SYNAPSE_COMPLEMENT_DATABASE=postgres` and `SYNAPSE_COMPLEMENT_USE_WORKERS=true`)
13+
14+
The image is self-contained; it contains an integrated Postgres, Redis and Nginx.
15+
16+
17+
## How to get Complement to pass the environment variables through
18+
19+
To pass these environment variables, use [Complement's `COMPLEMENT_SHARE_ENV_PREFIX`][complementEnv]
20+
variable to configure an environment prefix to pass through, then prefix the above options
21+
with that prefix.
22+
23+
Example:
24+
```
25+
COMPLEMENT_SHARE_ENV_PREFIX=PASS_ PASS_SYNAPSE_COMPLEMENT_DATABASE=postgres
26+
```
27+
28+
Consult `scripts-dev/complement.sh` in the repository root for a real example.
29+
30+
31+
[complement]: https://github.com/matrix-org/complement
32+
[complementEnv]: https://github.com/matrix-org/complement/pull/382

docker/complement/SynapseWorkers.Dockerfile

Lines changed: 0 additions & 40 deletions
This file was deleted.

docker/complement/conf-workers/start-complement-synapse-workers.sh

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)