File size: 2,566 Bytes
f3bcb28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9049b1b
f3bcb28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# --- É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"]