Update Dockerfile
Browse files- Dockerfile +34 -39
Dockerfile
CHANGED
|
@@ -1,14 +1,7 @@
|
|
| 1 |
-
#
|
| 2 |
FROM python:3.10-slim-bullseye
|
| 3 |
|
| 4 |
-
|
| 5 |
-
PIP_NO_CACHE_DIR=1 \
|
| 6 |
-
PYTHONUNBUFFERED=1
|
| 7 |
-
|
| 8 |
-
# ---- System packages your app/libs need ----
|
| 9 |
-
# - libgl1 / libx* / libsm6: for matplotlib, PIL, etc.
|
| 10 |
-
# - ffmpeg: media handling (gradio, PIL, etc. sometimes need it)
|
| 11 |
-
# - git & git-lfs: model downloads that use LFS
|
| 12 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 13 |
git git-lfs ffmpeg \
|
| 14 |
libglib2.0-0 libsm6 libxext6 libxrender1 libgl1 \
|
|
@@ -16,41 +9,43 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 16 |
&& rm -rf /var/lib/apt/lists/* \
|
| 17 |
&& git lfs install
|
| 18 |
|
| 19 |
-
#
|
| 20 |
RUN useradd -m -u 1000 user
|
| 21 |
USER user
|
| 22 |
WORKDIR /home/user/app
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
ENV MPLCONFIGDIR=/home/user/.config/matplotlib \
|
| 26 |
-
HF_HOME=/home/user/.cache/huggingface \
|
| 27 |
-
TRANSFORMERS_CACHE=/home/user/.cache/huggingface/hub \
|
| 28 |
-
SENTENCE_TRANSFORMERS_HOME=/home/user/.cache/sentencetransformers \
|
| 29 |
-
XDG_CACHE_HOME=/home/user/.cache
|
| 30 |
-
|
| 31 |
RUN mkdir -p \
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
#
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
#
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
EXPOSE 7860
|
| 54 |
-
|
| 55 |
-
# ---- Start the app ----
|
| 56 |
CMD ["python", "app.py"]
|
|
|
|
| 1 |
+
# Use a stable, compatible base
|
| 2 |
FROM python:3.10-slim-bullseye
|
| 3 |
|
| 4 |
+
# System packages required by your app (fonts + OpenGL bits for matplotlib/PIL, ffmpeg for video)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 6 |
git git-lfs ffmpeg \
|
| 7 |
libglib2.0-0 libsm6 libxext6 libxrender1 libgl1 \
|
|
|
|
| 9 |
&& rm -rf /var/lib/apt/lists/* \
|
| 10 |
&& git lfs install
|
| 11 |
|
| 12 |
+
# Create non-root user
|
| 13 |
RUN useradd -m -u 1000 user
|
| 14 |
USER user
|
| 15 |
WORKDIR /home/user/app
|
| 16 |
|
| 17 |
+
# Make cache/config dirs writable (and fast)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
RUN mkdir -p \
|
| 19 |
+
/home/user/.config/matplotlib \
|
| 20 |
+
/home/user/.cache/huggingface/hub \
|
| 21 |
+
/home/user/.cache/sentencetransformers \
|
| 22 |
+
/home/user/.cache/pip
|
| 23 |
+
|
| 24 |
+
# Ensure user installs are on PATH
|
| 25 |
+
ENV PATH="/home/user/.local/bin:${PATH}"
|
| 26 |
+
ENV MPLCONFIGDIR=/home/user/.config/matplotlib
|
| 27 |
+
ENV HF_HOME=/home/user/.cache/huggingface
|
| 28 |
+
ENV SENTENCE_TRANSFORMERS_HOME=/home/user/.cache/sentencetransformers
|
| 29 |
+
ENV GRADIO_ANALYTICS_ENABLED=false
|
| 30 |
+
ENV PYTHONUNBUFFERED=1
|
| 31 |
+
|
| 32 |
+
# Python deps
|
| 33 |
+
COPY --chown=user:user requirements.txt ./requirements.txt
|
| 34 |
+
RUN python -m pip install --upgrade pip && \
|
| 35 |
+
pip install --no-cache-dir -r requirements.txt
|
| 36 |
+
|
| 37 |
+
# (Optional) pre-cache the embedding model to avoid cold-start downloads
|
| 38 |
+
RUN python - <<'PY'
|
| 39 |
+
from sentence_transformers import SentenceTransformer
|
| 40 |
+
try:
|
| 41 |
+
SentenceTransformer("BAAI/bge-base-en-v1.5")
|
| 42 |
+
print("Pre-cached BAAI/bge-base-en-v1.5")
|
| 43 |
+
except Exception as e:
|
| 44 |
+
print("Model pre-download failed:", e)
|
| 45 |
+
PY
|
| 46 |
+
|
| 47 |
+
# App source
|
| 48 |
+
COPY --chown=user:user . .
|
| 49 |
|
| 50 |
EXPOSE 7860
|
|
|
|
|
|
|
| 51 |
CMD ["python", "app.py"]
|