services:
    # Docling
    docling:
        # https://github.com/docling-project/docling-serve
        # 5001: Web UI + API
        # OCR: EasyOCR with English + Chinese Simplified + Traditional (auto-downloaded on first run)

        image: ghcr.io/docling-project/docling-serve-cpu:v1.13.0
        container_name: jt-docling
        restart: unless-stopped
        environment:
            DOCLING_SERVE_ENABLE_UI: "true"
        volumes:
            - docling_models:/opt/app-root/src/.cache/docling/models
        ports:
            - "5001:5001"
        entrypoint: ["/bin/sh", "-c"]
        command:
            - |
              # Download Chinese OCR models if missing (first run only)
              if [ ! -f /opt/app-root/src/.cache/docling/models/EasyOcr/zh_sim_g2.pth ] || [ ! -f /opt/app-root/src/.cache/docling/models/EasyOcr/zh_tra_g2.pth ]; then
                echo "Downloading Chinese OCR models (Simplified + Traditional)..."
                python3 -c "import easyocr; easyocr.Reader(['en','ch_sim','ch_tra'], gpu=False)"
                # Copy downloaded models to correct location
                cp -n /opt/app-root/src/.EasyOCR/model/*.pth /opt/app-root/src/.cache/docling/models/EasyOcr/ 2>/dev/null || true
              fi
              exec uvicorn docling_serve.app:app --host 0.0.0.0 --port 5001
        healthcheck:
            test: ["CMD", "curl", "-sf", "http://localhost:5001/health"]
            interval: 30s
            timeout: 10s
            retries: 3
            start_period: 120s

    # Ollama
    ollama:
        # https://hub.docker.com/r/ollama/ollama
        # 11434: API port
        # Model: qwen3:1.7b (auto-pulled on startup)

        image: ollama/ollama:0.9.3
        container_name: jt-ollama
        restart: unless-stopped
        volumes:
            - ollama_data:/root/.ollama
        ports:
            - "11434:11434"
        entrypoint: ["/bin/sh", "-c", "ollama serve & sleep 5 && ollama pull qwen3:1.7b && wait"]
        healthcheck:
            test: ["CMD", "curl", "-sf", "http://localhost:11434/api/tags"]
            interval: 30s
            timeout: 10s
            retries: 5
            start_period: 120s

    # Tools (Python FastAPI - Excel operations)
    # tools:
    #     build: ./Tools/Service
    #     container_name: jt-tools
    #     restart: unless-stopped
    #     volumes:
    #         - /data/jingtian/BenjaminTeam:/data:rw
    #     ports:
    #         - "8080:8080"
    #     healthcheck:
    #         test: ["CMD", "curl", "-sf", "http://localhost:8080/health"]
    #         interval: 30s
    #         timeout: 10s
    #         retries: 3

volumes:
    docling_models:
        name: jt-docling-models
    ollama_data:
        name: jt-ollama-data
