Spaces:
Sleeping
Sleeping
File size: 2,394 Bytes
4362ba2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | # ββ Base: exact patch version matching the training interpreter (Β§1) ββββββ
# NOT alpine: musl libc has no manylinux wheels, so NumPy/SciPy would
# compile from source and can differ numerically.
FROM python:3.12-slim
# ββ Interpreter behaviour. Metadata only β no layer, never invalidated. βββ
# PYTHONUNBUFFERED is not cosmetic: without it logs sit in a buffer and
# vanish when the container is killed, exactly when they are needed.
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# ββ System libraries. One RUN, cleanup inside it, so the apt lists never ββ
# enter a layer. curl is needed by HEALTHCHECK.
RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*
# ββ Non-root user. HF Spaces expect uid 1000. ββββββββββββββββββββββββββββ
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"
WORKDIR /home/user/app
# ββ THE CACHE BOUNDARY: manifest alone, then install. ββββββββββββββββββββ
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# ββ Volatile files last. Edits here never re-run the install above. ββββββ
# superkart_features.py MUST be present: the pipeline's FunctionTransformer
# references engineer() by module path, and joblib.load fails without it.
COPY --chown=user superkart_features.py .
COPY --chown=user superkart_model_v1.joblib .
COPY --chown=user golden_sample.json model_manifest.json ./
COPY --chown=user app.py gunicorn.conf.py ./
# ββ Contract with the platform βββββββββββββββββββββββββββββββββββββββββββ
EXPOSE 7860
# start-period is generous: a 37 MB artefact must deserialize and pass the
# golden-sample check before the first probe counts against the retry budget.
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
CMD curl -fsS http://localhost:7860/health || exit 1
# ββ Exec form: gunicorn is PID 1, so SIGTERM reaches it and shutdown is ββ
# graceful. Shell form would put /bin/sh at PID 1, which swallows signals.
CMD ["gunicorn", "--config", "gunicorn.conf.py", "app:app"]
|