Marcin-XStudio commited on
Commit
ae042ea
·
1 Parent(s): dd9a95d
Files changed (1) hide show
  1. Dockerfile +8 -10
Dockerfile CHANGED
@@ -1,6 +1,6 @@
1
  FROM python:3.10-slim
2
 
3
- # 1) Set up cache/env paths
4
  ENV HOME="/home/user" \
5
  HF_HOME="$HOME/.cache/huggingface" \
6
  HF_HUB_CACHE="$HF_HOME/hub" \
@@ -8,25 +8,24 @@ ENV HOME="/home/user" \
8
  DOCLING_ARTIFACTS_PATH="$HOME/.cache/docling/models" \
9
  OMP_NUM_THREADS=2
10
 
11
- # 2) Create non-root user
12
  RUN useradd -m -u 1000 user
13
 
14
- # 3) Install system dependencies
15
  RUN apt-get update && apt-get install -y \
16
  build-essential git libpoppler-cpp-dev poppler-utils \
17
  libmagic-dev python3-dev \
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
- # 4) Copy and install Python dependencies
21
  WORKDIR $HOME/app
22
- # Note: this COPY refers to ./requirements.txt in YOUR repo, not /home/user/app
23
  COPY --chown=user:user requirements.txt ./
24
  RUN pip install --no-cache-dir \
25
  torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu \
26
  huggingface_hub accelerate \
27
  && pip install --no-cache-dir -r requirements.txt
28
 
29
- # 5) Prepare cache directories and set ownership
30
  RUN mkdir -p \
31
  $DOCLING_ARTIFACTS_PATH \
32
  $HF_HUB_CACHE \
@@ -36,15 +35,15 @@ RUN mkdir -p \
36
  $HOME/.cache/huggingface \
37
  $HOME/app/model_cache
38
 
39
- # 6) Switch to non-root to prefetch Docling models
40
  USER user
41
  RUN pip install --no-cache-dir docling \
42
  && docling-tools models download
43
 
44
- # 7) Prefetch the NuExtract model
45
  RUN python - <<EOF
46
- from huggingface_hub import snapshot_download
47
  import os
 
48
  snapshot_download(
49
  repo_id="numind/NuExtract-1.5-tiny",
50
  local_dir=os.path.join(os.getenv("HOME"), "app", "model_cache"),
@@ -53,6 +52,5 @@ snapshot_download(
53
  EOF
54
 
55
  # 8) Copy application code and start
56
- USER user
57
  COPY --chown=user:user . .
58
  CMD ["uvicorn","app:app","--host","0.0.0.0","--port","7860"]
 
1
  FROM python:3.10-slim
2
 
3
+ # 1) Set up env so caches live under the non-root user’s home
4
  ENV HOME="/home/user" \
5
  HF_HOME="$HOME/.cache/huggingface" \
6
  HF_HUB_CACHE="$HF_HOME/hub" \
 
8
  DOCLING_ARTIFACTS_PATH="$HOME/.cache/docling/models" \
9
  OMP_NUM_THREADS=2
10
 
11
+ # 2) Create non-root user early
12
  RUN useradd -m -u 1000 user
13
 
14
+ # 3) Install system deps
15
  RUN apt-get update && apt-get install -y \
16
  build-essential git libpoppler-cpp-dev poppler-utils \
17
  libmagic-dev python3-dev \
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
+ # 4) Copy & install Python deps
21
  WORKDIR $HOME/app
 
22
  COPY --chown=user:user requirements.txt ./
23
  RUN pip install --no-cache-dir \
24
  torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu \
25
  huggingface_hub accelerate \
26
  && pip install --no-cache-dir -r requirements.txt
27
 
28
+ # 5) Prepare cache dirs under root and chown to user
29
  RUN mkdir -p \
30
  $DOCLING_ARTIFACTS_PATH \
31
  $HF_HUB_CACHE \
 
35
  $HOME/.cache/huggingface \
36
  $HOME/app/model_cache
37
 
38
+ # 6) Switch to non-root: prefetch Docling models into $HOME/.cache/docling/models
39
  USER user
40
  RUN pip install --no-cache-dir docling \
41
  && docling-tools models download
42
 
43
+ # 7) Prefetch NuExtract model into app/model_cache using user-owned HF cache
44
  RUN python - <<EOF
 
45
  import os
46
+ from huggingface_hub import snapshot_download
47
  snapshot_download(
48
  repo_id="numind/NuExtract-1.5-tiny",
49
  local_dir=os.path.join(os.getenv("HOME"), "app", "model_cache"),
 
52
  EOF
53
 
54
  # 8) Copy application code and start
 
55
  COPY --chown=user:user . .
56
  CMD ["uvicorn","app:app","--host","0.0.0.0","--port","7860"]