This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add a dockerfile for running a set of Synapse worker processes #9162
Merged
Merged
Changes from 39 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
31e9579
Add docker image for Synapse with Workers
anoadragon453 d61dc37
Prevent an empty resources: list if no listener_resources defined
anoadragon453 3523080
Add documentation for the dockerfile
anoadragon453 e66f9e7
Changelog
anoadragon453 2e3134b
Missing media path for media worker
MatMaul f6571ee
Actually launch redis through supervisord
MatMaul 3f1b649
Add worker_extra_conf for media repo
MatMaul 8b41fdf
Keep redis in foreground
MatMaul 2d6af88
Reacts on keyboard signals
MatMaul cb0b272
Move nginx to 8008 and master to 8080
MatMaul 842dc50
lint
anoadragon453 31cac05
Axe healthcheck TODO
anoadragon453 fb40f20
Switch to templates instead of inline for process configs
anoadragon453 e363197
Rename SYNAPSE_PORT to SYNAPSE_HTTP_PORT, explain its use
anoadragon453 fb83854
Improve wording of single-container worker docker setup
anoadragon453 4779845
Remove support for '*' to specify all workers
anoadragon453 b265083
Add support for sharded worker instances
anoadragon453 e99007d
Add support for a background_worker worker type
anoadragon453 48b7faf
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/syn…
anoadragon453 cc9d243
lint
anoadragon453 04dd483
Explicitly set worker listener resources
anoadragon453 278579a
Stream writers need a replication listener configured
anoadragon453 7f5a8ee
Add frontend_proxy, event_creator support
anoadragon453 609f1c1
Drop whitelist of shardable worker types.
anoadragon453 f9d7e28
Prefix worker log lines with worker name
anoadragon453 3ae6108
Explicitly set supervisord to be root, instead of it guessing we want…
anoadragon453 f39a25b
Add load-balancing support; support sharding media_repo
anoadragon453 21b3f22
Bail out from configure script if it is run multiple times
anoadragon453 1711d34
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/syn…
anoadragon453 c54801a
Add env var SYNAPSE_WORKERS_WRITE_LOGS_TO_DISK
anoadragon453 0bd42a3
Update documentation for new env var behaviour
anoadragon453 ea31dc8
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/syn…
anoadragon453 5a77614
Clarify this is intended for testing purposes
anoadragon453 69a6399
Move worker setup-specific config template files to a separate dir
anoadragon453 e3fbd62
Apply suggestions from code review
anoadragon453 d844d97
Update worker docker image name to matrixdotorg/synapse-workers
anoadragon453 f218ae9
Move config block section templates outside of 'generate_worker_files
anoadragon453 a7666d1
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/syn…
anoadragon453 486d5d1
Move worker docker documentation to README-testing, document Compleme…
anoadragon453 e47b390
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/syn…
anoadragon453 700c203
SYNAPSE_WORKERS -> SYNAPSE_WORKER_TYPES
anoadragon453 314473f
Apply suggestions from code review
anoadragon453 030b1f4
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/syn…
anoadragon453 1a37f25
Remove python text encoding delcaration
anoadragon453 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add a dockerfile for running Synapse in worker-mode under Complement. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Inherit from the official Synapse docker image | ||
| FROM matrixdotorg/synapse | ||
|
|
||
| # Install deps | ||
| RUN apt-get update | ||
| RUN apt-get install -y supervisor redis nginx | ||
|
|
||
| # Remove the default nginx sites | ||
| RUN rm /etc/nginx/sites-enabled/default | ||
|
|
||
| # Copy Synapse worker, nginx and supervisord configuration template files | ||
| COPY ./docker/conf-workers/* /conf/ | ||
|
|
||
| # Expose nginx listener port | ||
| EXPOSE 8080/tcp | ||
|
|
||
| # Volume for user-editable config files, logs etc. | ||
| VOLUME ["/data"] | ||
|
|
||
| # A script to read environment variables and create the necessary | ||
| # files to run the desired worker configuration. Will start supervisord. | ||
| COPY ./docker/configure_workers_and_start.py /configure_workers_and_start.py | ||
| ENTRYPOINT ["/configure_workers_and_start.py"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # Running tests against a dockerised Synapse | ||
|
|
||
| It's possible to run integration tests against Synapse | ||
| using [Complement](https://github.com/matrix-org/complement). Complement is a Matrix Spec | ||
| compliance test suite for homeservers, and supports any homeserver docker image configured | ||
| to listen on ports 8008/8448. This document contains instructions for building Synapse | ||
| docker images that can be run inside Complement for testing purposes. | ||
|
|
||
| Note that running Synapse's unit tests from within the docker image is not supported. | ||
|
|
||
| ## Testing with SQLite and single-process Synapse | ||
|
|
||
| > Note that `scripts-dev/complement.sh` is a script that will automatically build | ||
| > and run an SQLite-based, single-process of Synapse against Complement. | ||
| The instructions below will set up Complement testing for a single-process, | ||
| SQLite-based Synapse deployment. | ||
|
|
||
| Start by building the base Synapse docker image. If you wish to run tests with the latest | ||
| release of Synapse, instead of your current checkout, you can skip this step. From the | ||
| root of the repository: | ||
|
|
||
| ```sh | ||
| docker build -t matrixdotorg/synapse -f docker/Dockerfile . | ||
| ``` | ||
|
|
||
| This will build an image with the tag `matrixdotorg/synapse`. | ||
|
|
||
| Next, build the Synapse image for Complement. You will need a local checkout | ||
| of Complement. Change to the root of your Complement checkout and run: | ||
|
|
||
| ```sh | ||
| docker build -t complement-synapse -f "dockerfiles/Synapse.Dockerfile" dockerfiles | ||
| ``` | ||
|
|
||
| This will build an image with the tag `complement-synapse`, which can be handed to | ||
| Complement for testing via the `COMPLEMENT_BASE_IMAGE` environment variable. Refer to | ||
| [Complement's documentation](https://github.com/matrix-org/complement/#running) for | ||
| how to run the tests, as well as the various available command line flags. | ||
|
|
||
| ## Testing with PostgreSQL and single or multi-process Synapse | ||
|
|
||
| The above docker image only supports running Synapse with SQLite and in a | ||
| single-process topology. The following instructions are used to build a Synapse image for | ||
| Complement that supports either single or multi-process topology with a PostgreSQL | ||
| database backend. | ||
|
|
||
| As with the single-process image, build the base Synapse docker image. If you wish to run | ||
| tests with the latest release of Synapse, instead of your current checkout, you can skip | ||
| this step. From the root of the repository: | ||
|
|
||
| ```sh | ||
| docker build -t matrixdotorg/synapse -f docker/Dockerfile . | ||
| ``` | ||
|
|
||
| This will build an image with the tag `matrixdotorg/synapse`. | ||
|
|
||
| Next, we build a new image with worker support based on `matrixdotorg/synapse:latest`. | ||
| Again, from the root of the repository: | ||
|
|
||
| ```sh | ||
| docker build -t matrixdotorg/synapse-workers -f docker/Dockerfile-workers . | ||
| ``` | ||
|
|
||
| This will build an image with the tag` matrixdotorg/synapse-workers`. | ||
|
|
||
| It's worth noting at this point that this image is fully functional, and | ||
| can be used for testing against locally. See instructions for using the container | ||
| under [Running the Dockerfile-worker image](#Running the Dockerfile-worker image) below. | ||
|
|
||
| Finally, build the Synapse image for Complement, which is based on | ||
| `matrixdotorg/synapse-workers`. You will need a local checkout of Complement. Change to | ||
| the root of your Complement checkout and run: | ||
|
|
||
| ```sh | ||
| docker build -t matrixdotorg/complement-synapse-workers -f dockerfiles/SynapseWorkers.Dockerfile dockerfiles | ||
| ``` | ||
|
|
||
| This will build an image with the tag `complement-synapse`, which can be handed to | ||
| Complement for testing via the `COMPLEMENT_BASE_IMAGE` environment variable. Refer to | ||
| [Complement's documentation](https://github.com/matrix-org/complement/#running) for | ||
| how to run the tests, as well as the various available command line flags. | ||
|
|
||
| ## Running the Dockerfile-worker image standalone | ||
|
|
||
| For manual testing of a multi-process Synapse instance in Docker, | ||
| [Dockerfile-workers](Dockerfile-workers) is a Dockerfile that will produce an image | ||
| bundling all necessary components together for a workerised homeserver instance. | ||
|
|
||
| This includes any desired Synapse worker processes, a nginx to route traffic accordingly, | ||
| a redis for worker communication and a supervisord instance to start up and monitor all | ||
| processes. You will need to provide your own postgres container to connect to, and TLS | ||
| is not handled by the container. | ||
|
|
||
| Once you've built the image using the above instructions, you can run it. Be sure | ||
| you've set up a volume according to the [usual Synapse docker instructions](README.md). | ||
| Then run something along the lines of: | ||
|
|
||
| ``` | ||
| docker run -d --name synapse \ | ||
| --mount type=volume,src=synapse-data,dst=/data \ | ||
| -p 8008:8008 \ | ||
| -e SYNAPSE_SERVER_NAME=my.matrix.host \ | ||
| -e SYNAPSE_REPORT_STATS=no \ | ||
| -e POSTGRES_HOST=postgres -e POSTGRES_USER=postgres POSTGRES_PASSWORD=somesecret \ | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| -e SYNAPSE_WORKERS=synchrotron,media_repository,user_dir \ | ||
| -e SYNAPSE_WORKERS_WRITE_LOGS_TO_DISK=1 \ | ||
| matrixdotorg/synapse-workers | ||
| ``` | ||
|
|
||
| Substituting `POSTGRES*` variables for those that match a postgres host you have | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| available (usually a running postgres docker container). | ||
|
|
||
| The `SYNAPSE_WORKERS` environment variable is a comma-separated list of workers to use | ||
| when running the container. All possible worker names are defined by the keys of the | ||
| `WORKERS_CONFIG` variable in [this script](configure_workers_and_start.py), which the | ||
| Dockerfile makes use of to generate appropriate worker, nginx and supervisord config files. | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Sharding is supported for a subset of workers, in line with the [worker documentation] | ||
| (../docs/workers.md). To run multiple instances of a given worker type, simply specify | ||
anoadragon453 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| the type multiple times in `SYNAPSE_WORKERS` | ||
| (e.g `SYNAPSE_WORKERS=event_creator,event_creator...`). | ||
|
|
||
| Otherwise, `SYNAPSE_WORKERS` can either be left empty or unset to spawn no workers | ||
| (leaving only the main process). The container is configured to use redis-based worker | ||
| mode. | ||
|
|
||
| Logs for workers and the main process are logged to stdout and can be viewed with | ||
| standard `docker logs` tooling. Worker logs contain their worker name | ||
| after the timestamp. | ||
|
|
||
| Setting `SYNAPSE_WORKERS_WRITE_LOGS_TO_DISK=1` will cause worker logs to be written to | ||
| `<data_dir>/logs/<worker_name>.log`. Logs are kept for 1 week and rotate every day at 00: | ||
| 00, according to the container's clock. Logging for the main process must still be | ||
| configured by modifying the homeserver's log config in your Synapse data volume. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # This file contains the base config for the reverse proxy, as part of ../Dockerfile-workers. | ||
| # configure_workers_and_start.py uses and amends to this file depending on the workers | ||
| # that have been selected. | ||
|
|
||
| {{ upstream_directives }} | ||
|
|
||
| server { | ||
| # Listen on an unoccupied port number | ||
| listen 8008; | ||
| listen [::]:8008; | ||
|
|
||
| server_name localhost; | ||
|
|
||
| # Nginx by default only allows file uploads up to 1M in size | ||
| # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml | ||
| client_max_body_size 100M; | ||
|
|
||
| {{ worker_locations }} | ||
|
|
||
| # Send all other traffic to the main process | ||
| location ~* ^(\\/_matrix|\\/_synapse) { | ||
| proxy_pass http://localhost:8080; | ||
| proxy_set_header X-Forwarded-For $remote_addr; | ||
| proxy_set_header X-Forwarded-Proto $scheme; | ||
| proxy_set_header Host $host; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # This file contains the base for the shared homeserver config file between Synapse workers, | ||
| # as part of ./Dockerfile-workers. | ||
| # configure_workers_and_start.py uses and amends to this file depending on the workers | ||
| # that have been selected. | ||
|
|
||
| redis: | ||
| enabled: true | ||
|
|
||
| {{ shared_worker_config }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # This file contains the base config for supervisord, as part of ../Dockerfile-workers. | ||
| # configure_workers_and_start.py uses and amends to this file depending on the workers | ||
| # that have been selected. | ||
| [supervisord] | ||
| nodaemon=true | ||
| user=root | ||
|
|
||
| [program:nginx] | ||
| command=/usr/sbin/nginx -g "daemon off;" | ||
| priority=500 | ||
| stdout_logfile=/dev/stdout | ||
| stdout_logfile_maxbytes=0 | ||
| stderr_logfile=/dev/stderr | ||
| stderr_logfile_maxbytes=0 | ||
| username=www-data | ||
| autorestart=true | ||
|
|
||
| [program:redis] | ||
| command=/usr/bin/redis-server /etc/redis/redis.conf --daemonize no | ||
| priority=1 | ||
| stdout_logfile=/dev/stdout | ||
| stdout_logfile_maxbytes=0 | ||
| stderr_logfile=/dev/stderr | ||
| stderr_logfile_maxbytes=0 | ||
| username=redis | ||
| autorestart=true | ||
|
|
||
| [program:synapse_main] | ||
| command=/usr/local/bin/python -m synapse.app.homeserver --config-path="{{ main_config_path }}" --config-path=/conf/workers/shared.yaml | ||
| priority=10 | ||
| # Log startup failures to supervisord's stdout/err | ||
| # Regular synapse logs will still go in the configured data directory | ||
| stdout_logfile=/dev/stdout | ||
| stdout_logfile_maxbytes=0 | ||
| stderr_logfile=/dev/stderr | ||
| stderr_logfile_maxbytes=0 | ||
| autorestart=unexpected | ||
| exitcodes=0 | ||
|
|
||
| # Additional process blocks | ||
| {{ worker_config }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # This is a configuration template for a single worker instance, and is | ||
| # used by Dockerfile-workers. | ||
| # Values will be change depending on whichever workers are selected when | ||
| # running that image. | ||
|
|
||
| worker_app: "{{ app }}" | ||
| worker_name: "{{ name }}" | ||
|
|
||
| # The replication listener on the main synapse process. | ||
| worker_replication_host: 127.0.0.1 | ||
| worker_replication_http_port: 9093 | ||
|
|
||
| worker_listeners: | ||
| - type: http | ||
| port: {{ port }} | ||
| {% if listener_resources %} | ||
| resources: | ||
| - names: | ||
| {%- for resource in listener_resources %} | ||
| - {{ resource }} | ||
| {%- endfor %} | ||
| {% endif %} | ||
|
|
||
| worker_log_config: {{ worker_log_config_filepath }} | ||
|
|
||
| {{ worker_extra_conf }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.