AthanasiusRG commited on
Commit
8984a6a
·
verified ·
1 Parent(s): deaa594

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -21
Dockerfile CHANGED
@@ -1,14 +1,13 @@
1
  FROM python:3.10-slim
2
 
3
- # 1. Configuration du répertoire de travail principal
4
- WORKDIR /home/user/app
5
-
6
- # Env vars pour brider le CPU et la mémoire en cas de fallback de compilation
7
- ENV CMAKE_BUILD_PARALLEL_LEVEL=1
8
- ENV MAKEFLAGS="-j1"
9
- ENV PYTHONUNBUFFERED=1
10
-
11
- # 2. Installation des outils système essentiels
12
  RUN apt-get update && apt-get install -y \
13
  build-essential \
14
  cmake \
@@ -16,23 +15,25 @@ RUN apt-get update && apt-get install -y \
16
  curl \
17
  && rm -rf /var/lib/apt/lists/*
18
 
19
- # 3. Création de l'utilisateur non-privilégié imposé par Hugging Face (ID 1000)
 
 
 
 
 
20
  RUN useradd -m -u 1000 user
21
- USER user
22
- ENV HOME=/home/user
23
- ENV PATH=/home/user/.local/bin:$PATH
24
 
25
- WORKDIR $HOME/app
 
26
 
27
- # 4. Installation des dépendances Python (Zéro compilation CPU grâce à l'index d'abetlen)
28
- RUN pip install --no-cache-dir --user fastapi uvicorn huggingface_hub pydantic
29
- RUN pip install --no-cache-dir --user llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
30
 
31
- # 5. Copie du code avec les bonnes permissions utilisateur
32
- COPY --chown=user . .
33
 
34
- # Déclaration du port imposé par Hugging Face Spaces
35
  EXPOSE 7860
36
 
37
- # 6. Commande de démarrage bloquante au premier plan (évite le Runtime Exit 0)
38
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  FROM python:3.10-slim
2
 
3
+ # 1. Dossier temporaire de build et variables d'environnement
4
+ WORKDIR /app
5
+ ENV PYTHONUNBUFFERED=1 \
6
+ PYTHONDONTWRITEBYTECODE=1 \
7
+ CMAKE_BUILD_PARALLEL_LEVEL=1 \
8
+ MAKEFLAGS="-j1"
9
+
10
+ # 2. Installation des outils système (en tant que root)
 
11
  RUN apt-get update && apt-get install -y \
12
  build-essential \
13
  cmake \
 
15
  curl \
16
  && rm -rf /var/lib/apt/lists/*
17
 
18
+ # 3. Installation globale des packages Python (en tant que root)
19
+ # Plus besoin de --user, c'est ultra-stable et isolé dans le conteneur
20
+ RUN pip install --no-cache-dir fastapi uvicorn huggingface_hub pydantic
21
+ RUN pip install --no-cache-dir llama-cpp-python --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
22
+
23
+ # 4. Création de l'utilisateur requis par Hugging Face (UID 1000)
24
  RUN useradd -m -u 1000 user
 
 
 
25
 
26
+ # 5. Configuration de son espace de travail
27
+ WORKDIR /home/user/app
28
 
29
+ # 6. Copie du code en lui attribuant directement la propriété des fichiers
30
+ COPY --chown=user:user . .
 
31
 
32
+ # 7. Passage sous l'utilisateur non-privilégié pour l'exécution
33
+ USER user
34
 
35
+ # Port Hugging Face
36
  EXPOSE 7860
37
 
38
+ # Lancement de l'API
39
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]