-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (52 loc) · 2.4 KB
/
Copy pathDockerfile
File metadata and controls
68 lines (52 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Stage 1: Build frontend
FROM node:20-alpine AS frontend-builder
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm install
COPY frontend/ ./
RUN npm run build
# Stage 2: Build Python dependencies (compilers live here, not in the runtime image)
FROM python:3.12-slim AS backend-builder
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*
COPY backend/requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
# Stage 3: Runtime base shared by both variants (no build toolchain)
FROM python:3.12-slim AS runtime-base
WORKDIR /app
# `unar` provides RAR extraction for rarfile (used to render .cbr cover
# thumbnails); without it .cbr archives are still served, just without a cover.
RUN apt-get update && apt-get install -y --no-install-recommends \
unar \
&& rm -rf /var/lib/apt/lists/*
# Bring in the pre-built Python packages from the builder stage.
COPY --from=backend-builder /install /usr/local
COPY backend/ ./backend/
COPY alembic.ini ./alembic.ini
COPY --from=frontend-builder /app/frontend/dist ./frontend/dist
RUN mkdir -p /data /library
ARG APP_VERSION=dev
ARG COMMIT_HASH="dev"
ENV APP_VERSION=${APP_VERSION}
ENV COMMIT_HASH=${COMMIT_HASH}
ENV PYTHONUNBUFFERED=1
EXPOSE 9481
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
CMD python -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:9481/api/health', timeout=4).status == 200 else 1)" || exit 1
ENV WORKERS=2
CMD ["sh", "-c", "exec python -m uvicorn backend.main:app --host 0.0.0.0 --port 9481 --workers ${WORKERS}"]
# Stage 4a: Slim variant — no OCR engine. Grimoire degrades gracefully: image-only
# PDFs stay excluded from full-text search, exactly as before OCR was added. Built
# with `--target slim` and published under the `-slim` tag family.
FROM runtime-base AS slim
# Stage 4b: Default variant — bundles Tesseract + English language data so image-only
# PDFs are OCR'd into the full-text index out of the box. Extra languages can be added
# at runtime by mounting tessdata and setting OCR_LANGUAGES (see README); no rebuild
# required. This is the last stage, so a plain `docker build` (no --target) yields it.
FROM runtime-base AS ocr
RUN apt-get update && apt-get install -y --no-install-recommends \
tesseract-ocr \
tesseract-ocr-eng \
&& rm -rf /var/lib/apt/lists/*