version: '3.8'

services:
  conduit:
    image: docker.io/girlbossceo/conduit:v0.8.0
    container_name: matrix-conduit
    restart: unless-stopped
    volumes:
      - ./data:/var/lib/matrix-conduit
    environment:
      - CONDUIT_SERVER_NAME=${CONDUIT_SERVER_NAME}
      - CONDUIT_DATABASE_PATH=/var/lib/matrix-conduit
      - CONDUIT_DATABASE_BACKEND=${CONDUIT_DATABASE_BACKEND:-rocksdb}
      - CONDUIT_PORT=6167
      - CONDUIT_ADDRESS=0.0.0.0
      - CONDUIT_CONFIG=${CONDUIT_CONFIG:-}
      - CONDUIT_ALLOW_REGISTRATION=${CONDUIT_ALLOW_REGISTRATION:-false}
      - CONDUIT_ALLOW_FEDERATION=${CONDUIT_ALLOW_FEDERATION:-true}
      - CONDUIT_ENABLE_METRICS=${CONDUIT_ENABLE_METRICS:-false}
      - RUST_LOG=info
    networks:
      - matrix
    expose:
      - "6167"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:6167/_matrix/client/versions"]
      interval: 30s
      timeout: 10s
      retries: 5

  caddy:
    image: docker.io/caddy:2.7-alpine
    container_name: matrix-caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "8448:8448"  # Federation
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config
    environment:
      - DOMAIN=${DOMAIN}
    depends_on:
      - conduit
    networks:
      - matrix
    cap_add:
      - NET_ADMIN  # For Caddy to bind low ports

networks:
  matrix:
    name: matrix

volumes:
  caddy_data:
  caddy_config:
