# --- Étape 1 : Build du Frontend (Next.js) --- FROM node:20-slim AS frontend-builder WORKDIR /app/frontend COPY frontend/package*.json ./ RUN npm ci --quiet COPY frontend/ ./ ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 ENV NEXT_PUBLIC_API_URL=/api ENV NEXT_PUBLIC_DEMO_MODE=true RUN npm run build # --- Étape 2 : Runtime Final --- FROM python:3.11-slim # Installation des dépendances (Node, Caddy, Outils) RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ gcc \ gnupg \ debian-keyring \ debian-archive-keyring \ apt-transport-https \ && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ && apt-get install -y nodejs \ && curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg \ && curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list \ && apt-get update \ && apt-get install -y caddy \ && apt-get clean && rm -rf /var/lib/apt/lists/* WORKDIR /app # Backend - Installation des dépendances COPY backend/requirements.txt ./backend/ RUN pip install --no-cache-dir -r backend/requirements.txt aiosqlite uvicorn COPY backend/ ./backend/ # Frontend - Copie du build COPY --from=frontend-builder /app/frontend/.next ./frontend/.next COPY --from=frontend-builder /app/frontend/node_modules ./frontend/node_modules COPY --from=frontend-builder /app/frontend/package.json ./frontend/ COPY --from=frontend-builder /app/frontend/public ./frontend/public COPY --from=frontend-builder /app/frontend/next.config.js ./frontend/ # Configuration Hugging Face Space COPY Caddyfile /etc/caddy/Caddyfile COPY start.sh /app/start.sh COPY seed_demo.py /app/seed_demo.py RUN chmod +x /app/start.sh # Variables d'environnement critiques ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONPATH=/app ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 ENV PORT=7860 ENV DATABASE_URL=sqlite+aiosqlite:////app/data/tensorwall.db ENV ENVIRONMENT=demo ENV DEMO_MODE=true ENV DEBUG=false ENV JWT_SECRET_KEY=hf-demo-secret-key-change-this-for-prod ENV CORS_ORIGINS_RAW=* # Gestion des permissions pour l'utilisateur 1000 (Hugging Face) RUN mkdir -p /app/data && chmod -R 777 /app/data && \ chmod -R 755 /app/backend /app/frontend USER 1000 EXPOSE 7860 HEALTHCHECK --interval=30s --timeout=10s --start-period=180s --retries=5 \ CMD curl -sf http://localhost:7860/api/health/live || exit 1 CMD ["/app/start.sh"]