# Reference agent backend image.
#
# Build context is the repository root, so the image can install `altar-identity` from `identity/`, the Altar
# package (with its agent extra), and the `altar-chrombpnet` binding the demo scorer resolves through the public
# model registry, then layer the web-server deps and the backend module on top:
#
#   docker build -f altar/reference/backend/Dockerfile -t altar-agent-backend .
#
# (or just `docker compose up` from `altar/reference/`, which sets the context for you).
FROM python:3.12-slim@sha256:2f17fc044b579bab302c2e8054d3a686e2cb9a83de48e70534b94cd8ebbe06a9

# A C toolchain for core dependencies that publish no wheel for every platform (e.g. `ncls` on arm64).
RUN apt-get update \
    && apt-get install -y --no-install-recommends build-essential \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /opt/altar

# Install identity, the package + agent extra, and the ChromBPNet binding (their own layer, so it caches across
# backend edits). The same pip call installs `altar-identity`, which `altar` pins, from the repository, so the
# demo runs the checkout's code rather than a released version; the binding depends only on `altar`.
COPY identity ./identity
COPY altar/pyproject.toml altar/README.md altar/LICENSE ./altar/
COPY altar/altar ./altar/altar
COPY bindings/chrombpnet ./bindings/chrombpnet
RUN pip install --no-cache-dir ./identity "./altar[agent]" ./bindings/chrombpnet

# Web-server deps, then the backend module.
COPY altar/reference/backend/requirements.txt ./reference-requirements.txt
RUN pip install --no-cache-dir -r reference-requirements.txt
COPY altar/reference/backend /opt/altar/backend

WORKDIR /opt/altar/backend
ENV REFERENCE_DATA_DIR=/data
EXPOSE 8010

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8010"]
