Spaces:
Build error
Build error
| # ---- Frontend build stage (React -> static files) ---- | |
| FROM node:20-slim AS frontend | |
| WORKDIR /frontend | |
| # Copy only manifest first for layer caching | |
| COPY frontend/package*.json ./ | |
| RUN npm ci | |
| COPY frontend/ ./ | |
| # Produces /frontend/dist (Vite) — change to build/ if you use CRA | |
| RUN npm run build | |
| # ---- Runtime stage (CUDA for imaging models on T4) ---- | |
| FROM nvidia/cuda:12.4.1-cudnn-runtime-ubuntu22.04 | |
| # System deps as root BEFORE creating the non-root user | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| python3.11 python3-pip python3.11-venv \ | |
| build-essential curl git ffmpeg libgl1 libglib2.0-0 \ | |
| && rm -rf /var/lib/apt/lists/* | |
| RUN ln -sf /usr/bin/python3.11 /usr/bin/python | |
| # Spaces runs your container as UID 1000 — create the matching user | |
| RUN useradd -m -u 1000 user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH \ | |
| # Model/cache dir. Ephemeral on free tier — fine, models re-download on boot. | |
| HF_HOME=/home/user/.cache/huggingface \ | |
| PYTHONUNBUFFERED=1 | |
| WORKDIR /app | |
| # Python deps (do NOT run any GPU/nvidia-smi command here — no GPU at build time) | |
| COPY --chown=user requirements.txt ./ | |
| RUN pip install --no-cache-dir --upgrade pip \ | |
| && pip install --no-cache-dir -r requirements.txt | |
| # App code | |
| COPY --chown=user backend/ ./backend/ | |
| COPY --chown=user startup.sh ./startup.sh | |
| # Built React static files from stage 1 | |
| COPY --chown=user --from=frontend /frontend/dist ./static | |
| RUN chmod +x ./startup.sh && chown -R user:user /app | |
| USER user | |
| # Spaces exposes a single public port; must match app_port in README | |
| EXPOSE 7860 | |
| CMD ["./startup.sh"] | |