Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +46 -13
Dockerfile
CHANGED
|
@@ -1,21 +1,54 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
COPY
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
EXPOSE 8501
|
| 18 |
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ---- Base image ----
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
|
| 4 |
+
# ---- Workdir ----
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
+
# ---- Env ----
|
| 8 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 9 |
+
PYTHONUNBUFFERED=1 \
|
| 10 |
+
PIP_NO_CACHE_DIR=1 \
|
| 11 |
+
STREAMLIT_SERVER_HEADLESS=true \
|
| 12 |
+
HF_HUB_DISABLE_SYMLINKS_WARNING=1 \
|
| 13 |
+
XDG_CACHE_HOME=/app/.cache
|
| 14 |
|
| 15 |
+
# ---- Python deps ----
|
| 16 |
+
COPY requirements.txt /app/requirements.txt
|
| 17 |
+
RUN python -m pip install --no-cache-dir --upgrade pip \
|
| 18 |
+
&& python -m pip install --no-cache-dir -r /app/requirements.txt
|
| 19 |
|
| 20 |
+
# System deps for video/text rendering
|
| 21 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 22 |
+
ffmpeg \
|
| 23 |
+
fonts-dejavu-core \
|
| 24 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 25 |
|
|
|
|
| 26 |
|
| 27 |
+
# ---- App code ----
|
| 28 |
+
COPY . /app
|
| 29 |
|
| 30 |
+
# ---- Create non-root user and fix permissions ----
|
| 31 |
+
# uid 1000 is conventional; adjust if you need
|
| 32 |
+
RUN useradd -m -u 1000 -s /bin/sh app \
|
| 33 |
+
&& mkdir -p /app/.streamlit /app/.cache \
|
| 34 |
+
&& chown -R app:app /app
|
| 35 |
+
|
| 36 |
+
# Drop privileges for runtime
|
| 37 |
+
USER app
|
| 38 |
+
|
| 39 |
+
# ---- Streamlit config ----
|
| 40 |
+
RUN printf "[server]\nheadless = true\nport = 7860\naddress = \"0.0.0.0\"\nenableCORS = false\nenableXsrfProtection = false\n" \
|
| 41 |
+
> /app/.streamlit/config.toml
|
| 42 |
+
|
| 43 |
+
# ---- Port & health ----
|
| 44 |
+
EXPOSE 7860
|
| 45 |
+
ENV PORT=7860
|
| 46 |
+
|
| 47 |
+
# Healthcheck hits Streamlit's built-in health endpoint
|
| 48 |
+
COPY --chown=app:app healthcheck.py /app/healthcheck.py
|
| 49 |
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=5 \
|
| 50 |
+
CMD python /app/healthcheck.py || exit 1
|
| 51 |
+
|
| 52 |
+
# ---- Start the app ----
|
| 53 |
+
# Use sh -c so ${PORT} expands at runtime on Spaces
|
| 54 |
+
CMD ["sh","-c","python -m streamlit run app.py --server.port=${PORT:-7860} --server.address=0.0.0.0 --server.enableCORS=false --server.enableXsrfProtection=false"]
|