Spaces:
Running
Running
| # Stage 1: Build Frontend | |
| FROM node:20-slim AS frontend-builder | |
| WORKDIR /app/frontend | |
| COPY frontend/package*.json ./ | |
| RUN npm install | |
| COPY frontend/ ./ | |
| RUN npm run build | |
| # Stage 2: Final Image | |
| FROM python:3.11-slim | |
| # Create a non-root user | |
| RUN useradd -m -u 1000 user | |
| # Install Node.js | |
| 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/* | |
| WORKDIR /app | |
| # Install Python dependencies | |
| COPY backend/requirements.txt ./backend/ | |
| RUN pip install --no-cache-dir -r backend/requirements.txt | |
| # Pre-download rembg models | |
| ENV U2NET_HOME=/app/.u2net | |
| RUN mkdir -p /app/.u2net && \ | |
| python3 -c "from rembg import new_session; new_session('u2net')" && \ | |
| chown -R user:user /app/.u2net | |
| # Copy backend code | |
| COPY backend/ ./backend/ | |
| # Copy built frontend | |
| COPY --from=frontend-builder /app/frontend/.next ./frontend/.next | |
| COPY --from=frontend-builder /app/frontend/public ./frontend/public | |
| COPY --from=frontend-builder /app/frontend/package*.json ./frontend/ | |
| COPY --from=frontend-builder /app/frontend/next.config.ts ./frontend/ | |
| COPY --from=frontend-builder /app/frontend/node_modules ./frontend/node_modules | |
| # Copy startup script | |
| COPY scripts/start_hf.sh ./scripts/start_hf.sh | |
| RUN chmod +x ./scripts/start_hf.sh && chown user:user ./scripts/start_hf.sh | |
| # Ensure permissions | |
| RUN chown -R user:user /app | |
| USER user | |
| EXPOSE 7860 | |
| CMD ["./scripts/start_hf.sh"] | |