Spaces:
Running
Running
| # ============================================================ | |
| # InnerVoice — Hugging Face Spaces Docker Deployment | |
| # ============================================================ | |
| # ---------- Stage 1: Build the Next.js frontend ---------- | |
| FROM node:20-slim AS frontend_builder | |
| WORKDIR /build/frontend | |
| COPY frontend/package*.json ./ | |
| RUN npm ci --no-audit --no-fund | |
| COPY frontend/ ./ | |
| RUN npm run build | |
| # ---------- Stage 2: Final runtime ---------- | |
| FROM python:3.10-slim | |
| # Copy Node.js binaries from official node image (no apt needed) | |
| COPY --from=node:20-slim /usr/local/bin /usr/local/bin | |
| COPY --from=node:20-slim /usr/local/lib/node_modules /usr/local/lib/node_modules | |
| # Install only system-level deps | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| ffmpeg \ | |
| libsndfile1 \ | |
| build-essential \ | |
| git \ | |
| curl \ | |
| && apt-get clean \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # HF Spaces user | |
| RUN useradd -m -u 1000 user | |
| ENV HOME=/home/user | |
| ENV PATH=$HOME/.local/bin:$PATH | |
| WORKDIR $HOME/app | |
| RUN chown -R user:user $HOME | |
| USER user | |
| # Python deps (CPU-only PyTorch) | |
| COPY --chown=user:user backend/requirements.txt ./backend/ | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir \ | |
| -r backend/requirements.txt \ | |
| --extra-index-url https://download.pytorch.org/whl/cpu | |
| # Copy pre-built frontend from Stage 1 | |
| COPY --from=frontend_builder --chown=user:user /build/frontend/.next ./frontend/.next | |
| COPY --from=frontend_builder --chown=user:user /build/frontend/node_modules ./frontend/node_modules | |
| COPY --from=frontend_builder --chown=user:user /build/frontend/package.json ./frontend/package.json | |
| COPY --from=frontend_builder --chown=user:user /build/frontend/public ./frontend/public | |
| COPY --from=frontend_builder --chown=user:user /build/frontend/next.config.mjs ./frontend/next.config.mjs | |
| # Copy backend | |
| COPY --chown=user:user backend/ ./backend/ | |
| # Entrypoint | |
| COPY --chown=user:user start.sh ./ | |
| RUN chmod +x start.sh | |
| EXPOSE 7860 | |
| CMD ["./start.sh"] | |