diff --git a/Dockerfile b/Dockerfile index bbfbe36..a18a14c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ # syntax=docker/dockerfile:1 # ============================================================================= -# Docling Studio — single-image build (frontend + backend) +# Docling Studio — single-image build (frontend + backend, multi-target) # # Usage: -# docker build -t docling-studio . -# docker run -p 3000:3000 docling-studio +# docker build --target remote -t docling-studio:remote . +# docker build --target local -t docling-studio:local . # ============================================================================= # --- Stage 1: Build frontend assets --- @@ -18,21 +18,19 @@ RUN npm ci COPY frontend/ . RUN VITE_APP_VERSION=${APP_VERSION} npm run build -# --- Stage 2: Runtime (Python + Nginx) --- -FROM python:3.12-slim +# --- Stage 2: Base runtime (Python + Nginx) --- +FROM python:3.12-slim AS base ARG APP_VERSION=dev ENV APP_VERSION=${APP_VERSION} -# System deps: poppler (pdf2image), nginx, and OpenCV runtime libs +# System deps: poppler (pdf2image), nginx RUN apt-get update && apt-get install -y --no-install-recommends \ poppler-utils \ - libgl1 \ - libglib2.0-0 \ nginx \ && rm -rf /var/lib/apt/lists/* -# Python deps +# Python deps (common) WORKDIR /app COPY document-parser/requirements.txt . RUN pip install --no-cache-dir -r requirements.txt @@ -57,5 +55,22 @@ ENV DB_PATH=/app/data/docling_studio.db EXPOSE 3000 -# nginx needs to run as root for port binding, then drops to appuser for uvicorn CMD ["sh", "-c", "nginx && exec su appuser -c 'uvicorn main:app --host 127.0.0.1 --port 8000'"] + +# --- Remote: lightweight, delegates to Docling Serve --- +FROM base AS remote +ENV CONVERSION_ENGINE=remote + +# --- Local: full Docling in-process --- +FROM base AS local + +RUN apt-get update && apt-get install -y --no-install-recommends \ + libgl1 \ + libglib2.0-0 \ + && rm -rf /var/lib/apt/lists/* + +COPY document-parser/requirements-local.txt . +RUN pip install --no-cache-dir -r requirements-local.txt + +RUN chown -R appuser:appuser /app +ENV CONVERSION_ENGINE=local diff --git a/docker-compose.yml b/docker-compose.yml index 6e75d5e..f1f80aa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,7 @@ services: document-parser: build: context: ./document-parser + target: ${CONVERSION_MODE:-local} expose: - "8000" volumes: @@ -9,6 +10,8 @@ services: - db_data:/app/data environment: CORS_ORIGINS: ${CORS_ORIGINS:-http://localhost:3000,http://localhost:5173} + DOCLING_SERVE_URL: ${DOCLING_SERVE_URL:-} + DOCLING_SERVE_API_KEY: ${DOCLING_SERVE_API_KEY:-} deploy: resources: limits: diff --git a/document-parser/Dockerfile b/document-parser/Dockerfile index 76cc697..a9c3b17 100644 --- a/document-parser/Dockerfile +++ b/document-parser/Dockerfile @@ -1,9 +1,17 @@ -FROM python:3.12-slim +# syntax=docker/dockerfile:1 +# ============================================================================= +# Docling Studio — backend image (multi-target: remote / local) +# +# Usage: +# docker build --target remote -t docling-studio-backend:remote . +# docker build --target local -t docling-studio-backend:local . +# ============================================================================= + +# --- Base: common deps for both targets --- +FROM python:3.12-slim AS base RUN apt-get update && apt-get install -y --no-install-recommends \ poppler-utils \ - libgl1 \ - libglib2.0-0 \ && rm -rf /var/lib/apt/lists/* WORKDIR /app @@ -24,3 +32,23 @@ ENV DB_PATH=/app/data/docling_studio.db USER appuser CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] + +# --- Remote: lightweight, delegates to Docling Serve --- +FROM base AS remote +ENV CONVERSION_ENGINE=remote + +# --- Local: full Docling in-process --- +FROM base AS local + +USER root +RUN apt-get update && apt-get install -y --no-install-recommends \ + libgl1 \ + libglib2.0-0 \ + && rm -rf /var/lib/apt/lists/* + +COPY requirements-local.txt . +RUN pip install --no-cache-dir -r requirements-local.txt + +RUN chown -R appuser:appuser /app +USER appuser +ENV CONVERSION_ENGINE=local