HFNLWebDemo / Dockerfile
rvguha's picture
Tolerate an absent bundled corpus when clearing it
1ea15e2 verified
Raw History Blame
1.41 kB
# Hugging Face Spaces (Docker SDK) serves on port 7860 and runs as uid 1000.
FROM python:3.12-slim
ENV PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
ASKHUB_HOST=0.0.0.0 \
ASKHUB_PORT=7860 \
ASKHUB_DATA_DIR=/data/corpus \
ASKHUB_CACHE_DIR=/data/embeddings
RUN useradd -m -u 1000 app
WORKDIR /app
COPY pyproject.toml ./
COPY src ./src
RUN pip install --no-cache-dir .
# Drop the corpus baked into the package. The catalog loader prefers bundled
# content over the data directory -- deliberately, so an upgrade cannot be
# shadowed by a stale runtime copy -- which here would mean the image's corpus
# silently winning over the mounted bucket, and a refresh of the bucket having
# no effect at all. The mount is the source of truth on this deployment.
# Belt and braces: the corpus is excluded from what is pushed here, but if a
# build ever does carry one it must not shadow the mount. Tolerant of the
# directory being absent, which is the normal case -- `find` on a missing path
# exits 1 and would fail the build.
RUN find /usr/local/lib/python3.12/site-packages/askhub -name '*.jsonl' -delete 2>/dev/null || true
COPY sources.yaml ./
# /data is a mounted bucket: the corpus is read from it and the embedding cache
# is written back to it, so neither is recomputed or redownloaded on a restart.
RUN mkdir -p /data && chown -R app:app /data /app
USER app
EXPOSE 7860
CMD ["ask-hf-hub"]