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

  # Alternativer weg mit inplace-Upgrade (funktioniert nicht)
  # https://github.com/tianon/docker-postgres-upgrade

  db:

    image: postgres:17
    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:latest
    restart: always
    cpu_count: "1"
    cpuset: "0"
    depends_on:
      - db
    volumes:
      - /srv/matrix/synapse-data/:/data
    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


  purgemediacache:
    
    image: jsonfry/curl-cron:latest 
    restart: always
    depends_on:
      - synapse
    volumes:
      - /srv/matrix/purgemediacache.sh:/curl.sh
    environment:
      CRON_SCHEDULE: "0 7 * * *"
    networks:
      - default


networks:
  web:
    external: true
