# 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 revisions # 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 ml/model/qwen3-embedding-0.6b.lock.json /tmp/locks/ RUN python /tmp/model_files.py fetch --lock /tmp/locks/giga-embeddings-480m.lock.json --out /opt/lincodex/models/giga-480m \ && python /tmp/model_files.py fetch --lock /tmp/locks/qwen3-embedding-0.6b.lock.json --out /opt/lincodex/models/qwen3-0.6b \ && rm -r /tmp/model_files.py /tmp/locks FROM base ENV PATH="/opt/venv/bin:${PATH}" \ PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ ML_EMBEDDER=giga,qwen3 \ ML_GIGA_MODEL_DIR=/opt/lincodex/models/giga-480m \ ML_QWEN3_MODEL_DIR=/opt/lincodex/models/qwen3-0.6b \ ML_TORCH_THREADS=4 \ ML_LISTEN_HOST=0.0.0.0 \ ML_LISTEN_PORT=8000 \ 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/models /opt/lincodex/models 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)"] # The entry point refuses to listen on 0.0.0.0 without ML_SERVICE_TOKEN. CMD ["python", "-m", "lincodex_ml.serve"]