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

Add a dockerfile for running a set of Synapse worker processes #9162

Merged
merged 44 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 11 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 Dec 14, 2020
d61dc37
Prevent an empty resources: list if no listener_resources defined
anoadragon453 Jan 20, 2021
3523080
Add documentation for the dockerfile
anoadragon453 Jan 19, 2021
e66f9e7
Changelog
anoadragon453 Jan 19, 2021
2e3134b
Missing media path for media worker
MatMaul Jan 22, 2021
f6571ee
Actually launch redis through supervisord
MatMaul Jan 22, 2021
3f1b649
Add worker_extra_conf for media repo
MatMaul Jan 22, 2021
8b41fdf
Keep redis in foreground
MatMaul Jan 23, 2021
2d6af88
Reacts on keyboard signals
MatMaul Jan 23, 2021
cb0b272
Move nginx to 8008 and master to 8080
MatMaul Jan 23, 2021
842dc50
lint
anoadragon453 Jan 23, 2021
31cac05
Axe healthcheck TODO
anoadragon453 Feb 1, 2021
fb40f20
Switch to templates instead of inline for process configs
anoadragon453 Feb 2, 2021
e363197
Rename SYNAPSE_PORT to SYNAPSE_HTTP_PORT, explain its use
anoadragon453 Mar 3, 2021
fb83854
Improve wording of single-container worker docker setup
anoadragon453 Mar 3, 2021
4779845
Remove support for '*' to specify all workers
anoadragon453 Mar 3, 2021
b265083
Add support for sharded worker instances
anoadragon453 Mar 4, 2021
e99007d
Add support for a background_worker worker type
anoadragon453 Mar 4, 2021
48b7faf
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/syn…
anoadragon453 Mar 5, 2021
cc9d243
lint
anoadragon453 Mar 5, 2021
04dd483
Explicitly set worker listener resources
anoadragon453 Mar 5, 2021
278579a
Stream writers need a replication listener configured
anoadragon453 Mar 5, 2021
7f5a8ee
Add frontend_proxy, event_creator support
anoadragon453 Mar 8, 2021
609f1c1
Drop whitelist of shardable worker types.
anoadragon453 Mar 8, 2021
f9d7e28
Prefix worker log lines with worker name
anoadragon453 Mar 9, 2021
3ae6108
Explicitly set supervisord to be root, instead of it guessing we want…
anoadragon453 Mar 10, 2021
f39a25b
Add load-balancing support; support sharding media_repo
anoadragon453 Mar 22, 2021
21b3f22
Bail out from configure script if it is run multiple times
anoadragon453 Mar 24, 2021
1711d34
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/syn…
anoadragon453 Mar 25, 2021
c54801a
Add env var SYNAPSE_WORKERS_WRITE_LOGS_TO_DISK
anoadragon453 Mar 25, 2021
0bd42a3
Update documentation for new env var behaviour
anoadragon453 Mar 29, 2021
ea31dc8
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/syn…
anoadragon453 Mar 29, 2021
5a77614
Clarify this is intended for testing purposes
anoadragon453 Apr 6, 2021
69a6399
Move worker setup-specific config template files to a separate dir
anoadragon453 Apr 6, 2021
e3fbd62
Apply suggestions from code review
anoadragon453 Apr 6, 2021
d844d97
Update worker docker image name to matrixdotorg/synapse-workers
anoadragon453 Apr 6, 2021
f218ae9
Move config block section templates outside of 'generate_worker_files
anoadragon453 Apr 6, 2021
a7666d1
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/syn…
anoadragon453 Apr 6, 2021
486d5d1
Move worker docker documentation to README-testing, document Compleme…
anoadragon453 Apr 9, 2021
e47b390
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/syn…
anoadragon453 Apr 13, 2021
700c203
SYNAPSE_WORKERS -> SYNAPSE_WORKER_TYPES
anoadragon453 Apr 13, 2021
314473f
Apply suggestions from code review
anoadragon453 Apr 14, 2021
030b1f4
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/syn…
anoadragon453 Apr 14, 2021
1a37f25
Remove python text encoding delcaration
anoadragon453 Apr 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/9162.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a dockerfile for running Synapse in worker-mode under Complement.
25 changes: 25 additions & 0 deletions docker/Dockerfile-workers
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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 the worker process and log configuration files
COPY ./docker/conf/worker.yaml.j2 /conf/worker.yaml.j2

# 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"]

# TODO: Healthcheck? Which worker to ask? Can we ask supervisord?
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
48 changes: 48 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,51 @@ healthcheck:
timeout: 10s
retries: 3
```

### Running all worker processes in a single container
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved

Anyone looking to run Synapse workers with docker in production should use one container
per Synapse process, specifying a different worker config per container.
However, if for some reason you want to run all Synapse processes in the same
container, [Dockerfile-workers](Dockerfile-workers) will provide that functionality (the
team currently use this image for
[Complement testing](https://github.com/matrix-org/complement), which requires a complete
homeserver bundled in a single docker image).

The Dockerfile will create a container with any desired Synapse worker processes, as well as
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. TLS is not handled by the container. A reverse proxy should be
placed in front the exposed HTTP port for the purposes of TLS termination.

Note that the worker Dockerfile is based off the main `[Dockerfile](Dockerfile)`. If you
would like to build from the current checkout, first build the main Synapse docker image
using the instructions in [Building the image](#building-the-image), then afterwards build the
worker image:

```
docker build -t matrixdotorg/synapse:workers -f docker/Dockerfile-workers .
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
```

To start a container, use the following:

```
docker run -d --name synapse \
--mount type=volume,src=synapse-data,dst=/data \
-p 8008:8080 \
-e SYNAPSE_SERVER_NAME=my.matrix.host \
-e SYNAPSE_REPORT_STATS=yes \
-e SYNAPSE_WORKERS=synchrotron,media_repository,user_dir \
matrixdotorg/synapse:workers
```

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.

Otherwise, `SYNAPSE_WORKERS` can be set to `*` to use all possible workers, or either left
empty or unset to spawn no workers. The container is configured to use redis-based worker mode.

Note that currently only one instance of a worker can be spun up at once, but this may
improve in the future.
2 changes: 1 addition & 1 deletion docker/conf/homeserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ listeners:
compress: false
{% endif %}

- port: 8008
- port: {{ SYNAPSE_PORT or 8008 }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we making this configurable?

Copy link
Member Author

@anoadragon453 anoadragon453 Feb 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that the reverse proxy can listen on 8008 and route traffic instead. Complement will only contact the homeserver on 8008/8448 (and making it configurable on Complement's end has been rejected).

I can place a comment down if you'd like?

tls: false
bind_addresses: ['::']
type: http
Expand Down
24 changes: 24 additions & 0 deletions docker/conf/worker.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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_extra_conf }}
Loading