# Multi-stage build for better optimization FROM node:18-alpine AS frontend-builder WORKDIR /app/frontend # Copy package files COPY frontend/package*.json ./ # Clear npm cache and install dependencies RUN npm cache clean --force && \ (npm ci --no-audit --no-fund || npm install --no-audit --no-fund) # Copy frontend source code COPY frontend/ ./ # Build the frontend RUN npm run build # Python backend stage FROM python:3.11-slim AS backend # Install system dependencies RUN apt-get update && apt-get install -y \ gcc \ g++ \ curl \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Copy and install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY . . # Copy built frontend from previous stage COPY --from=frontend-builder /app/frontend/build ./frontend/build # Set environment variables for containerized environments ENV PORT=7860 ENV HOST=0.0.0.0 ENV FLASK_ENV=production ENV PYTHONPATH=/app # Hugging Face Spaces typically expects the app to be on port 7860 or the PORT env var EXPOSE 7860 # Use our startup script which ensures directories are properly configured CMD ["python", "startup_hf.py"]