|
| 1 | +# Running tests against a dockerised Synapse |
| 2 | + |
| 3 | +It's possible to run integration tests against Synapse |
| 4 | +using [Complement](https://github.com/matrix-org/complement). Complement is a Matrix Spec |
| 5 | +compliance test suite for homeservers, and supports any homeserver docker image configured |
| 6 | +to listen on ports 8008/8448. This document contains instructions for building Synapse |
| 7 | +docker images that can be run inside Complement for testing purposes. |
| 8 | + |
| 9 | +Note that running Synapse's unit tests from within the docker image is not supported. |
| 10 | + |
| 11 | +## Testing with SQLite and single-process Synapse |
| 12 | + |
| 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. |
| 15 | +
|
| 16 | +The instructions below will set up Complement testing for a single-process, |
| 17 | +SQLite-based Synapse deployment. |
| 18 | + |
| 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. You will need a local checkout |
| 30 | +of Complement. Change to the root of your Complement checkout and run: |
| 31 | + |
| 32 | +```sh |
| 33 | +docker build -t complement-synapse -f "dockerfiles/Synapse.Dockerfile" dockerfiles |
| 34 | +``` |
| 35 | + |
| 36 | +This will build an image with the tag `complement-synapse`, which can be handed to |
| 37 | +Complement for testing via the `COMPLEMENT_BASE_IMAGE` environment variable. Refer to |
| 38 | +[Complement's documentation](https://github.com/matrix-org/complement/#running) for |
| 39 | +how to run the tests, as well as the various available command line flags. |
| 40 | + |
| 41 | +## Testing with PostgreSQL and single or multi-process Synapse |
| 42 | + |
| 43 | +The above docker image only supports running Synapse with SQLite and in a |
| 44 | +single-process topology. The following instructions are used to build a Synapse image for |
| 45 | +Complement that supports either single or multi-process topology with a PostgreSQL |
| 46 | +database backend. |
| 47 | + |
| 48 | +As with the single-process image, build the base Synapse docker image. If you wish to run |
| 49 | +tests with the latest release of Synapse, instead of your current checkout, you can skip |
| 50 | +this step. From the root of the repository: |
| 51 | + |
| 52 | +```sh |
| 53 | +docker build -t matrixdotorg/synapse -f docker/Dockerfile . |
| 54 | +``` |
| 55 | + |
| 56 | +This will build an image with the tag `matrixdotorg/synapse`. |
| 57 | + |
| 58 | +Next, we build a new image with worker support based on `matrixdotorg/synapse:latest`. |
| 59 | +Again, from the root of the repository: |
| 60 | + |
| 61 | +```sh |
| 62 | +docker build -t matrixdotorg/synapse-workers -f docker/Dockerfile-workers . |
| 63 | +``` |
| 64 | + |
| 65 | +This will build an image with the tag` matrixdotorg/synapse-workers`. |
| 66 | + |
| 67 | +It's worth noting at this point that this image is fully functional, and |
| 68 | +can be used for testing against locally. See instructions for using the container |
| 69 | +under |
| 70 | +[Running the Dockerfile-worker image standalone](#running-the-dockerfile-worker-image-standalone) |
| 71 | +below. |
| 72 | + |
| 73 | +Finally, build the Synapse image for Complement, which is based on |
| 74 | +`matrixdotorg/synapse-workers`. You will need a local checkout of Complement. Change to |
| 75 | +the root of your Complement checkout and run: |
| 76 | + |
| 77 | +```sh |
| 78 | +docker build -t matrixdotorg/complement-synapse-workers -f dockerfiles/SynapseWorkers.Dockerfile dockerfiles |
| 79 | +``` |
| 80 | + |
| 81 | +This will build an image with the tag `complement-synapse`, which can be handed to |
| 82 | +Complement for testing via the `COMPLEMENT_BASE_IMAGE` environment variable. Refer to |
| 83 | +[Complement's documentation](https://github.com/matrix-org/complement/#running) for |
| 84 | +how to run the tests, as well as the various available command line flags. |
| 85 | + |
| 86 | +## Running the Dockerfile-worker image standalone |
| 87 | + |
| 88 | +For manual testing of a multi-process Synapse instance in Docker, |
| 89 | +[Dockerfile-workers](Dockerfile-workers) is a Dockerfile that will produce an image |
| 90 | +bundling all necessary components together for a workerised homeserver instance. |
| 91 | + |
| 92 | +This includes any desired Synapse worker processes, a nginx to route traffic accordingly, |
| 93 | +a redis for worker communication and a supervisord instance to start up and monitor all |
| 94 | +processes. You will need to provide your own postgres container to connect to, and TLS |
| 95 | +is not handled by the container. |
| 96 | + |
| 97 | +Once you've built the image using the above instructions, you can run it. Be sure |
| 98 | +you've set up a volume according to the [usual Synapse docker instructions](README.md). |
| 99 | +Then run something along the lines of: |
| 100 | + |
| 101 | +``` |
| 102 | +docker run -d --name synapse \ |
| 103 | + --mount type=volume,src=synapse-data,dst=/data \ |
| 104 | + -p 8008:8008 \ |
| 105 | + -e SYNAPSE_SERVER_NAME=my.matrix.host \ |
| 106 | + -e SYNAPSE_REPORT_STATS=no \ |
| 107 | + -e POSTGRES_HOST=postgres \ |
| 108 | + -e POSTGRES_USER=postgres \ |
| 109 | + -e POSTGRES_PASSWORD=somesecret \ |
| 110 | + -e SYNAPSE_WORKER_TYPES=synchrotron,media_repository,user_dir \ |
| 111 | + -e SYNAPSE_WORKERS_WRITE_LOGS_TO_DISK=1 \ |
| 112 | + matrixdotorg/synapse-workers |
| 113 | +``` |
| 114 | + |
| 115 | +...substituting `POSTGRES*` variables for those that match a postgres host you have |
| 116 | +available (usually a running postgres docker container). |
| 117 | + |
| 118 | +The `SYNAPSE_WORKER_TYPES` environment variable is a comma-separated list of workers to |
| 119 | +use when running the container. All possible worker names are defined by the keys of the |
| 120 | +`WORKERS_CONFIG` variable in [this script](configure_workers_and_start.py), which the |
| 121 | +Dockerfile makes use of to generate appropriate worker, nginx and supervisord config |
| 122 | +files. |
| 123 | + |
| 124 | +Sharding is supported for a subset of workers, in line with the |
| 125 | +[worker documentation](../docs/workers.md). To run multiple instances of a given worker |
| 126 | +type, simply specify the type multiple times in `SYNAPSE_WORKER_TYPES` |
| 127 | +(e.g `SYNAPSE_WORKER_TYPES=event_creator,event_creator...`). |
| 128 | + |
| 129 | +Otherwise, `SYNAPSE_WORKER_TYPES` can either be left empty or unset to spawn no workers |
| 130 | +(leaving only the main process). The container is configured to use redis-based worker |
| 131 | +mode. |
| 132 | + |
| 133 | +Logs for workers and the main process are logged to stdout and can be viewed with |
| 134 | +standard `docker logs` tooling. Worker logs contain their worker name |
| 135 | +after the timestamp. |
| 136 | + |
| 137 | +Setting `SYNAPSE_WORKERS_WRITE_LOGS_TO_DISK=1` will cause worker logs to be written to |
| 138 | +`<data_dir>/logs/<worker_name>.log`. Logs are kept for 1 week and rotate every day at 00: |
| 139 | +00, according to the container's clock. Logging for the main process must still be |
| 140 | +configured by modifying the homeserver's log config in your Synapse data volume. |
0 commit comments