# apps/embedding-runtime/Dockerfile
# SmartMLOps Tier-2 embedding-runtime — OpenAI-compatible embeddings/rerank server.
# KServe owns lifecycle (ClusterServingRuntime container); we own only this serving code.
FROM cgr.dev/chainguard/python:latest-dev@sha256:489eccd3f58cc60c69fe6b15fab4a04ad57072b1463a86e968649e2afc2e3c9d AS dependencies

ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \
    PYTHONDONTWRITEBYTECODE=1
WORKDIR /home/nonroot/app
COPY requirements.txt /home/nonroot/app/requirements.txt
RUN python -m venv /home/nonroot/venv \
    && /home/nonroot/venv/bin/pip install --no-cache-dir -r requirements.txt

FROM dependencies AS quality
ENV VIRTUAL_ENV=/home/nonroot/venv \
    PYTHONPYCACHEPREFIX=/tmp/embedding-runtime-pycache
COPY requirements-test.txt Dockerfile README.md server.py /home/nonroot/app/
COPY tests /home/nonroot/app/tests
RUN /home/nonroot/venv/bin/pip install --no-cache-dir -r requirements-test.txt \
    && /home/nonroot/venv/bin/python -m pytest -p no:cacheprovider tests \
    && /home/nonroot/venv/bin/ruff check server.py tests \
    && /home/nonroot/venv/bin/ty check server.py tests \
    && /home/nonroot/venv/bin/python -m compileall -q server.py tests

FROM dependencies AS runtime-dependencies
RUN /home/nonroot/venv/bin/pip uninstall -y pip setuptools wheel jaraco.context

FROM cgr.dev/chainguard/python:latest@sha256:ce9aaca1f826f7f963cd031e98f8c19f993b1843096d395ea919b646e72cb8de

ENV HF_HUB_DISABLE_TELEMETRY=1 \
    PATH="/home/nonroot/venv/bin:${PATH}" \
    PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1
WORKDIR /app
COPY --from=runtime-dependencies --chown=65532:65532 /home/nonroot/venv /home/nonroot/venv
COPY --chown=65532:65532 server.py /app/server.py
EXPOSE 8080
# KServe mounts the model artifact at /mnt/models; server.py reads EMBEDDING_MODEL_DIR (default /mnt/models).
USER 65532:65532
ENTRYPOINT ["/home/nonroot/venv/bin/uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8080"]
