File size: 2,954 Bytes
73859e0 8be3a16 73859e0 013b739 73859e0 8be3a16 013b739 8be0db8 73859e0 013b739 8be3a16 73859e0 8be0db8 8be3a16 8be0db8 013b739 73859e0 8be0db8 73859e0 8be3a16 73859e0 8be3a16 8be0db8 8be3a16 8be0db8 | 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 image ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
FROM python:3.11-slim
# ββ System deps βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# curl β healthcheck only (no ffmpeg needed without download feature)
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*
# ββ Working directory βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
WORKDIR /app
# ββ Python deps β separate layer so code changes don't bust the cache βββββββββ
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt
# ββ App code ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
COPY app.py ./
# ββ Ensure tmp dirs exist and are writable ββββββββββββββββββββββββββββββββββββ
RUN mkdir -p /tmp/ytm_cache \
&& chmod -R 777 /tmp/ytm_cache
# ββ Hugging Face Spaces runs as a non-root user βββββββββββββββββββββββββββββββ
RUN chmod -R 755 /app
# ββ Expose port 7860 (required by HF Spaces) βββββββββββββββββββββββββββββββββ
EXPOSE 7860
# ββ Health check ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:7860/health || exit 1
# ββ Start server ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Single worker: in-memory chart cache (_cache_charts) is process-local.
# With 1 worker all requests share the same 10-hour chart cache.
# Disk cache (diskcache) provides durability across restarts.
# uvloop + httptools come in via uvicorn[standard].
CMD ["uvicorn", "app:app", \
"--host", "0.0.0.0", \
"--port", "7860", \
"--workers", "1", \
"--loop", "uvloop", \
"--http", "httptools", \
"--timeout-keep-alive", "120", \
"--access-log"]
|