Tulitula commited on
Commit
af7bed5
·
verified ·
1 Parent(s): cd0b356

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +34 -39
Dockerfile CHANGED
@@ -1,14 +1,7 @@
1
- # ---- Base image (pin to a stable Debian) ----
2
  FROM python:3.10-slim-bullseye
3
 
4
- ENV DEBIAN_FRONTEND=noninteractive \
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
- # ---- Non-root user ----
20
  RUN useradd -m -u 1000 user
21
  USER user
22
  WORKDIR /home/user/app
23
 
24
- # ---- Writable caches (fixes the matplotlib & HF cache warnings) ----
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
- "$MPLCONFIGDIR" \
33
- "$HF_HOME" \
34
- "$TRANSFORMERS_CACHE" \
35
- "$SENTENCE_TRANSFORMERS_HOME" \
36
- "$XDG_CACHE_HOME"
37
-
38
- # ---- Python deps ----
39
- # Make sure requirements.txt is in your repo root.
40
- COPY --chown=user:user requirements.txt /home/user/app/requirements.txt
41
- RUN python -m pip install --upgrade pip && pip install -r requirements.txt
42
-
43
- # (Optional) Pre-download the embedding model at build time to speed up first run.
44
- # Uncomment if you prefer longer build but faster startup.
45
- # RUN python - <<'PY'
46
- # from sentence_transformers import SentenceTransformer
47
- # SentenceTransformer("BAAI/bge-base-en-v1.5")
48
- # PY
49
-
50
- # ---- App code ----
51
- COPY --chown=user:user . /home/user/app
 
 
 
 
 
 
 
 
 
 
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"]