# python:3.14-slim, pinned by index digest (multi-arch); bump with the lock.
FROM python:3.14-slim@sha256:9aaa474097d094040649f2162a627c0049b408f52138d980916788d80f04802f

WORKDIR /app

ENV PYTHONUNBUFFERED=1
ENV OMP_NUM_THREADS=1
# Model cache outside /tmp, owned by the runtime user (UID 10001, the app's).
ENV FASTEMBED_CACHE_PATH=/opt/fastembed

RUN groupadd --system --gid 10001 limedoc \
	&& useradd --system --uid 10001 --gid limedoc --no-create-home \
		--home-dir /nonexistent --shell /usr/sbin/nologin limedoc

# Exact versions with hashes (requirements.lock, generated from requirements.txt).
COPY requirements.lock .
RUN pip install --no-cache-dir --require-hashes -r requirements.lock

COPY src/ ./src/

WORKDIR /app/src

# Bake multilingual-e5-small into the image so cold starts do not block /health.
RUN python -c "from embedder import warmup; warmup()" \
	&& mkdir -p /app/data/cache/vectorsearch \
	&& chown -R limedoc:limedoc /opt/fastembed /app/data

# Same UID as the app: the cache volume is shared (the app entrypoint chowns
# it on start; a fresh named volume takes /app/data/... ownership from here).
USER 10001:10001

EXPOSE 8091

CMD ["python", "main.py"]
