67 lines
2.5 KiB
Docker
67 lines
2.5 KiB
Docker
# The base image is a build argument so that make -C deploy release-build can
|
|
# pin it to the digest it resolved. PyTorch publishes glibc wheels only, so the
|
|
# service uses the Debian slim variant instead of Alpine, and the minor version
|
|
# is fixed because requires-python and the locked wheels are for Python 3.14.
|
|
ARG PYTHON_IMAGE=python:3.14-slim
|
|
|
|
FROM ${PYTHON_IMAGE} AS base
|
|
|
|
RUN apt-get update \
|
|
&& apt-get upgrade --yes --no-install-recommends \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
FROM base AS build
|
|
|
|
ENV UV_COMPILE_BYTECODE=1 \
|
|
UV_LINK_MODE=copy \
|
|
UV_PROJECT_ENVIRONMENT=/opt/venv \
|
|
UV_PYTHON_DOWNLOADS=never
|
|
|
|
WORKDIR /workspace
|
|
RUN python -m pip install --no-cache-dir uv==0.12.22
|
|
|
|
COPY ml/.python-version ml/pyproject.toml ml/uv.lock ./ml/
|
|
COPY ml/src ./ml/src
|
|
RUN uv sync --project ml --python /usr/local/bin/python --locked --no-dev --no-editable
|
|
|
|
# The model files are fetched once, at build time, from the pinned revision
|
|
# and verified against the SHA-256 of the lock file. Only safetensors weights,
|
|
# configs, and the tokenizer are fetched: no remote code, no pickle weights.
|
|
FROM base AS model
|
|
|
|
COPY ml/src/lincodex_ml/model_files.py /tmp/model_files.py
|
|
COPY ml/model/giga-embeddings-480m.lock.json /tmp/model.lock.json
|
|
RUN python /tmp/model_files.py fetch --lock /tmp/model.lock.json --out /opt/lincodex/model \
|
|
&& rm /tmp/model_files.py /tmp/model.lock.json
|
|
|
|
FROM base
|
|
|
|
ENV PATH="/opt/venv/bin:${PATH}" \
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
PYTHONUNBUFFERED=1 \
|
|
ML_EMBEDDER=giga \
|
|
ML_MODEL_DIR=/opt/lincodex/model \
|
|
ML_TORCH_THREADS=4 \
|
|
HF_HUB_OFFLINE=1 \
|
|
TRANSFORMERS_OFFLINE=1 \
|
|
HF_HUB_DISABLE_TELEMETRY=1
|
|
|
|
WORKDIR /app
|
|
# Package installation belongs to the build stage, not the service runtime.
|
|
RUN python -m pip uninstall --yes pip \
|
|
&& python -c "import ensurepip, shutil; shutil.rmtree(ensurepip.__path__[0])" \
|
|
&& groupadd --system --gid 10001 lincodex \
|
|
&& useradd --system --uid 10001 --gid lincodex --no-create-home --shell /usr/sbin/nologin lincodex
|
|
|
|
COPY --from=build --chown=lincodex:lincodex /opt/venv /opt/venv
|
|
# Read-only for the service user: root owns the weights.
|
|
COPY --from=model /opt/lincodex/model /opt/lincodex/model
|
|
|
|
USER 10001:10001
|
|
EXPOSE 8000
|
|
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/healthz', timeout=2)"]
|
|
|
|
CMD ["uvicorn", "lincodex_ml.main:app", "--host", "0.0.0.0", "--port", "8000"]
|