Marcin-XStudio commited on
Commit
b8658f4
·
1 Parent(s): ae042ea
Files changed (1) hide show
  1. Dockerfile +21 -21
Dockerfile CHANGED
@@ -1,47 +1,47 @@
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" \
7
- TRANSFORMERS_CACHE="$HF_HOME/transformers" \
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 \
 
32
  $HOME/app/model_cache \
33
  && chown -R user:user \
34
- $HOME/.cache/docling \
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(
@@ -51,6 +51,6 @@ snapshot_download(
51
  )
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"]
 
1
  FROM python:3.10-slim
2
 
3
+ # 1) Configure all caches under the non-root home
4
+ ENV HOME=/home/user \
5
+ HF_HOME=/home/user/.cache/huggingface \
6
+ HF_HUB_CACHE=/home/user/.cache/huggingface/hub \
7
+ TRANSFORMERS_CACHE=/home/user/.cache/huggingface/transformers \
8
+ DOCLING_ARTIFACTS_PATH=/home/user/.cache/docling/models \
9
  OMP_NUM_THREADS=2
10
 
11
+ # 2) Install system-level dependencies
 
 
 
12
  RUN apt-get update && apt-get install -y \
13
  build-essential git libpoppler-cpp-dev poppler-utils \
14
  libmagic-dev python3-dev \
15
  && rm -rf /var/lib/apt/lists/*
16
 
17
+ # 3) Create a non-root user
18
+ RUN useradd -m -u 1000 user
19
+
20
  WORKDIR $HOME/app
21
+
22
+ # 4) Copy & install Python runtime dependencies
23
+ COPY 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 give ownership to `user`
30
  RUN mkdir -p \
 
31
  $HF_HUB_CACHE \
32
+ $DOCLING_ARTIFACTS_PATH \
33
  $HOME/app/model_cache \
34
  && chown -R user:user \
35
+ $HOME/.cache \
 
36
  $HOME/app/model_cache
37
 
38
+ # 6) Switch to non-root and prefetch Docling’s models
39
  USER user
40
  RUN pip install --no-cache-dir docling \
41
  && docling-tools models download
42
 
43
+ # 7) Prefetch your NuExtract model into model_cache
44
+ RUN python3 - <<EOF
45
  import os
46
  from huggingface_hub import snapshot_download
47
  snapshot_download(
 
51
  )
52
  EOF
53
 
54
+ # 8) Copy your application code & start the server
55
  COPY --chown=user:user . .
56
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]