# Build stage - install dependencies that require compilation FROM python:3.11-slim as builder ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 WORKDIR /app # Install build dependencies only RUN apt-get update && \ apt-get install -y --no-install-recommends \ build-essential \ curl \ && rm -rf /var/lib/apt/lists/* # Copy and install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir --user -r requirements.txt && \ pip cache purge # Download SpaCy English model RUN python -m spacy download en_core_web_sm # Runtime stage - minimal image with only runtime dependencies FROM python:3.11-slim ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PYTHONPATH=/app/src \ PATH=/root/.local/bin:$PATH \ MULTI_DOC_STORAGE_ROOT=/app/storage \ MULTI_DOC_CLAUDE_MODEL=claude-3-5-haiku-latest \ CLAUDE_MODEL=claude-3-5-haiku-latest \ PORT=8024 WORKDIR /app # Install only runtime dependencies (no build tools) RUN apt-get update && \ apt-get install -y --no-install-recommends \ poppler-utils \ tesseract-ocr \ ffmpeg \ libmagic1 \ curl \ # Required for some Python packages at runtime libgomp1 \ libglib2.0-0 \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean # Copy Python packages from builder stage (includes spacy model) COPY --from=builder /root/.local /root/.local # Copy application code COPY src ./src EXPOSE 8024 CMD ["sh", "-c", "uvicorn multi_document_upload_service.main:app --host 0.0.0.0 --port ${PORT:-8024}"]