Spaces:
Sleeping
Sleeping
| # --- Étape 1 : Build de l'application React --- | |
| FROM node:20-slim AS build-stage | |
| WORKDIR /app | |
| COPY package*.json ./ | |
| RUN npm install | |
| COPY . . | |
| RUN npm run build | |
| # --- Étape 2 : Serveur Nginx --- | |
| FROM nginx:stable-alpine | |
| # Création de l'utilisateur 1000 (requis par HF) | |
| RUN adduser -D -u 1000 user | |
| # On remplace la configuration globale de Nginx pour : | |
| # 1. Déplacer le fichier PID vers /tmp (accessible à l'utilisateur 1000) | |
| # 2. Configurer tous les dossiers temporaires dans /tmp | |
| # 3. Écouter sur le port 7860 | |
| RUN printf 'worker_processes 1;\n\ | |
| pid /tmp/nginx.pid;\n\ | |
| events { worker_connections 1024; }\n\ | |
| http {\n\ | |
| include /etc/nginx/mime.types;\n\ | |
| client_body_temp_path /tmp/client_temp;\n\ | |
| proxy_temp_path /tmp/proxy_temp;\n\ | |
| fastcgi_temp_path /tmp/fastcgi_temp;\n\ | |
| uwsgi_temp_path /tmp/uwsgi_temp;\n\ | |
| scgi_temp_path /tmp/scgi_temp;\n\ | |
| server {\n\ | |
| listen 7860;\n\ | |
| location / {\n\ | |
| root /usr/share/nginx/html;\n\ | |
| index index.html;\n\ | |
| try_files $uri $uri/ /index.html;\n\ | |
| }\n\ | |
| }\n\ | |
| }' > /etc/nginx/nginx.conf | |
| # Copie des fichiers de build | |
| COPY --from=build-stage /app/dist /usr/share/nginx/html | |
| # Ajustement des permissions pour l'utilisateur 1000 | |
| RUN chown -R user:user /usr/share/nginx/html /etc/nginx /var/log/nginx /var/cache/nginx && \ | |
| chmod -R 777 /tmp | |
| USER user | |
| EXPOSE 7860 | |
| CMD ["nginx", "-g", "daemon off;"] |