FROM node:18 AS frontend-builder # Set working directory for frontend WORKDIR /app/frontend # Copy frontend package files and install dependencies COPY frontend/package*.json ./ RUN npm install # Copy frontend source code and build COPY frontend/ . RUN npm run build # Start with Python base image for final stage FROM python:3.9-slim WORKDIR /app # Install system dependencies and Node.js RUN apt-get update && apt-get install -y \ curl \ && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ && apt-get install -y nodejs \ && rm -rf /var/lib/apt/lists/* # Create necessary directories and set permissions RUN mkdir -p ./figures ./pdfs ./src/processed_markdown \ && chown -R 1000:1000 /app # Create a user with ID 1000 (required for Hugging Face Spaces) RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ PYTHONPATH=/app # Copy and install Python requirements COPY --chown=user requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy frontend build from previous stage COPY --chown=user --from=frontend-builder /app/frontend/.next ./.next COPY --chown=user --from=frontend-builder /app/frontend/public ./public COPY --chown=user --from=frontend-builder /app/frontend/package*.json ./ # Copy backend code COPY --chown=user src/ ./src/ # Install frontend production dependencies RUN npm install --production # Copy start script COPY --chown=user start.sh ./ RUN chmod +x start.sh # Start both services CMD ["./start.sh"]