networks:
  ai-net:
    driver: bridge
  ai-services:
    name: ai-services
  ix-databases_shared-databases:
    external: true
  pangolin:
    external: true

services:
  ollama:
    container_name: ollama
    image: ollama/ollama:latest
    restart: unless-stopped
    networks:
      - ai-net
      - ai-services
    ports:
      - "11434:11434"
    environment:
      TZ: ${TZ}
      NVIDIA_VISIBLE_DEVICES: all
      NVIDIA_DRIVER_CAPABILITIES: compute,utility
    volumes:
      - /mnt/docker-ssd/docker/appdata/ollama:/root/.ollama
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]

  openwebui:
    container_name: openwebui
    image: ghcr.io/open-webui/open-webui:main
    restart: unless-stopped
    networks:
      - ai-net
      - ai-services
      - ix-databases_shared-databases
      - pangolin
    ports:
      - "8282:8080"
    environment:
      TZ: ${TZ}
      OLLAMA_BASE_URL: http://ollama:11434
      WEBUI_SECRET_KEY: ${OPENWEBUI_SECRET_KEY}
      DATABASE_URL: postgresql://openwebui:${OPENWEBUI_DB_PASS}@shared-postgres:5432/openwebui
      ENABLE_SIGNUP: "true"
      ENABLE_LOGIN_FORM: "true"
      VECTOR_DB: qdrant
      QDRANT_URI: http://qdrant:6333
      RAG_RERANKING_MODEL: "reranker"
      RAG_RERANKING_MODEL_AUTO_UPDATE: "false"
      RAG_OPENAI_API_BASE_URL: "http://litellm:4000"
      RAG_OPENAI_API_KEY: ${LITELLM_MASTER_KEY}
    volumes:
      - /mnt/docker-ssd/docker/appdata/openwebui:/app/backend/data
    depends_on:
      - ollama
    healthcheck:
      test: ["CMD-SHELL", "curl -sf http://127.0.0.1:8080/ || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  qdrant:
    container_name: qdrant
    image: qdrant/qdrant:v1.17.0
    restart: unless-stopped
    networks:
      - ai-net
      - ai-services
    ports:
      - "6333:6333"
      - "6334:6334"
    environment:
      TZ: ${TZ}
      QDRANT__SERVICE__GRPC_PORT: 6334
      QDRANT__STORAGE__STORAGE_PATH: /qdrant/storage
      QDRANT__STORAGE__SNAPSHOTS_PATH: /qdrant/snapshots
    volumes:
      - /mnt/docker-ssd/docker/appdata/qdrant/storage:/qdrant/storage
      - /mnt/docker-ssd/docker/appdata/qdrant/snapshots:/qdrant/snapshots

  litellm:
    container_name: litellm
    image: ghcr.io/berriai/litellm:main-latest
    restart: unless-stopped
    networks:
      - ai-net
      - ai-services
    ports:
      - "4000:4000"
    environment:
      TZ: ${TZ}
      LITELLM_MASTER_KEY: ${LITELLM_MASTER_KEY}
    volumes:
      - /mnt/docker-ssd/docker/compose/ai/litellm/config.yaml:/app/config.yaml:ro
      - /mnt/docker-ssd/docker/appdata/litellm:/app/data
    command: ["--config", "/app/config.yaml", "--port", "4000"]
    extra_hosts:
      - "host.docker.internal:host-gateway"

