Skip to content

Commit 5a79929

Browse files
Merge pull request #22 from missingcharacter/matrix
Added matrix element homeserver compose stack
2 parents 5db4a6a + 9127660 commit 5a79929

13 files changed

Lines changed: 309 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# others
132+
*.tar.gz

stacks/synapse/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Synapse home server for matrix
2+
3+
## `/opt/docker` folder structure
4+
5+
```shell
6+
root@server:~# tree -L 4 /opt/docker/
7+
/opt/docker/
8+
└── synapse
9+
├── caddy
10+
│   ├── Caddyfile
11+
│   ├── config
12+
│   └── data
13+
├── postgres
14+
│   ├── data
15+
│   │   └── 18
16+
│   │   └── docker
17+
│   └── runtime.env
18+
└── synapse
19+
├── config
20+
│   ├── chat.yourdomain.tld.log.config
21+
│   ├── chat.yourdomain.tld.signing.key
22+
│   └── homeserver.yaml
23+
└── data
24+
25+
17 directories, 8 files
26+
```
27+
28+
## How to generate keys
29+
30+
Source: [element installation](https://element-hq.github.io/synapse/latest/setup/installation.html)
31+
32+
Before you can start Synapse, you will need to generate a configuration file.
33+
To do this, run (in your virtualenv, as before):
34+
35+
```shell
36+
cd ~/synapse
37+
python -m synapse.app.homeserver \
38+
--server-name chat.yourdomain.tld \
39+
--config-path homeserver.yaml \
40+
--generate-config \
41+
--report-stats=[yes|no]
42+
```
43+
44+
substituting an appropriate value for --server-name and choosing whether or not
45+
to report usage statistics (hostname, Synapse version, uptime, total users,
46+
etc.) to the developers via the --report-stats argument.
47+
48+
This command will generate you a config file that you can then customise, but
49+
it will also generate a set of keys for you.

stacks/synapse/docker-compose.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
services:
3+
caddy:
4+
hostname: caddy
5+
image: docker.io/caddy:2.10.2-alpine
6+
restart: unless-stopped
7+
ports:
8+
- 80:80
9+
- 443:443
10+
- 443:443/udp
11+
- 8008:8008
12+
- 8448:8448
13+
- 8448:8448/udp
14+
volumes:
15+
- /opt/docker/synapse/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
16+
- /opt/docker/synapse/caddy/data:/data
17+
- /opt/docker/synapse/caddy/config:/config
18+
networks:
19+
- internal
20+
postgres:
21+
hostname: postgres
22+
image: docker.io/postgres:18.0-alpine3.22
23+
restart: unless-stopped
24+
environment:
25+
POSTGRES_DB: synapse
26+
POSTGRES_USER: synapse
27+
POSTGRES_INITDB_ARGS: --encoding=UTF-8 --lc-collate=C --lc-ctype=C
28+
env_file:
29+
- /opt/docker/synapse/postgres/runtime.env
30+
# `postgres` container starts as root but switches to user `postgres`
31+
# with `uid` and `gid` number 70
32+
# $ sudo docker run --rm -it --entrypoint bash docker.io/postgres:17.6-alpine3.22
33+
# ae14e6d0f571:/# grep postgres /etc/passwd
34+
# postgres:x:70:70::/var/lib/postgresql:/bin/sh
35+
volumes:
36+
- /opt/docker/synapse/postgres/data/18/docker:/var/lib/postgresql/18/docker
37+
#- /home/ricdros/dump17.sql:/tmp/dump.sql:ro
38+
healthcheck:
39+
test: |
40+
pg_isready -d "$${POSTGRES_DB}" -U "$${POSTGRES_USER}"
41+
start_period: 80s
42+
interval: 30s
43+
timeout: 60s
44+
retries: 5
45+
networks:
46+
- internal
47+
synapse:
48+
hostname: synapse
49+
image: ghcr.io/element-hq/synapse:v1.141.0
50+
restart: unless-stopped
51+
environment:
52+
SYNAPSE_CONFIG_DIR: /config
53+
SYNAPSE_CONFIG_PATH: /config/homeserver.yaml
54+
UID: 991
55+
GID: 991
56+
TZ: UTC
57+
volumes:
58+
- /opt/docker/synapse/synapse/config:/config
59+
- /opt/docker/synapse/synapse/data:/data
60+
depends_on:
61+
postgres:
62+
condition: service_healthy
63+
healthcheck:
64+
test: |
65+
curl -fSs http://localhost:8008/health || exit 1
66+
start_period: 5s
67+
interval: 15s
68+
timeout: 5s
69+
retries: 3
70+
networks:
71+
- internal
72+
matrix-registration-bot:
73+
image: moanos/matrix-registration-bot:latest
74+
environment:
75+
LOGGING_LEVEL: DEBUG
76+
BOT_SERVER: "https://chat.yourdomain.tld"
77+
BOT_USERNAME: "<BOT-USERNAME-HERE>"
78+
API_BASE_URL: "https://chat.yourdomain.tld"
79+
env_file:
80+
- /opt/docker/synapse/matrix-registration-bot/runtime.env
81+
depends_on:
82+
synapse:
83+
condition: service_healthy
84+
networks:
85+
internal:
86+
attachable: true
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
admin off
3+
email you@yourdomain.tld
4+
# acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
5+
}
6+
7+
http://chat.yourdomain.tld {
8+
redir https://chat.yourdomain.tld{uri} permanent
9+
}
10+
11+
https://chat.yourdomain.tld {
12+
reverse_proxy synapse:8008
13+
}
14+
15+
http://chat.yourdomain.tld:8008 {
16+
redir https://chat.yourdomain.tld:8448{uri} permanent
17+
18+
}
19+
20+
https://chat.yourdomain.tld:8448 {
21+
reverse_proxy synapse:8008
22+
}
23+
24+
:9180 {
25+
metrics
26+
}

