# Local development Dockerfile (avoids CI-only build metadata files)
FROM python:3.14.1 AS builder

WORKDIR /app

COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt

FROM python:3.14.1-slim

WORKDIR /app

COPY --from=builder /usr/local/lib/python3.14/site-packages /usr/local/lib/python3.14/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin

# Install system-level OCR tools required for local OCR workflows:
#   tesseract-ocr   – OCR engine used by pytesseract and ocrmypdf
#   ghostscript     – required by ocrmypdf for PDF/PS operations
#   poppler-utils   – provides pdfinfo/pdftoppm used by pdf2image
#   unpaper         – optional deskewing pre-processor used by ocrmypdf
RUN apt-get update && apt-get install -y --no-install-recommends \
        tesseract-ocr \
        ghostscript \
        poppler-utils \
        unpaper \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

COPY ./app /app/app
COPY ./frontend /app/frontend
COPY ./migrations /app/migrations
COPY ./alembic.ini /app/alembic.ini
COPY ./LICENSE /app/LICENSE
COPY ./VERSION /app/VERSION
COPY ./BUILD_DATE /app/BUILD_DATE

# Local fallbacks for build metadata
RUN echo "local" > /app/GIT_SHA \
    && echo "local" > /app/RUNTIME_INFO

RUN mkdir -p /app/runtime_info
RUN mkdir -p /workdir

ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1

EXPOSE 8000

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
