Spaces:
Running
Running
File size: 1,848 Bytes
84a0530 3431323 84a0530 3431323 84a0530 3431323 84a0530 3431323 84a0530 3431323 | 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 | # scikit-plots/ai Β· Dockerfile v3.1.0
#
# Changes from v3.0.0
# βββββββββββββββββββ
# + COPY _shared_logic.py β required because app.py v3.1.0 imports from it.
# If this COPY is missing, the container starts, uvicorn loads app.py, and
# `from _shared_logic import ...` raises ModuleNotFoundError at import time.
# This would manifest as the container restarting in a crash loop, with
# HF logging "ModuleNotFoundError: No module named '_shared_logic'".
#
# Unchanged from v3.0.0
# βββββββββββββββββββββ
# Base image, WORKDIR, port, CMD, HEALTHCHECK are all identical.
#
# SPDX-License-Identifier: BSD-3-Clause
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy _shared_logic.py BEFORE app.py so Docker layer cache is invalidated
# only when these files actually change (requirements.txt changes least often;
# _shared_logic.py changes less often than app.py).
COPY _shared_logic.py .
COPY app.py .
# HuggingFace Spaces routes traffic to the port declared in README.md
# (app_port: 7860). Do not change without also updating README.md.
EXPOSE 7860
# Health check β probes /health every 15 s after a 10 s startup grace period.
# The container is marked unhealthy (and restarted by HF) if /health fails
# 3 consecutive times. This ensures requests are only routed to the container
# after uvicorn has bound its port and app.py startup validation has passed.
#
# Using python -c avoids installing curl into the image.
HEALTHCHECK --interval=15s --timeout=5s --start-period=10s --retries=3 \
CMD python -c \
"import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" \
|| exit 1
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|