services:
  synapse:
    image: matrixdotorg/synapse:latest
    container_name: synapse
    restart: unless-stopped
    volumes:
      - ${SYNAPSE_DATA}:/data
      - /etc/localtime:/etc/localtime:ro
    environment:
      - SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
    ports:
      - "127.0.0.1:8008:8008"
    depends_on:
      - db
    networks:
      - matrix
      - frontend

  db:
    image: postgres:16-alpine
    container_name: synapse-db
    restart: unless-stopped
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=C --lc-ctype=C
    volumes:
      - ${POSTGRES_DATA}:/var/lib/postgresql/data
      - /etc/localtime:/etc/localtime:ro
    networks:
      - matrix

  lk-jwt-service:
    image: ghcr.io/element-hq/lk-jwt-service:latest
    container_name: lk-jwt-service
    restart: unless-stopped
    ports:
      - "127.0.0.1:8009:8080"
    environment:
      - LIVEKIT_JWT_BIND=:8080
      - LIVEKIT_URL=wss://lk.alogins.net
      - LIVEKIT_KEY=${LIVEKIT_KEY}
      - LIVEKIT_SECRET=${LIVEKIT_SECRET}
      - LIVEKIT_FULL_ACCESS_HOMESERVERS=mtx.alogins.net
    extra_hosts:
      - "mtx.alogins.net:host-gateway"
      - "lk.alogins.net:host-gateway"

  livekit:
    image: livekit/livekit-server:latest
    container_name: livekit
    restart: unless-stopped
    network_mode: host
    volumes:
      - ./livekit/livekit.yaml:/etc/livekit.yaml:ro
    command: --config /etc/livekit.yaml

  coturn:
    image: coturn/coturn:latest
    container_name: coturn
    restart: unless-stopped
    network_mode: host
    volumes:
      - ./coturn/turnserver.conf:/etc/coturn/turnserver.conf:ro
      - /etc/localtime:/etc/localtime:ro

networks:
  matrix:
    driver: bridge
    internal: true
  frontend:
    driver: bridge
