Compare commits
9 Commits
anoa/testb
...
mv/synapse
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f19f47b44b | ||
|
|
9115c47dc3 | ||
|
|
ce591bf75b | ||
|
|
1acb2d9ee1 | ||
|
|
f73e9db981 | ||
|
|
cbe335d2f0 | ||
|
|
ee138d87db | ||
|
|
dfd5e8079b | ||
|
|
80db995e33 |
@@ -5,11 +5,13 @@ FROM matrixdotorg/synapse
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y supervisor redis nginx
|
||||
|
||||
RUN rm /etc/nginx/sites-enabled/default
|
||||
|
||||
# Copy the worker process and log configuration files
|
||||
COPY ./docker/workers /conf/workers/
|
||||
COPY ./docker/worker.yaml.j2 /conf/worker.yaml.j2
|
||||
|
||||
# Expose nginx listener port
|
||||
EXPOSE 8008/tcp
|
||||
EXPOSE 8080/tcp
|
||||
|
||||
# Volume for user-editable config files, logs etc.
|
||||
VOLUME ["/data"]
|
||||
|
||||
31
docker/Dockerfile-workers-complement
Normal file
31
docker/Dockerfile-workers-complement
Normal file
@@ -0,0 +1,31 @@
|
||||
# Inherit from the workers Synapse docker image
|
||||
FROM matrixdotorg/synapse:workers
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y postgresql
|
||||
|
||||
RUN pg_ctlcluster 11 main start && su postgres -c "echo \
|
||||
\"ALTER USER postgres PASSWORD 'somesecret'; \
|
||||
CREATE DATABASE synapse \
|
||||
ENCODING 'UTF8' \
|
||||
LC_COLLATE='C' \
|
||||
LC_CTYPE='C' \
|
||||
template=template0;\" | psql" && pg_ctlcluster 11 main stop
|
||||
|
||||
WORKDIR /root
|
||||
|
||||
RUN curl -OL "https://github.com/caddyserver/caddy/releases/download/v2.3.0/caddy_2.3.0_linux_amd64.tar.gz" && \
|
||||
tar xzf caddy_2.3.0_linux_amd64.tar.gz && rm caddy_2.3.0_linux_amd64.tar.gz
|
||||
|
||||
COPY ./docker/caddy.complement.json /root/caddy.json
|
||||
|
||||
EXPOSE 8008 8448
|
||||
|
||||
ENTRYPOINT sed -i "s/{{ server_name }}/${SERVER_NAME}/g" /root/caddy.json && \
|
||||
pg_ctlcluster 11 main start > /dev/null && \
|
||||
/root/caddy start --config /root/caddy.json > /dev/null && \
|
||||
SYNAPSE_SERVER_NAME=${SERVER_NAME} \
|
||||
SYNAPSE_REPORT_STATS=no \
|
||||
POSTGRES_PASSWORD=somesecret POSTGRES_USER=postgres POSTGRES_HOST=localhost \
|
||||
SYNAPSE_WORKERS=synchrotron \
|
||||
/configure_workers_and_start.py
|
||||
@@ -1,35 +0,0 @@
|
||||
# This dockerfile builds on top of Dockerfile-worker and includes a built-in postgres instance.
|
||||
# It is intended to be used for Complement testing
|
||||
|
||||
FROM matrixdotorg/synapse:workers
|
||||
|
||||
# Install postgres
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y postgres
|
||||
|
||||
# Create required databases in postgres
|
||||
|
||||
# Create a user without a password
|
||||
RUN sudo -u postgres createuser -w synapse_user
|
||||
|
||||
# Then set their password
|
||||
RUN sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'somesecret';"
|
||||
|
||||
# Create the synapse database
|
||||
RUN sudo -u postgres psql -c "CREATE DATABASE synapse \
|
||||
ENCODING 'UTF8' \
|
||||
LC_COLLATE='C' \
|
||||
LC_CTYPE='C' \
|
||||
template=template0 \
|
||||
OWNER synapse_user;"
|
||||
|
||||
# Modify Synapse's database config to point to the local postgres
|
||||
COPY ./docker/synapse_use_local_postgres.py /synapse_use_local_postgres.py
|
||||
RUN /synapse_use_local_postgres.py
|
||||
|
||||
VOLUME ["/data"]
|
||||
|
||||
EXPOSE 8008/tcp 8009/tcp 8448/tcp
|
||||
|
||||
# Start supervisord
|
||||
CMD ["/usr/bin/supervisord"]
|
||||
76
docker/caddy.complement.json
Normal file
76
docker/caddy.complement.json
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":8448"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"match": [
|
||||
{
|
||||
"host": [
|
||||
"{{ server_name }}"
|
||||
]
|
||||
}
|
||||
],
|
||||
"handle": [
|
||||
{
|
||||
"handler": "subroute",
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "reverse_proxy",
|
||||
"upstreams": [
|
||||
{
|
||||
"dial": "localhost:80"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"terminal": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"tls": {
|
||||
"automation": {
|
||||
"policies": [
|
||||
{
|
||||
"subjects": [
|
||||
"{{ server_name }}"
|
||||
],
|
||||
"issuers": [
|
||||
{
|
||||
"module": "internal"
|
||||
}
|
||||
],
|
||||
"on_demand": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"pki": {
|
||||
"certificate_authorities": {
|
||||
"local": {
|
||||
"name": "Complement CA",
|
||||
"root": {
|
||||
"certificate": "/ca/ca.crt",
|
||||
"private_key": "/ca/ca.key"
|
||||
},
|
||||
"intermediate": {
|
||||
"certificate": "/ca/ca.crt",
|
||||
"private_key": "/ca/ca.key"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ listeners:
|
||||
tls: false
|
||||
bind_addresses: ['::']
|
||||
type: http
|
||||
x_forwarded: false
|
||||
x_forwarded: true
|
||||
|
||||
resources:
|
||||
- names: [client]
|
||||
@@ -51,15 +51,6 @@ listeners:
|
||||
- names: [federation]
|
||||
compress: false
|
||||
|
||||
{% if SYNAPSE_WORKERS %}
|
||||
# The HTTP replication port
|
||||
- port: 9093
|
||||
bind_address: '127.0.0.1'
|
||||
type: http
|
||||
resources:
|
||||
- names: [replication]
|
||||
{% endif %}
|
||||
|
||||
## Database ##
|
||||
|
||||
{% if POSTGRES_PASSWORD %}
|
||||
|
||||
@@ -21,7 +21,94 @@ import os
|
||||
import sys
|
||||
import subprocess
|
||||
import jinja2
|
||||
import yaml
|
||||
|
||||
DEFAULT_LISTENER_RESOURCES = ["client", "federation"]
|
||||
|
||||
WORKERS_CONFIG = {
|
||||
"pusher": {
|
||||
"app": "synapse.app.pusher",
|
||||
"listener_resources": [],
|
||||
"endpoint_patterns": [],
|
||||
"shared_extra_conf": "start_pushers: false"
|
||||
},
|
||||
"user_dir": {
|
||||
"app": "synapse.app.user_dir",
|
||||
"listener_resources": DEFAULT_LISTENER_RESOURCES,
|
||||
"endpoint_patterns": [
|
||||
"^/_matrix/client/(api/v1|r0|unstable)/user_directory/search$"
|
||||
],
|
||||
"shared_extra_conf": "update_user_directory: false"
|
||||
},
|
||||
"media_repository": {
|
||||
"app": "synapse.app.media_repository",
|
||||
"listener_resources": ["media"],
|
||||
"endpoint_patterns": [
|
||||
"^/_synapse/admin/v1/purge_media_cache$",
|
||||
"^/_synapse/admin/v1/room/.*/media.*$",
|
||||
"^/_synapse/admin/v1/user/.*/media.*$",
|
||||
"^/_synapse/admin/v1/media/.*$",
|
||||
"^/_synapse/admin/v1/quarantine_media/.*$",
|
||||
],
|
||||
"shared_extra_conf": "enable_media_repo: false"
|
||||
},
|
||||
"appservice": {
|
||||
"app": "synapse.app.appservice",
|
||||
"listener_resources": [],
|
||||
"endpoint_patterns": [],
|
||||
"shared_extra_conf": "notify_appservices: false"
|
||||
},
|
||||
"federation_sender": {
|
||||
"app": "synapse.app.federation_sender",
|
||||
"listener_resources": [],
|
||||
"endpoint_patterns": [],
|
||||
"shared_extra_conf": "send_federation: false"
|
||||
},
|
||||
"synchrotron": {
|
||||
"app": "synapse.app.generic_worker",
|
||||
"listener_resources": DEFAULT_LISTENER_RESOURCES,
|
||||
"endpoint_patterns": [
|
||||
"^/_matrix/client/(v2_alpha|r0)/sync$",
|
||||
"^/_matrix/client/(api/v1|v2_alpha|r0)/events$",
|
||||
"^/_matrix/client/(api/v1|r0)/initialSync$",
|
||||
"^/_matrix/client/(api/v1|r0)/rooms/[^/]+/initialSync$",
|
||||
],
|
||||
"shared_extra_conf": ""
|
||||
},
|
||||
"federation_reader": {
|
||||
"app": "synapse.app.generic_worker",
|
||||
"listener_resources": DEFAULT_LISTENER_RESOURCES,
|
||||
"endpoint_patterns": [
|
||||
"^/_matrix/federation/(v1|v2)/event/",
|
||||
"^/_matrix/federation/(v1|v2)/state/",
|
||||
"^/_matrix/federation/(v1|v2)/state_ids/",
|
||||
"^/_matrix/federation/(v1|v2)/backfill/",
|
||||
"^/_matrix/federation/(v1|v2)/get_missing_events/",
|
||||
"^/_matrix/federation/(v1|v2)/publicRooms",
|
||||
"^/_matrix/federation/(v1|v2)/query/",
|
||||
"^/_matrix/federation/(v1|v2)/make_join/",
|
||||
"^/_matrix/federation/(v1|v2)/make_leave/",
|
||||
"^/_matrix/federation/(v1|v2)/send_join/",
|
||||
"^/_matrix/federation/(v1|v2)/send_leave/",
|
||||
"^/_matrix/federation/(v1|v2)/invite/",
|
||||
"^/_matrix/federation/(v1|v2)/query_auth/",
|
||||
"^/_matrix/federation/(v1|v2)/event_auth/",
|
||||
"^/_matrix/federation/(v1|v2)/exchange_third_party_invite/",
|
||||
"^/_matrix/federation/(v1|v2)/user/devices/",
|
||||
"^/_matrix/federation/(v1|v2)/get_groups_publicised$",
|
||||
"^/_matrix/key/v2/query",
|
||||
],
|
||||
"shared_extra_conf": ""
|
||||
},
|
||||
"federation_inbound": {
|
||||
"app": "synapse.app.generic_worker",
|
||||
"listener_resources": DEFAULT_LISTENER_RESOURCES,
|
||||
"endpoint_patterns": [
|
||||
"/_matrix/federation/(v1|v2)/send/",
|
||||
],
|
||||
"shared_extra_conf": ""
|
||||
},
|
||||
}
|
||||
|
||||
# Utility functions
|
||||
def log(txt):
|
||||
@@ -44,6 +131,7 @@ def convert(src, dst, environ):
|
||||
with open(src) as infile:
|
||||
template = infile.read()
|
||||
rendered = jinja2.Template(template, autoescape=True).render(**environ)
|
||||
print(rendered)
|
||||
with open(dst, "w") as outfile:
|
||||
outfile.write(rendered)
|
||||
|
||||
@@ -56,7 +144,7 @@ def generate_base_homeserver_config():
|
||||
"""
|
||||
# start.py already does this for us, so just call that.
|
||||
# note that this script is copied in in the official, monolith dockerfile
|
||||
subprocess.check_output(["/usr/local/bin/python", "/start.py", "generate"])
|
||||
subprocess.check_output(["/usr/local/bin/python", "/start.py", "migrate_config"])
|
||||
|
||||
|
||||
def generate_worker_files(environ, config_path: str, data_dir: str):
|
||||
@@ -74,14 +162,33 @@ def generate_worker_files(environ, config_path: str, data_dir: str):
|
||||
|
||||
# The contents of a Synapse config file that will be added alongside the generated
|
||||
# config when running the main Synapse process.
|
||||
# It is intended mainly for disabling functionality when certain workers are spun up.
|
||||
homeserver_config = """
|
||||
# It is intended mainly for disabling functionality when certain workers are spun up,
|
||||
# and add the replication listener
|
||||
|
||||
# first read the original config file to take listeners config and add the replication one
|
||||
listeners = [{
|
||||
"port": 9093,
|
||||
"bind_address": "127.0.0.1",
|
||||
"type": "http",
|
||||
"resources":[{
|
||||
"names": ["replication"]
|
||||
}]
|
||||
}]
|
||||
with open(config_path) as file_stream:
|
||||
original_config = yaml.safe_load(file_stream)
|
||||
original_listeners = original_config.get("listeners")
|
||||
if original_listeners:
|
||||
listeners += original_listeners
|
||||
|
||||
homeserver_config = yaml.dump({"listeners": listeners})
|
||||
|
||||
homeserver_config += """
|
||||
redis:
|
||||
enabled: true
|
||||
|
||||
# TODO: remove before prod
|
||||
suppress_key_server_warning: true
|
||||
"""
|
||||
"""
|
||||
|
||||
# The supervisord config
|
||||
supervisord_config = """
|
||||
@@ -90,7 +197,7 @@ nodaemon=true
|
||||
|
||||
[program:nginx]
|
||||
command=/usr/sbin/nginx -g "daemon off;"
|
||||
priority=900
|
||||
priority=500
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
@@ -102,7 +209,7 @@ autorestart=true
|
||||
command=/usr/local/bin/python -m synapse.app.homeserver \
|
||||
--config-path="%s" \
|
||||
--config-path=/conf/workers/shared.yaml
|
||||
|
||||
priority=1
|
||||
# Log startup failures to supervisord's stdout/err
|
||||
# Regular synapse logs will still go in the configured data directory
|
||||
stdout_logfile=/dev/stdout
|
||||
@@ -112,176 +219,95 @@ stderr_logfile_maxbytes=0
|
||||
autorestart=unexpected
|
||||
exitcodes=0
|
||||
|
||||
""" % (config_path,)
|
||||
""" % (config_path,)
|
||||
|
||||
# An nginx site config. Will live in /etc/nginx/conf.d
|
||||
nginx_config_template_header = """
|
||||
server {
|
||||
# Listen on Synapse's default HTTP port number
|
||||
listen 8008;
|
||||
listen [::]:8008;
|
||||
listen 8080;
|
||||
listen [::]:8080;
|
||||
|
||||
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;
|
||||
"""
|
||||
nginx_config_body = "" # to modify below
|
||||
nginx_config_template_end = """
|
||||
# Send all other traffic to the main process
|
||||
location ~* ^(\/_matrix|\/_synapse) {
|
||||
proxy_pass http://localhost:18008;
|
||||
proxy_pass http://localhost:8008;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
|
||||
# TODO: Can we move this to the default nginx.conf so all locations are
|
||||
# affected?
|
||||
#
|
||||
# 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 50M;
|
||||
}
|
||||
}
|
||||
"""
|
||||
"""
|
||||
|
||||
# Read desired worker configuration from environment
|
||||
if "SYNAPSE_WORKERS" not in environ:
|
||||
error("Environment variable 'SYNAPSE_WORKERS' is mandatory.")
|
||||
worker_types = []
|
||||
else:
|
||||
worker_types = environ.get("SYNAPSE_WORKERS")
|
||||
worker_types = worker_types.split(",")
|
||||
|
||||
worker_types = environ.get("SYNAPSE_WORKERS")
|
||||
worker_types = worker_types.split(",")
|
||||
os.mkdir("/conf/workers")
|
||||
|
||||
worker_port = 18009
|
||||
for worker_type in worker_types:
|
||||
worker_type = worker_type.strip()
|
||||
|
||||
if worker_type == "pusher":
|
||||
# Disable push handling from the main process
|
||||
homeserver_config += """
|
||||
start_pushers: false
|
||||
"""
|
||||
worker_config = WORKERS_CONFIG.get(worker_type)
|
||||
if worker_config:
|
||||
worker_config = worker_config.copy()
|
||||
else:
|
||||
log(worker_type + " is a wrong worker type ! It will be ignored")
|
||||
continue
|
||||
|
||||
# this is not hardcoded bc we want to be able to have several workers
|
||||
# of each type ultimately (not supported for now)
|
||||
worker_name = worker_type
|
||||
worker_config.update({"name": worker_name})
|
||||
|
||||
worker_config.update({"port": worker_port})
|
||||
worker_config.update({"config_path": config_path})
|
||||
|
||||
homeserver_config += worker_config['shared_extra_conf'] + "\n"
|
||||
|
||||
# Enable the pusher worker in supervisord
|
||||
supervisord_config += """
|
||||
[program:synapse_pusher]
|
||||
command=/usr/local/bin/python -m synapse.app.pusher \
|
||||
--config-path="%s" \
|
||||
supervisord_config += """
|
||||
[program:synapse_{name}]
|
||||
command=/usr/local/bin/python -m {app} \
|
||||
--config-path="{config_path}" \
|
||||
--config-path=/conf/workers/shared.yaml \
|
||||
--config-path=/conf/workers/pusher.yaml
|
||||
--config-path=/conf/workers/{name}.yaml
|
||||
autorestart=unexpected
|
||||
priority=500
|
||||
exitcodes=0
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
""" % (config_path,)
|
||||
stderr_logfile_maxbytes=0""".format_map(worker_config)
|
||||
|
||||
# This worker does not handle any REST endpoints
|
||||
|
||||
elif worker_type == "appservice":
|
||||
# Disable appservice traffic sending from the main process
|
||||
homeserver_config += """
|
||||
notify_appservices: false
|
||||
"""
|
||||
|
||||
# Enable the pusher worker in supervisord
|
||||
supervisord_config += """
|
||||
[program:synapse_appservice]
|
||||
command=/usr/local/bin/python -m synapse.app.appservice \
|
||||
--config-path="%s" \
|
||||
--config-path=/conf/workers/shared.yaml \
|
||||
--config-path=/conf/workers/appservice.yaml
|
||||
autorestart=unexpected
|
||||
exitcodes=0
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
""" % (config_path,)
|
||||
|
||||
# This worker does not handle any REST endpoints
|
||||
|
||||
elif worker_type == "user_dir":
|
||||
# Disable user directory updates on the main process
|
||||
homeserver_config += """
|
||||
update_user_directory: false
|
||||
"""
|
||||
|
||||
# Enable the user directory worker in supervisord
|
||||
supervisord_config += """
|
||||
[program:synapse_user_dir]
|
||||
command=/usr/local/bin/python -m synapse.app.user_dir \
|
||||
--config-path="%s" \
|
||||
--config-path=/conf/workers/shared.yaml \
|
||||
--config-path=/conf/workers/user_dir.yaml
|
||||
autorestart=unexpected
|
||||
exitcodes=0
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
""" % (config_path,)
|
||||
|
||||
# Route user directory requests to this worker
|
||||
for pattern in worker_config['endpoint_patterns']:
|
||||
nginx_config_body += """
|
||||
location ~* ^/_matrix/client/(api/v1|r0|unstable)/user_directory/search$ {
|
||||
proxy_pass http://localhost:8010;
|
||||
location ~* %s {
|
||||
proxy_pass http://localhost:%s;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
}
|
||||
"""
|
||||
""" % (pattern, worker_port)
|
||||
|
||||
elif worker_type == "federation_sender":
|
||||
# Disable user directory updates on the main process
|
||||
homeserver_config += """
|
||||
send_federation: False
|
||||
"""
|
||||
convert("/conf/worker.yaml.j2", "/conf/workers/{name}.yaml".format(name=worker_name), worker_config)
|
||||
|
||||
# Enable the user directory worker in supervisord
|
||||
supervisord_config += """
|
||||
[program:synapse_user_dir]
|
||||
command=/usr/local/bin/python -m synapse.app.user_dir \
|
||||
--config-path="%s" \
|
||||
--config-path=/conf/workers/shared.yaml \
|
||||
--config-path=/conf/workers/user_dir.yaml
|
||||
autorestart=unexpected
|
||||
exitcodes=0
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
""" % (config_path,)
|
||||
worker_port += 1
|
||||
|
||||
# This worker does not handle any REST endpoints
|
||||
|
||||
elif worker_type == "media_repository":
|
||||
# Disable user directory updates on the main process
|
||||
homeserver_config += """
|
||||
update_user_directory: false
|
||||
"""
|
||||
|
||||
# Enable the user directory worker in supervisord
|
||||
supervisord_config += """
|
||||
[program:synapse_user_dir]
|
||||
command=/usr/local/bin/python -m synapse.app.user_dir \
|
||||
--config-path="%s" \
|
||||
--config-path=/conf/workers/shared.yaml \
|
||||
--config-path=/conf/workers/user_dir.yaml
|
||||
autorestart=unexpected
|
||||
exitcodes=0
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
""" % (config_path,)
|
||||
|
||||
# Route user directory requests to this worker
|
||||
nginx_config_body += """
|
||||
location ~* (^/_matrix/media/.*$|^/_synapse/admin/v1/(purge_media_cache$|(room|user)/.*/media.*$|media/.*$|quarantine_media/.*$) {
|
||||
proxy_pass http://localhost:8010;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
}
|
||||
"""
|
||||
|
||||
# Write out the config files
|
||||
# Write out the config files. We use append mode for each in case the
|
||||
# files may have already been written to by others.
|
||||
|
||||
# Shared homeserver config
|
||||
print(homeserver_config)
|
||||
with open("/conf/workers/shared.yaml", "w") as f:
|
||||
with open("/conf/workers/shared.yaml", "a") as f:
|
||||
f.write(homeserver_config)
|
||||
|
||||
# Nginx config
|
||||
@@ -289,7 +315,7 @@ stderr_logfile_maxbytes=0
|
||||
print(nginx_config_template_header)
|
||||
print(nginx_config_body)
|
||||
print(nginx_config_template_end)
|
||||
with open("/etc/nginx/conf.d/matrix-synapse.conf", "w") as f:
|
||||
with open("/etc/nginx/conf.d/matrix-synapse.conf", "a") as f:
|
||||
f.write(nginx_config_template_header)
|
||||
f.write(nginx_config_body)
|
||||
f.write(nginx_config_template_end)
|
||||
@@ -297,20 +323,9 @@ stderr_logfile_maxbytes=0
|
||||
# Supervisord config
|
||||
print()
|
||||
print(supervisord_config)
|
||||
with open("/etc/supervisor/conf.d/supervisord.conf", "w") as f:
|
||||
with open("/etc/supervisor/conf.d/supervisord.conf", "a") as f:
|
||||
f.write(supervisord_config)
|
||||
|
||||
# Generate worker log config files from the templates.
|
||||
# The templates are mainly there so that we can inject some environment variable
|
||||
# values into them.
|
||||
log_config_template_dir = "/conf/workers/log_config_templates/"
|
||||
log_config_dir = "/conf/workers/"
|
||||
for log_config_filename in os.listdir(log_config_template_dir):
|
||||
template_path = log_config_template_dir + log_config_filename
|
||||
out_path = log_config_dir + log_config_filename
|
||||
|
||||
convert(template_path, out_path, environ)
|
||||
|
||||
# Ensure the logging directory exists
|
||||
log_dir = data_dir + "/logs"
|
||||
if not os.path.exists(log_dir):
|
||||
@@ -330,6 +345,10 @@ def main(args, environ):
|
||||
config_path = environ.get("SYNAPSE_CONFIG_PATH", config_dir + "/homeserver.yaml")
|
||||
data_dir = environ.get("SYNAPSE_DATA_DIR", "/data")
|
||||
|
||||
# override SYNAPSE_NO_TLS, we don't support TLS in worker mode,
|
||||
# this needs to be handled by a frontend proxy
|
||||
environ["SYNAPSE_NO_TLS"] = "yes"
|
||||
|
||||
# Generate the base homeserver config if one does not yet exist
|
||||
if not os.path.exists(config_path):
|
||||
log("Generating base homeserver config")
|
||||
|
||||
@@ -134,6 +134,7 @@ def run_generate_config(environ, ownership):
|
||||
|
||||
Never returns.
|
||||
"""
|
||||
print("running generate config")
|
||||
for v in ("SYNAPSE_SERVER_NAME", "SYNAPSE_REPORT_STATS"):
|
||||
if v not in environ:
|
||||
error("Environment variable '%s' is mandatory in `generate` mode." % (v,))
|
||||
@@ -149,6 +150,8 @@ def run_generate_config(environ, ownership):
|
||||
log("Creating log config %s" % (log_config_file,))
|
||||
convert("/conf/log.config", log_config_file, environ)
|
||||
|
||||
print("Generating config at", config_path, "Config dir:", config_dir)
|
||||
|
||||
args = [
|
||||
"python",
|
||||
"-m",
|
||||
@@ -178,6 +181,7 @@ def run_generate_config(environ, ownership):
|
||||
os.execv("/usr/local/bin/python", args)
|
||||
|
||||
def main(args, environ):
|
||||
print("bla")
|
||||
mode = args[1] if len(args) > 1 else "run"
|
||||
desired_uid = int(environ.get("UID", "991"))
|
||||
desired_gid = int(environ.get("GID", "991"))
|
||||
|
||||
15
docker/worker.yaml.j2
Normal file
15
docker/worker.yaml.j2
Normal file
@@ -0,0 +1,15 @@
|
||||
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 }}
|
||||
resources:
|
||||
- names:
|
||||
{%- for resource in listener_resources %}
|
||||
- {{ resource }}
|
||||
{%- endfor %}
|
||||
@@ -1,30 +0,0 @@
|
||||
version: 1
|
||||
|
||||
formatters:
|
||||
precise:
|
||||
format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
|
||||
|
||||
handlers:
|
||||
file:
|
||||
class: logging.handlers.TimedRotatingFileHandler
|
||||
formatter: precise
|
||||
filename: "{{ SYNAPSE_DATA_DIR or '/data' }}/logs/pusher1.log"
|
||||
when: midnight
|
||||
backupCount: 3 # Does not include the current log file.
|
||||
encoding: utf8
|
||||
|
||||
console:
|
||||
class: logging.StreamHandler
|
||||
formatter: precise
|
||||
|
||||
loggers:
|
||||
synapse.storage.SQL:
|
||||
# beware: increasing this to DEBUG will make synapse log sensitive
|
||||
# information such as access tokens.
|
||||
level: INFO
|
||||
|
||||
root:
|
||||
level: {{ SYNAPSE_LOG_LEVEL or "INFO" }}
|
||||
handlers: [console]
|
||||
|
||||
disable_existing_loggers: false
|
||||
@@ -1,30 +0,0 @@
|
||||
version: 1
|
||||
|
||||
formatters:
|
||||
precise:
|
||||
format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
|
||||
|
||||
handlers:
|
||||
file:
|
||||
class: logging.handlers.TimedRotatingFileHandler
|
||||
formatter: precise
|
||||
filename: "{{ SYNAPSE_DATA_DIR or '/data' }}/logs/pusher1.log"
|
||||
when: midnight
|
||||
backupCount: 3 # Does not include the current log file.
|
||||
encoding: utf8
|
||||
|
||||
console:
|
||||
class: logging.StreamHandler
|
||||
formatter: precise
|
||||
|
||||
loggers:
|
||||
synapse.storage.SQL:
|
||||
# beware: increasing this to DEBUG will make synapse log sensitive
|
||||
# information such as access tokens.
|
||||
level: INFO
|
||||
|
||||
root:
|
||||
level: {{ SYNAPSE_LOG_LEVEL or "INFO" }}
|
||||
handlers: [console]
|
||||
|
||||
disable_existing_loggers: false
|
||||
@@ -1,13 +0,0 @@
|
||||
worker_app: synapse.app.pusher
|
||||
worker_name: pusher
|
||||
|
||||
# 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: 8083
|
||||
resources: []
|
||||
|
||||
worker_log_config: /conf/workers/pusher_log.yaml
|
||||
@@ -1,13 +0,0 @@
|
||||
worker_app: synapse.app.user_dir
|
||||
worker_name: user_dir
|
||||
|
||||
# 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: 8084
|
||||
resources: []
|
||||
|
||||
worker_log_config: /conf/workers/user_dir_log.yaml
|
||||
30
scripts-dev/complement-workers.sh
Executable file
30
scripts-dev/complement-workers.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#! /bin/bash -eu
|
||||
# This script is designed for developers who want to test their code
|
||||
# against Complement.
|
||||
#
|
||||
# It creates a Complement-ready worker-enabled Synapse docker image from
|
||||
# the local checkout and runs Complement tests against it.
|
||||
#
|
||||
# This script assumes that it is located in the scripts-dev folder of a
|
||||
# Synapse checkout, and that Complement exists at ../../complement
|
||||
# In my case, I have /home/user/code/complement and /home/user/code/synapse.
|
||||
COMPLEMENT_DIR="/home/user/code/complement"
|
||||
|
||||
cd "$(dirname $0)/.."
|
||||
|
||||
# Build the Synapse image from the local checkout
|
||||
docker build -t matrixdotorg/synapse:latest -f docker/Dockerfile .
|
||||
|
||||
# Build the base Synapse worker image
|
||||
docker build -t matrixdotorg/synapse:workers -f docker/Dockerfile-workers .
|
||||
|
||||
cd "$COMPLEMENT_DIR"
|
||||
|
||||
# Build the Complement Synapse worker image
|
||||
docker build -t matrixdotorg/complement-synapse:workers -f dockerfiles/SynapseWorkers.Dockerfile dockerfiles
|
||||
|
||||
# Run the tests on the resulting image!
|
||||
COMPLEMENT_VERSION_CHECK_ITERATIONS=300 COMPLEMENT_DEBUG=1 COMPLEMENT_BASE_IMAGE=matrixdotorg/complement-synapse:workers go test -v -count=1 -tags="synapse_blacklist" -failfast ./tests
|
||||
#COMPLEMENT_VERSION_CHECK_ITERATIONS=100 COMPLEMENT_DEBUG=1 COMPLEMENT_BASE_IMAGE=complement-synapse go test -v -count=1 -parallel=1 ./tests/
|
||||
|
||||
#COMPLEMENT_VERSION_CHECK_ITERATIONS=100 COMPLEMENT_BASE_IMAGE=complement-synapse go test ./tests
|
||||
Reference in New Issue
Block a user