Spaces:
Build error
Build error
| # Multi-stage Dockerfile for Hugging Face Spaces | |
| # This combines both frontend and backend into a single container | |
| # Stage 1: Build frontend | |
| FROM node:20-alpine AS frontend-builder | |
| WORKDIR /app/frontend | |
| COPY frontend/package*.json ./ | |
| RUN npm ci | |
| COPY frontend/ ./ | |
| RUN npm run build | |
| # Stage 2: Setup backend with built frontend | |
| FROM python:3.11-slim | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| gcc \ | |
| nginx \ | |
| supervisor \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy and install backend requirements | |
| COPY backend/requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy backend code | |
| COPY backend/ ./backend/ | |
| # Copy built frontend to nginx directory | |
| COPY --from=frontend-builder /app/frontend/dist /usr/share/nginx/html | |
| # Create nginx configuration for Hugging Face Spaces | |
| RUN echo 'server { \n\ | |
| listen 7860; \n\ | |
| server_name localhost; \n\ | |
| \n\ | |
| location / { \n\ | |
| root /usr/share/nginx/html; \n\ | |
| try_files $uri $uri/ /index.html; \n\ | |
| } \n\ | |
| \n\ | |
| location /api { \n\ | |
| proxy_pass http://127.0.0.1:8000; \n\ | |
| proxy_http_version 1.1; \n\ | |
| proxy_set_header Upgrade $http_upgrade; \n\ | |
| proxy_set_header Connection "upgrade"; \n\ | |
| proxy_set_header Host $host; \n\ | |
| proxy_set_header X-Real-IP $remote_addr; \n\ | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \n\ | |
| proxy_set_header X-Forwarded-Proto $scheme; \n\ | |
| } \n\ | |
| }' > /etc/nginx/sites-available/default | |
| # Create supervisor configuration | |
| RUN echo '[supervisord] \n\ | |
| nodaemon=true \n\ | |
| \n\ | |
| [program:backend] \n\ | |
| command=python -m uvicorn backend.app.main:app --host 0.0.0.0 --port 8000 \n\ | |
| directory=/app \n\ | |
| autostart=true \n\ | |
| autorestart=true \n\ | |
| redirect_stderr=true \n\ | |
| stdout_logfile=/dev/stdout \n\ | |
| stdout_logfile_maxbytes=0 \n\ | |
| \n\ | |
| [program:nginx] \n\ | |
| command=nginx -g "daemon off;" \n\ | |
| autostart=true \n\ | |
| autorestart=true \n\ | |
| redirect_stderr=true \n\ | |
| stdout_logfile=/dev/stdout \n\ | |
| stdout_logfile_maxbytes=0' > /etc/supervisor/conf.d/supervisord.conf | |
| # Create data directory for SQLite | |
| RUN mkdir -p /app/data | |
| # Hugging Face Spaces expects port 7860 | |
| EXPOSE 7860 | |
| # Start both services with supervisor | |
| CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] |