# Single-stage build: Node + Python in one image (avoids multi-stage cache issues) FROM python:3.10-slim # Install Node.js 20 as root RUN apt-get update && apt-get install -y curl && \ curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ apt-get install -y nodejs && \ rm -rf /var/lib/apt/lists/* # Set up a new user named "user" with user ID 1000 (Required by Hugging Face Spaces) RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" WORKDIR /home/user/app # Install Python dependencies (cached separately) COPY --chown=user:user requirements.txt ./ RUN pip install --no-cache-dir --upgrade pip RUN pip install --no-cache-dir -r requirements.txt # Build React frontend (in same stage, no cross-stage cache issue) COPY --chown=user:user frontend/package*.json ./frontend/ RUN cd frontend && npm install --ignore-scripts COPY --chown=user:user frontend/ ./frontend/ RUN cd frontend && npm run build # Copy remaining project files (does NOT overwrite frontend/dist/) COPY --chown=user:user . . EXPOSE 7860 ENV TRANSFORMERS_CACHE="/home/user/app/.cache/huggingface" CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "7860"]