mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2026-09-03 05:10:16 +03:00
217 lines
11 KiB
Docker
217 lines
11 KiB
Docker
# syntax=docker/dockerfile:1
|
|
|
|
# Stirling-PDF - Fat version (embedded frontend)
|
|
# Extra fonts for air-gapped environments
|
|
# Uses pre-built base image for fast builds
|
|
|
|
ARG BASE_VERSION=1.0.2@sha256:c7698687f486707ddef9e0298587ca8b44c4e96185e1bdb0c3d119eb2bf9a82e
|
|
ARG BASE_IMAGE=stirlingtools/stirling-pdf-base:${BASE_VERSION}
|
|
|
|
# Stage 1: Build the Java application and frontend
|
|
FROM gradle:9.7.1-jdk25@sha256:d868117760a7c92214705f47ed173116a5d13e58d68702f974ff30acd062737e AS app-build
|
|
|
|
ARG TASK_VERSION=3.52.0
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends curl ca-certificates \
|
|
&& update-ca-certificates \
|
|
&& curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
|
|
&& apt-get install -y --no-install-recommends nodejs \
|
|
&& ARCH=$(dpkg --print-architecture) \
|
|
&& curl -fsSL "https://github.com/go-task/task/releases/download/v${TASK_VERSION}/task_${TASK_VERSION}_linux_${ARCH}.deb" -o /tmp/task.deb \
|
|
&& dpkg -i /tmp/task.deb \
|
|
&& rm /tmp/task.deb \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Bake an Auto Form Detection model into this air-gapped image, seeded into the writable configs
|
|
# model dir at startup. This is the one image where baking earns its cost: it is the deployment
|
|
# that cannot download a model later. The internet-connected images leave it to an admin install.
|
|
#
|
|
# Only weights we hold a redistribution grant for may go here - which the FFDNet checkpoints are
|
|
# not, as their publisher declares no licence at all. FFDetr is Apache-2.0 end to end, so it is
|
|
# the default: our own int8 export from scripts/export-ffdetr-onnx.py, pinned to a revision SHA.
|
|
# Costs ~27MB of pull and ~37MB on disk. Keep these three in step with the ffdetr entry in
|
|
# model-catalog.json - a mismatch fails the build at the sha256sum check below, by design.
|
|
ARG FORM_DETECTION_MODEL_URL="https://huggingface.co/Frooodle/ffdetr-int8/resolve/ad3223d7c3ae25ce1d1ec8fe972c8ff7630aff45/ffdetr-int8.onnx"
|
|
ARG FORM_DETECTION_MODEL_SHA256="de43bb39adb08459fe62fa1a7be6bfb4f2d397bb034c46055f3b8fa3d04fc8f4"
|
|
ARG FORM_DETECTION_MODEL_ID="ffdetr"
|
|
RUN mkdir -p /preinstalled-models \
|
|
&& if [ -n "${FORM_DETECTION_MODEL_URL}" ]; then \
|
|
curl -fSL "${FORM_DETECTION_MODEL_URL}" -o "/preinstalled-models/${FORM_DETECTION_MODEL_ID}.onnx" \
|
|
&& echo "${FORM_DETECTION_MODEL_SHA256} /preinstalled-models/${FORM_DETECTION_MODEL_ID}.onnx" | sha256sum -c -; \
|
|
else \
|
|
echo "No form-detection model pre-bundled (FORM_DETECTION_MODEL_URL unset)"; \
|
|
fi
|
|
|
|
# JDK 25+: --add-exports is no longer accepted via JAVA_TOOL_OPTIONS; use JDK_JAVA_OPTIONS instead
|
|
ENV JDK_JAVA_OPTIONS="--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
|
|
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
|
|
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
|
|
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
|
|
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
|
|
|
|
WORKDIR /app
|
|
|
|
COPY build.gradle settings.gradle gradlew ./
|
|
COPY gradle/ gradle/
|
|
COPY buildSrc/build.gradle buildSrc/
|
|
COPY buildSrc/src/main/ buildSrc/src/main/
|
|
COPY app/core/build.gradle app/core/
|
|
COPY app/common/build.gradle app/common/
|
|
COPY app/proprietary/build.gradle app/proprietary/
|
|
|
|
# Use system gradle instead of gradlew to avoid SSL issues downloading gradle distribution on emulated arm64
|
|
RUN --mount=type=cache,id=stirling-pdf-gradle-cache,target=/home/gradle/.gradle,sharing=locked \
|
|
gradle dependencies --no-daemon || true
|
|
|
|
COPY . .
|
|
|
|
# Embed the admin portal app at /portal when the deploy workflow flags it.
|
|
ARG BUILD_PORTAL=false
|
|
# Bundle only the JPDFium native for this image's target arch.
|
|
ARG TARGETARCH
|
|
RUN --mount=type=cache,id=stirling-pdf-npm-cache,target=/root/.npm,sharing=locked \
|
|
--mount=type=cache,id=stirling-pdf-gradle-cache,target=/home/gradle/.gradle,sharing=locked \
|
|
JPDFIUM_PLATFORM="$([ "$TARGETARCH" = arm64 ] && echo linux-arm64 || echo linux-x64)" && \
|
|
DISABLE_ADDITIONAL_FEATURES=false \
|
|
gradle clean build \
|
|
-PbuildWithFrontend=true \
|
|
-PbundleOnnxRuntime=true \
|
|
-PbuildWithPortal=${BUILD_PORTAL} \
|
|
-PjpdfiumPlatforms="$JPDFIUM_PLATFORM" \
|
|
-x spotlessApply -x spotlessCheck -x test -x sonarqube \
|
|
--no-daemon
|
|
|
|
# Stage 2: Extract Spring Boot Layers
|
|
FROM eclipse-temurin:25-jre-noble@sha256:fbcf915c585659b30eb766ada4d6d7cfc9ec1040bf521e95bf61b10a25af73db AS jar-extract
|
|
WORKDIR /tmp
|
|
COPY --from=app-build /app/app/core/build/libs/*.jar app.jar
|
|
RUN java -Djarmode=tools -jar app.jar extract --layers --destination /layers
|
|
|
|
# Slim the bundled ONNX Runtime (included only via -PbundleOnnxRuntime above) to the target Linux
|
|
# arch (~42MB jar -> ~8MB). Docker server image only; desktop/local builds don't bundle it at all.
|
|
COPY scripts/slim-onnxruntime.sh /tmp/slim-onnxruntime.sh
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends zip \
|
|
&& rm -rf /var/lib/apt/lists/* \
|
|
&& sh /tmp/slim-onnxruntime.sh /layers/dependencies
|
|
|
|
|
|
# Stage 2b: AI engine. Built at its final path so the venv resolves after the copy, on uv's
|
|
# managed CPython because the runtime base ships Python 3.12.
|
|
FROM ghcr.io/astral-sh/uv:bookworm-slim@sha256:22334efe746f1b69217d455049b484d7b8cacfb2d5f42555580b62415a98e0a3 AS engine-build
|
|
ENV UV_PYTHON_INSTALL_DIR=/opt/stirling-engine/python
|
|
WORKDIR /opt/stirling-engine
|
|
COPY engine/pyproject.toml engine/uv.lock ./
|
|
# One layer: trimming in a second RUN would cache the untrimmed copy too, and this build
|
|
# exports every layer to a GHA cache that is capped repo-wide. Trimming saves ~20MB.
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
set -eux; \
|
|
apt-get update && apt-get install -y --no-install-recommends binutils; \
|
|
uv python install 3.13; \
|
|
uv sync --frozen --no-dev --no-install-project --group engine --python-preference only-managed; \
|
|
P="$(ls -d /opt/stirling-engine/python/cpython-*)"; \
|
|
rm -rf "$P/share" "$P/include" \
|
|
"$P/lib/python3.13/idlelib" "$P/lib/python3.13/tkinter" \
|
|
"$P/lib/python3.13/ensurepip" "$P/lib/python3.13/pydoc_data" \
|
|
"$P/lib/python3.13/test" "$P/lib/python3.13/lib2to3"; \
|
|
find /opt/stirling-engine -name '__pycache__' -type d -prune -exec rm -rf {} + ; \
|
|
find /opt/stirling-engine \( -name '*.so' -o -name '*.so.*' \) -print0 \
|
|
| xargs -0 -r strip --strip-unneeded 2>/dev/null || true; \
|
|
apt-get purge -y binutils; apt-get autoremove -y; rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
# Stage 3: Final runtime image on top of pre-built base
|
|
FROM ${BASE_IMAGE}
|
|
|
|
ARG VERSION_TAG
|
|
|
|
WORKDIR /app
|
|
|
|
# Application layers
|
|
COPY --link --from=jar-extract --chown=1000:1000 /layers/dependencies/ /app/
|
|
COPY --link --from=jar-extract --chown=1000:1000 /layers/spring-boot-loader/ /app/
|
|
COPY --link --from=jar-extract --chown=1000:1000 /layers/snapshot-dependencies/ /app/
|
|
COPY --link --from=jar-extract --chown=1000:1000 /layers/application/ /app/
|
|
|
|
COPY --link --from=app-build --chown=1000:1000 \
|
|
/app/build/libs/restart-helper.jar /restart-helper.jar
|
|
COPY --link --chown=1000:1000 scripts/ /scripts/
|
|
|
|
# init-without-ocr.sh starts the engine when this directory exists, so other images are unaffected.
|
|
COPY --link --from=engine-build --chown=1000:1000 /opt/stirling-engine/python /opt/stirling-engine/python
|
|
COPY --link --from=engine-build --chown=1000:1000 /opt/stirling-engine/.venv /opt/stirling-engine/.venv
|
|
COPY --link --chown=1000:1000 engine/.env /opt/stirling-engine/.env
|
|
COPY --link --chown=1000:1000 engine/src/ /opt/stirling-engine/src/
|
|
|
|
# Pre-bundled default detection model; FormDetectionModelManager seeds it into /configs on startup.
|
|
COPY --link --from=app-build --chown=1000:1000 /preinstalled-models/ /opt/stirling/preinstalled-models/
|
|
|
|
# Fonts go to system dir, root ownership is correct (world-readable)
|
|
COPY app/core/src/main/resources/static/fonts/*.ttf /usr/share/fonts/truetype/
|
|
|
|
# Permissions and configuration
|
|
RUN set -eux; \
|
|
chmod +x /scripts/*; \
|
|
ln -s /logs /app/logs; \
|
|
ln -s /configs /app/configs; \
|
|
ln -s /customFiles /app/customFiles; \
|
|
ln -s /pipeline /app/pipeline; \
|
|
ln -s /storage /app/storage; \
|
|
chown -h stirlingpdfuser:stirlingpdfgroup /app/logs /app/configs /app/customFiles /app/pipeline /app/storage; \
|
|
chown stirlingpdfuser:stirlingpdfgroup /app; \
|
|
mkdir -p /opt/stirling-engine/data; \
|
|
chown -R stirlingpdfuser:stirlingpdfgroup /opt/stirling-engine/data; \
|
|
chmod 750 /tmp/stirling-pdf; \
|
|
chmod 750 /tmp/stirling-pdf/heap_dumps; \
|
|
fc-cache -f
|
|
|
|
# Write version to a file so it is readable by scripts without env-var inheritance.
|
|
RUN echo "${VERSION_TAG:-dev}" > /etc/stirling_version
|
|
|
|
# Environment variables
|
|
ENV VERSION_TAG=$VERSION_TAG \
|
|
FORMDETECTION_PREINSTALLEDMODELDIR="/opt/stirling/preinstalled-models" \
|
|
STIRLING_AOT_ENABLE="false" \
|
|
STIRLING_JVM_PROFILE="balanced" \
|
|
_JVM_OPTS_BALANCED="-XX:+ExitOnOutOfMemoryError -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/configs/heap_dumps -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:G1HeapRegionSize=4m -XX:G1PeriodicGCInterval=60000 -XX:+UseStringDeduplication -XX:+UseCompactObjectHeaders -XX:+ExplicitGCInvokesConcurrent -Dspring.threads.virtual.enabled=true -Djava.awt.headless=true" \
|
|
_JVM_OPTS_PERFORMANCE="-XX:+ExitOnOutOfMemoryError -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/configs/heap_dumps -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -XX:+UseCompactObjectHeaders -XX:+UseStringDeduplication -XX:+AlwaysPreTouch -XX:+ExplicitGCInvokesConcurrent -Dspring.threads.virtual.enabled=true -Djava.awt.headless=true" \
|
|
JAVA_CUSTOM_OPTS="" \
|
|
HOME=/home/stirlingpdfuser \
|
|
PUID=1000 \
|
|
PGID=1000 \
|
|
UMASK=022 \
|
|
FAT_DOCKER=true \
|
|
AIENGINE_ENABLED=true \
|
|
STIRLING_ENGINE_HOME=/opt/stirling-engine \
|
|
STIRLING_ENGINE_PORT=5001 \
|
|
STIRLING_ENGINE_WORKERS=2 \
|
|
INSTALL_BOOK_AND_ADVANCED_HTML_OPS=false \
|
|
STIRLING_TEMPFILES_DIRECTORY=/tmp/stirling-pdf \
|
|
TMPDIR=/tmp/stirling-pdf \
|
|
TEMP=/tmp/stirling-pdf \
|
|
TMP=/tmp/stirling-pdf \
|
|
DBUS_SESSION_BUS_ADDRESS=/dev/null \
|
|
SAL_TMP=/tmp/stirling-pdf/libre
|
|
|
|
# Metadata labels
|
|
LABEL org.opencontainers.image.title="Stirling-PDF Fat" \
|
|
org.opencontainers.image.description="Fat version with extra fonts for air-gapped environments, includes Calibre, LibreOffice, Tesseract, OCRmyPDF" \
|
|
org.opencontainers.image.source="https://github.com/Stirling-Tools/Stirling-PDF" \
|
|
org.opencontainers.image.licenses="MIT" \
|
|
org.opencontainers.image.vendor="Stirling-Tools" \
|
|
org.opencontainers.image.url="https://www.stirlingpdf.com" \
|
|
org.opencontainers.image.documentation="https://docs.stirlingpdf.com" \
|
|
maintainer="Stirling-Tools" \
|
|
org.opencontainers.image.authors="Stirling-Tools" \
|
|
org.opencontainers.image.version="${VERSION_TAG}" \
|
|
org.opencontainers.image.keywords="PDF, manipulation, fat, air-gapped, API, Spring Boot, React"
|
|
|
|
EXPOSE 8080/tcp
|
|
STOPSIGNAL SIGTERM
|
|
|
|
HEALTHCHECK --interval=30s --timeout=15s --start-period=120s --retries=5 \
|
|
CMD curl -fs --max-time 10 http://localhost:8080${SYSTEM_ROOTURIPATH:-''}/api/v1/info/status || exit 1
|
|
|
|
ENTRYPOINT ["tini", "--", "/scripts/init.sh"]
|
|
CMD []
|