version: "3.8"

# Matrix/Conduit Homeserver Stack
# Deploy: docker compose up -d
# Pre-reqs: Domain with DNS A record → host IP, ports 443/8448 open

services:
  conduit:
    image: matrixconduit/matrix-conduit:latest
    container_name: conduit-homeserver
    restart: unless-stopped
    ports:
      - "6167:6167"  # Internal HTTP (behind reverse proxy)
    volumes:
      - ./conduit.toml:/etc/conduit.toml:ro
      - conduit_data:/var/lib/matrix-conduit
    environment:
      - CONDUIT_CONFIG=/etc/conduit.toml
    networks:
      - matrix
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:6167/_matrix/client/versions"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  # Optional: PostgreSQL for scale (comment out for SQLite default)
  # postgres:
  #   image: postgres:15-alpine
  #   container_name: conduit-postgres
  #   restart: unless-stopped
  #   environment:
  #     POSTGRES_USER: conduit
  #     POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
  #     POSTGRES_DB: conduit
  #   volumes:
  #     - postgres_data:/var/lib/postgresql/data
  #   networks:
  #     - matrix

  # Optional: Element web client (self-hosted)
  element:
    image: vectorim/element-web:latest
    container_name: element-web
    restart: unless-stopped
    ports:
      - "8080:80"  # Expose on 8080, reverse proxy to 443
    volumes:
      - ./element-config.json:/app/config.json:ro
    networks:
      - matrix

volumes:
  conduit_data:
  # postgres_data:

networks:
  matrix:
    driver: bridge