stacks/synapse/opt/docker/synapse/caddy/config/.gitkeep

Whitespace-only changes.

stacks/synapse/opt/docker/synapse/caddy/data/.gitkeep

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BOT_PASSWORD=YOURBOTPASSWORDHERE # pragma: allowlist secret
2+
API_TOKEN=YOURAPITOKENHERE

stacks/synapse/opt/docker/synapse/postgres/data/18/docker/.gitkeep

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
POSTGRES_PASSWORD=YOURSUPERSECUREPASSWORDHERE # pragma: allowlist secret
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Log configuration for Synapse.
2+
#
3+
# This is a YAML file containing a standard Python logging configuration
4+
# dictionary. See [1] for details on the valid settings.
5+
#
6+
# Synapse also supports structured logging for machine readable logs which can
7+
# be ingested by ELK stacks. See [2] for details.
8+
#
9+
# [1]: https://docs.python.org/3/library/logging.config.html#configuration-dictionary-schema
10+
# [2]: https://element-hq.github.io/synapse/latest/structured_logging.html
11+
12+
version: 1
13+
14+
formatters:
15+
precise:
16+
format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
17+
18+
handlers:
19+
# file:
20+
# class: logging.handlers.TimedRotatingFileHandler
21+
# formatter: precise
22+
# filename: /var/lib/matrix/homeserver.log
23+
# when: midnight
24+
# backupCount: 3 # Does not include the current log file.
25+
# encoding: utf8
26+
27+
# # Default to buffering writes to log file for efficiency.
28+
# # WARNING/ERROR logs will still be flushed immediately, but there will be a
29+
# # delay (of up to `period` seconds, or until the buffer is full with
30+
# # `capacity` messages) before INFO/DEBUG logs get written.
31+
# buffer:
32+
# class: synapse.logging.handlers.PeriodicallyFlushingMemoryHandler
33+
# target: file
34+
35+
# # The capacity is the maximum number of log lines that are buffered
36+
# # before being written to disk. Increasing this will lead to better
37+
# # performance, at the expensive of it taking longer for log lines to
38+
# # be written to disk.
39+
# # This parameter is required.
40+
# capacity: 10
41+
42+
# # Logs with a level at or above the flush level will cause the buffer to
43+
# # be flushed immediately.
44+
# # Default value: 40 (ERROR)
45+
# # Other values: 50 (CRITICAL), 30 (WARNING), 20 (INFO), 10 (DEBUG)
46+
# flushLevel: 30 # Flush immediately for WARNING logs and higher
47+
48+
# # The period of time, in seconds, between forced flushes.
49+
# # Messages will not be delayed for longer than this time.
50+
# # Default value: 5 seconds
51+
# period: 5
52+
53+
# A handler that writes logs to stderr. Unused by default, but can be used
54+
# instead of "buffer" and "file" in the logger handlers.
55+
console:
56+
class: logging.StreamHandler
57+
formatter: precise
58+
59+
loggers:
60+
synapse.storage.SQL:
61+
# beware: increasing this to DEBUG will make synapse log sensitive
62+
# information such as access tokens.
63+
level: WARN
64+
65+
root:
66+
level: WARN
67+
# Write logs to the `buffer` handler, which will buffer them together in memory,
68+
# then write them to a file.
69+
#
70+
# Replace "buffer" with "console" to log to stderr instead.
71+
#
72+
handlers: [console]
73+
74+
disable_existing_loggers: false
75+
# vim:ft=yaml

0 commit comments

Comments
 (0)