Marcin-XStudio commited on
Commit
91f3fdd
·
1 Parent(s): 8f27b26

new dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +24 -31
Dockerfile CHANGED
@@ -1,47 +1,40 @@
1
  FROM python:3.10-slim
2
- WORKDIR /app
 
 
 
3
 
4
- # 1) Variables pour rediriger tous les caches HF
5
- ENV PYTHONUNBUFFERED=1 \
6
- PORT=8000 \
7
- HF_HOME=/home/user/huggingface
8
- ENV HF_HUB_CACHE="/app/model_cache/hf_cache/hub"
9
- ENV TRANSFORMERS_CACHE="/app/model_cache/hf_cache/transformers"
10
-
11
- COPY requirements.txt .
12
 
 
13
  RUN apt-get update && apt-get install -y \
14
- build-essential \
15
- git \
16
- libpoppler-cpp-dev \
17
- poppler-utils \
18
- libmagic-dev \
19
- python3-dev \
20
  && rm -rf /var/lib/apt/lists/*
21
 
22
- # 2) Installer huggingface_hub + dépendances
23
- RUN pip install \
24
- --no-cache-dir \
25
- torch torchvision \
26
- --extra-index-url https://download.pytorch.org/whl/cpu
27
- RUN pip install --no-cache-dir -r requirements.txt
28
  RUN pip install --no-cache-dir huggingface_hub
 
29
 
30
- # 3) Précharger le modèle au build-time
 
 
 
 
 
 
31
  RUN python - <<EOF
32
  from huggingface_hub import snapshot_download
33
  snapshot_download(
34
  repo_id="numind/NuExtract-1.5-tiny",
35
- local_dir="/app/model_cache", # snapshot final
36
- cache_dir="/app/model_cache/hf_cache" # cache HF
37
  )
38
  EOF
39
 
40
- # 4) Rendre le dossier accessible à l’utilisateur
41
- RUN chmod -R a+rX /app/model_cache \
42
- && chown -R $(id -u):$(id -g) /app/model_cache
43
-
44
- # 5) Copier le code et démarrer
45
- COPY . .
46
-
47
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  FROM python:3.10-slim
2
+ # 1) Variables HF
3
+ ENV HF_HOME="/home/user/.cache/huggingface" \
4
+ HF_HUB_CACHE="/home/user/.cache/huggingface/hub" \
5
+ TRANSFORMERS_CACHE="/home/user/.cache/huggingface/transformers"
6
 
7
+ # 2) Créer l’utilisateur dès le départ
8
+ RUN useradd -m -u 1000 user
 
 
 
 
 
 
9
 
10
+ # 3) Installer dépendances système
11
  RUN apt-get update && apt-get install -y \
12
+ build-essential git libpoppler-cpp-dev poppler-utils libmagic-dev python3-dev \
 
 
 
 
 
13
  && rm -rf /var/lib/apt/lists/*
14
 
15
+ # 4) Copier et installer Python libs
16
+ WORKDIR /home/user/app
17
+ COPY --chown=user requirements.txt .
18
+ RUN pip install --no-cache-dir torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu
 
 
19
  RUN pip install --no-cache-dir huggingface_hub
20
+ RUN pip install --no-cache-dir -r requirements.txt
21
 
22
+ # 5) Pré-créer et donner droits sur model_cache
23
+ RUN mkdir -p /home/user/app/model_cache \
24
+ && mkdir -p $HF_HUB_CACHE \
25
+ && chown -R user:user /home/user/app/model_cache $HF_HOME
26
+
27
+ # 6) Télécharger le modèle (build-time)
28
+ USER user
29
  RUN python - <<EOF
30
  from huggingface_hub import snapshot_download
31
  snapshot_download(
32
  repo_id="numind/NuExtract-1.5-tiny",
33
+ local_dir="/home/user/app/model_cache",
34
+ cache_dir="$HF_HUB_CACHE"
35
  )
36
  EOF
37
 
38
+ # 7) Copier le code et démarrer
39
+ COPY --chown=user . .
 
 
 
 
 
40
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]