# Stage 1: Build Next.js frontend (standalone mode) FROM node:20-slim AS frontend-builder WORKDIR /app COPY package.json package-lock.json ./ RUN npm ci COPY . . RUN npm run build # Stage 2: Final runtime image FROM python:3.11-slim # System dependencies RUN apt-get update && apt-get install -y \ curl \ nodejs \ npm \ libgl1 \ libglib2.0-0 \ poppler-utils \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Copy full repo source (backend code, configs, etc.) COPY . . # Install Python backend dependencies WORKDIR /app/backend RUN pip install --no-cache-dir -r requirements.txt # Copy Next.js standalone build output WORKDIR /app COPY --from=frontend-builder /app/.next/standalone ./ COPY --from=frontend-builder /app/.next/static ./.next/static COPY --from=frontend-builder /app/public ./public # HuggingFace Spaces uses port 7860 EXPOSE 7860 # Copy and run entrypoint COPY docker-entrypoint.sh /docker-entrypoint.sh RUN chmod +x /docker-entrypoint.sh CMD ["/docker-entrypoint.sh"]