# Model runtime (local builds and reference image)

FROM python:3.11-slim

WORKDIR /app

# Install runtime deps from runtime/pyproject.toml only (avoid busting cache when runtime/Dockerfile changes).
COPY runtime/pyproject.toml /app/runtime/pyproject.toml
# First, install heavy dependencies using pip cache
RUN --mount=type=cache,target=/root/.cache/pip \
    pip install /app/runtime

# Second, copy and install the project wheel (which changes on every push)
COPY .aimp/runtime-wheelhouse/ /opt/aimp/runtime-wheelhouse/
RUN --mount=type=cache,target=/root/.cache/pip \
    if [ -d /opt/aimp/runtime-wheelhouse ] && ls /opt/aimp/runtime-wheelhouse/*.whl >/dev/null 2>&1; then \
      pip install /opt/aimp/runtime-wheelhouse/*.whl; \
    fi

COPY . .

CMD ["python", "-m", "aimp_sdk.model_runner", "--module", "/app/main.py"]
