# Default image = CUDA (GPU). See Dockerfile.cpu for the CPU-only image.
# Build:  docker build -t open-decision:latest .
# Run:    docker run --gpus all -p 8000:8000 -v ~/.cache/huggingface:/root/.cache/huggingface \
#             -e OPEN_DECISION_MODEL=org/open-decision-150m open-decision:latest
FROM nvidia/cuda:12.8.1-runtime-ubuntu24.04 AS base

ENV DEBIAN_FRONTEND=noninteractive PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 \
    UV_LINK_MODE=copy UV_COMPILE_BYTECODE=1 UV_PYTHON_INSTALL_DIR=/opt/python
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl \
    && rm -rf /var/lib/apt/lists/*
COPY --from=ghcr.io/astral-sh/uv:0.8 /uv /uvx /bin/

WORKDIR /app
# Dependencies first (cached), then the project.
COPY pyproject.toml uv.lock .python-version README.md ./
RUN uv sync --frozen --no-dev --no-install-project
COPY src ./src
RUN uv sync --frozen --no-dev

ENV PATH="/app/.venv/bin:$PATH" \
    OPEN_DECISION_HOST=0.0.0.0 \
    OPEN_DECISION_PORT=8000 \
    OPEN_DECISION_DEVICE=auto \
    HF_HUB_DISABLE_TELEMETRY=1
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=5s --start-period=120s --retries=3 \
    CMD curl -fs http://localhost:8000/ready || exit 1
ENTRYPOINT ["open-decision", "serve"]
