FROM python:3.10-slim

# System deps
RUN apt-get update && apt-get install -y --no-install-recommends gcc g++ libgeos-dev git libxcb1 libgl1 libglib2.0-0 libsm6 libxext6 libxrender-dev && apt-get clean && find /var/lib/apt/lists -type f -delete

# Step 1: CPU-only PyTorch FIRST (avoids 2GB+ CUDA deps)
RUN pip install --no-cache-dir --timeout=600 --retries=5 torch --index-url https://download.pytorch.org/whl/cpu

# Step 2: Core dependencies
RUN pip install --no-cache-dir --timeout=600 --retries=5 numpy pandas pyarrow scipy pathos Pillow tqdm packaging

# Step 3: av2-api-sm and TrackEval (reuses CPU torch)
RUN pip install --no-cache-dir --timeout=600 --retries=5 "git+https://github.com/CainanD/av2-api-sm.git" "git+https://github.com/JonathonLuiten/TrackEval.git"

WORKDIR /app
COPY data/ /data/
ENV PYTHONPATH="/data/refav_runtime:${PYTHONPATH}"
RUN mkdir -p /logs/verifier /data/output
