version: "2.2"

services:

  # Datenbank Dump vor Upgrade (im Container)
  # pg_dump --clean --create -d synapse -U synapse > /var/lib/postgresql/data/dump.sql

  # Datenbank einlesen nach Upgrade (im Container)
  # psql -U synapse -d synapse < /var/lib/postgresql/data/dump.sql

  db:

    image: postgres:13.6
    restart: always
    volumes:
      - /srv/matrix/db:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: synapse
      POSTGRES_USER: synapse
      POSTGRES_PASSWORD: "{{ postgres_user_pass }}"
      POSTGRES_INITDB_ARGS: --encoding=UTF-8 --lc-collate=C --lc-ctype=C
    networks:
      - default

  synapse:

    image: matrixdotorg/synapse:v1.78.0
    restart: always
    cpu_count: "1"
    cpuset: "0"
    depends_on:
      - db
      - ma1sd
    volumes:
      - /srv/matrix/synapse-data/:/data
      # Python version can be found in the dockerfile: https://github.com/matrix-org/synapse/blob/develop/docker/Dockerfile check for tag to get the correct version
      - /srv/matrix/rest_auth_provider.py:/usr/local/lib/python3.11/site-packages/rest_auth_provider.py
    environment:
      SYNAPSE_CONFIG_PATH: "/data/homeserver.yaml"
      TZ: "Europe/Berlin"
    labels:
      - traefik.enable=true
      - traefik.http.routers.{{ servicename }}.rule=Host(`{{ domain }}`)
      - traefik.http.routers.{{ servicename }}.entrypoints=websecure
      - traefik.http.routers.{{ servicename }}.service={{ servicename }}
      - traefik.http.services.{{ servicename }}.loadbalancer.server.port=8008
      - traefik.http.routers.matrix_federation.rule=Host(`{{ domain }}`)
      - traefik.http.routers.matrix_federation.entrypoints=matrix_federation
      - traefik.http.routers.matrix_federation.service=matrix_federation
      - traefik.http.services.matrix_federation.loadbalancer.server.port=8448
    networks:
      - default
      - web

  ma1sd:

    image: ma1uta/ma1sd:2.5.0
    restart: always
    volumes:
      - /srv/matrix/ma1sd-config/:/etc/ma1sd
      - /srv/matrix/ma1sd-data/:/var/ma1sd
    labels:
      - traefik.enable=true
      - traefik.http.routers.{{ servicename }}-ma1sd.rule=((Host(`{{ domain }}`) && PathPrefix(`/_matrix/client/r0/login`)) || (Host(`{{ domain }}`) && PathPrefix(`/_matrix/identity`)))
      - traefik.http.routers.{{ servicename }}-ma1sd.entrypoints=websecure
      - traefik.http.services.{{ servicename }}-ma1sd.loadbalancer.server.port=8090
    networks:
      - default
      - web

networks:
  web:
    external: true
