services:
  comet:
    container_name: comet
    image: g0ldyy/comet
    restart: unless-stopped
    ports:
      - "8000:8000"
    environment:
      DATABASE_TYPE: ${DATABASE_TYPE:-postgresql}
      DATABASE_URL: ${DATABASE_URL:-comet:comet@postgres:5432/comet}
    env_file:
      - .env
    volumes:
      - comet_data:/data
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8000/health"]
      interval: 5s
      timeout: 5s
      retries: 5
      start_period: 10s
    depends_on:
      postgres:
        condition: service_healthy

  postgres:
    container_name: comet-postgres
    image: postgres:18-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: comet
      POSTGRES_PASSWORD: comet
      POSTGRES_DB: comet
    command:
      - "postgres"
      - "-c"
      - "shared_buffers=128MB"
      - "-c"
      - "effective_cache_size=384MB"
      - "-c"
      - "maintenance_work_mem=64MB"
      - "-c"
      - "checkpoint_completion_target=0.9"
      - "-c"
      - "wal_buffers=8MB"
      - "-c"
      - "random_page_cost=1.1"
      - "-c"
      - "effective_io_concurrency=200"
      - "-c"
      - "work_mem=8MB"
      - "-c"
      - "max_connections=100"
    volumes:
      - postgres_data:/var/lib/postgresql/
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U comet -d comet"]
      interval: 5s
      timeout: 5s
      retries: 5

volumes:
  comet_data:
  postgres_data: