Spaces:
Sleeping
Sleeping
| # Hugging Face Spaces Dockerfile | |
| # Multi-stage build for Hugging Face deployment | |
| # Stage 1: Build frontend | |
| FROM node:20-alpine AS frontend-builder | |
| WORKDIR /app/frontend | |
| # Copy package files | |
| COPY frontend/package*.json ./ | |
| # Install dependencies | |
| RUN npm ci | |
| # Copy frontend source | |
| COPY frontend/ ./ | |
| # Build arguments for environment variables | |
| # Hugging Face Spaces will provide the public URL | |
| ARG VITE_API_BASE_URL | |
| ENV VITE_API_BASE_URL=${VITE_API_BASE_URL} | |
| # Build frontend | |
| RUN npm run build | |
| # Stage 2: Python backend with frontend | |
| FROM python:3.11-slim | |
| # Set working directory | |
| WORKDIR /app | |
| # Install system dependencies including ffmpeg | |
| RUN apt-get update && \ | |
| apt-get install -y --no-install-recommends \ | |
| ffmpeg \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy requirements first for better caching | |
| COPY requirements.txt . | |
| # Install Python dependencies | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy application code | |
| COPY . . | |
| # Copy built frontend from builder stage | |
| COPY --from=frontend-builder /app/frontend/dist ./frontend/dist | |
| # Create storage directories | |
| RUN mkdir -p storage/images storage/videos | |
| # Hugging Face Spaces uses port 7860 by default | |
| # But we'll use PORT env var if provided, or default to 7860 | |
| EXPOSE 7860 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | |
| CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" | |
| # Run the application | |
| # Hugging Face Spaces provides PORT env var, default to 7860 | |
| CMD python -c "import os; port = int(os.getenv('PORT', 7860)); import uvicorn; uvicorn.run('main:app', host='0.0.0.0', port=port)" | |