# Dockerfile.jetson — for NVIDIA Jetson Orin (ARM64 + CUDA)
# Build on Jetson or with buildx for linux/arm64
#
# Usage:
#   docker build -f Dockerfile.jetson -t proxym:jetson .
#   docker run --runtime nvidia --gpus all -p 4000:4000 proxym:jetson

FROM dustynv/ollama:r36.4.0 AS ollama-base

# ── Runtime ───────────────────────────────────────────────────
FROM python:3.11-slim

WORKDIR /app

# Install system deps
RUN apt-get update && \
    apt-get install -y --no-install-recommends curl && \
    rm -rf /var/lib/apt/lists/*

# Install Python deps
COPY pyproject.toml .
COPY src/ src/
RUN pip install --no-cache-dir ".[gpu]" 2>/dev/null || pip install --no-cache-dir .

# Copy Ollama binary from jetson container
COPY --from=ollama-base /bin/ollama /usr/local/bin/ollama

# Entrypoint script that starts Ollama + proxy
COPY scripts/jetson-entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

EXPOSE 4000 11434

HEALTHCHECK --interval=15s --timeout=5s --retries=3 \
    CMD curl -f http://localhost:4000/health || exit 1

ENTRYPOINT ["/entrypoint.sh"]
