Spaces:
Sleeping
Sleeping
| # Dockerfile for Hugging Face Spaces (Next.js + FastAPI) | |
| # ----------------------------------------------------------------------------- | |
| # Stage 1: Build Frontend (Node.js) | |
| # ----------------------------------------------------------------------------- | |
| FROM node:20-alpine AS builder | |
| WORKDIR /app | |
| # Install dependencies | |
| COPY package.json package-lock.json* ./ | |
| RUN npm ci | |
| # Copy source code | |
| COPY . . | |
| # Build Next.js (Standalone output configured in next.config.js) | |
| ENV NEXT_TELEMETRY_DISABLED 1 | |
| RUN npm run build | |
| # ----------------------------------------------------------------------------- | |
| # Stage 2: Runtime (Python + Node.js) | |
| # ----------------------------------------------------------------------------- | |
| FROM python:3.11-slim AS runner | |
| # Install System Dependencies | |
| # - ffmpeg: For audio processing | |
| # - curl, gnupg: For installing Node.js | |
| RUN apt-get update && apt-get install -y \ | |
| ffmpeg \ | |
| libsndfile1 \ | |
| curl \ | |
| gnupg \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Install Node.js 20 (LTS) | |
| RUN mkdir -p /etc/apt/keyrings | |
| RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg | |
| ENV NODE_MAJOR=20 | |
| RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list | |
| RUN apt-get update && apt-get install -y nodejs | |
| # Set up Python Environment | |
| WORKDIR /app | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| ENV PYTHONUNBUFFERED=1 | |
| # Install Python Dependencies | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # Copy Backend Source | |
| COPY backend/ backend/ | |
| # Copy Frontend Build Artifacts from Builder | |
| # We copy the standalone server and the static assets | |
| COPY --from=builder /app/.next/standalone ./ | |
| COPY --from=builder /app/.next/static ./.next/static | |
| COPY --from=builder /app/public ./public | |
| # Copy Entry Point | |
| COPY app.py . | |
| # Create necessary temp directories for the application if needed | |
| RUN mkdir -p /tmp/daw_audio_processing | |
| # Create a non-root user for security (Optional but recommended for HF Spaces) | |
| RUN useradd -m -u 1000 user | |
| RUN chown -R user:user /app | |
| USER user | |
| # Expose the port HF Spaces expects | |
| EXPOSE 7860 | |
| # Run the application manager | |
| CMD ["python", "app.py"] | |