version: "3.8"

services:
  livekit:
    image: livekit/livekit-server:v1.8.2
    ports:
      - "7880:7880"
      - "7881:7881"
      - "7882:7882/udp"
    environment:
      - LIVEKIT_KEYS=${LIVEKIT_API_KEY:-devkey}:${LIVEKIT_API_SECRET:-secret}
    depends_on:
      - redis
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    command: redis-server --requirepass ${REDIS_PASSWORD:-cyberverse_redis_dev}
    restart: unless-stopped
    # No port exposure - internal only

  cyberverse-server:
    build:
      context: ..
      dockerfile: infra/Dockerfile.server
    ports:
      - "8080:8080"
    environment:
      - LIVEKIT_URL=ws://livekit:7880
      - LIVEKIT_API_KEY=${LIVEKIT_API_KEY:-devkey}
      - LIVEKIT_API_SECRET=${LIVEKIT_API_SECRET:-secret}
      - GRPC_INFERENCE_ADDR=cyberverse-inference:50051
      - ZHIHU_APP_ID=${ZHIHU_APP_ID:-}
      - ZHIHU_APP_KEY=${ZHIHU_APP_KEY:-}
      - ZHIHU_REDIRECT_URI=${ZHIHU_REDIRECT_URI:-}
    volumes:
      - ../data:/app/data
    depends_on:
      - livekit
      - cyberverse-inference
    restart: unless-stopped
    deploy:
      resources:
        limits:
          memory: 512M

  cyberverse-inference:
    build:
      context: ..
      dockerfile: infra/Dockerfile.inference
    environment:
      - DOUBAO_API_KEY=${DOUBAO_API_KEY:?DOUBAO_API_KEY is required}
      - DOUBAO_APP_ID=${DOUBAO_APP_ID:?DOUBAO_APP_ID is required}
      - OPENAI_API_KEY=${OPENAI_API_KEY:?OPENAI_API_KEY is required}
      - CYBERVERSE_DATA_DIR=/app/data
    volumes:
      - ../checkpoints:/app/checkpoints
      - ../data:/app/data
    deploy:
      resources:
        limits:
          memory: 32G
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    restart: unless-stopped

  nginx:
    build:
      context: ..
      dockerfile: infra/Dockerfile.frontend
    ports:
      - "80:80"
    depends_on:
      - cyberverse-server
    restart: unless-stopped
    deploy:
      resources:
        limits:
          memory: 128M
