services:
  matrix-synapse:
    image: docker.io/matrixdotorg/synapse:latest
    container_name: matrix-synapse
    restart: unless-stopped
    volumes:
      - ./data:/data
    environment:
      - SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
    depends_on:
      - matrix-db
    deploy:
      resources:
        limits:
          cpus: '1.0'
          memory: 512M
        reservations:
          memory: 256M
    networks:
      - matrix_network

  matrix-db:
    image: docker.io/postgres:14-alpine
    container_name: matrix-db
    restart: unless-stopped
    environment:
      - POSTGRES_USER=${MATRIX_DB_USER:?}
      - POSTGRES_PASSWORD=${MATRIX_DB_PASSWORD:?}
      - POSTGRES_DB=${MATRIX_DB:?}
      - POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=C --lc-ctype=C
    volumes:
      - ./db:/var/lib/postgresql/data
    deploy:
      resources:
        limits:
          cpus: '1.0'
          memory: 512M
        reservations:
          memory: 256M
    networks:
      - matrix_network

  matrix-element:
    image: docker.io/vectorim/element-web:latest
    container_name: matrix-element
    restart: unless-stopped
    environment:
      - ELEMENT_WEB_PORT=${MATRIX_ELEMENT_PORT:?}
    deploy:
      resources:
        limits:
          cpus: '1.0'
          memory: 256M
        reservations:
          memory: 128M
    networks:
      - matrix_network

  synapse-admin:
    container_name: synapse-admin
    hostname: synapse-admin
    image: docker.io/awesometechnologies/synapse-admin:latest
    ports:
      - "8009:80"
    restart: always
    networks:
      - matrix_network
    deploy:
      resources:
        limits:
          cpus: '1.0'
          memory: 256M
        reservations:
          memory: 128M

networks:
  matrix_network:
    name: matrix_network
    driver: bridge
