# Backend ultra-lite Dockerfile - Java Spring Boot with minimal dependencies and build stage # ======================================== # STAGE 1: Build stage - Gradle # ======================================== FROM gradle:8.14-jdk21 AS build COPY build.gradle . COPY settings.gradle . COPY gradlew . COPY gradle gradle/ COPY app/core/build.gradle core/. COPY app/common/build.gradle common/. COPY app/proprietary/build.gradle proprietary/. RUN ./gradlew build -x spotlessApply -x spotlessCheck -x test -x sonarqube || return 0 # Set the working directory WORKDIR /app # Copy the entire project to the working directory COPY . . # Build the application with DISABLE_ADDITIONAL_FEATURES=true RUN DISABLE_ADDITIONAL_FEATURES=true \ STIRLING_PDF_DESKTOP_UI=false \ ./gradlew clean build -x spotlessApply -x spotlessCheck -x test -x sonarqube # ======================================== # STAGE 2: Runtime stage - Alpine minimal # ======================================== FROM alpine:3.22.2@sha256:4b7ce07002c69e8f3d704a9c5d6fd3053be500b7f1c69fc0d80990c2ad8dd412 ARG VERSION_TAG # Set Environment Variables ENV HOME=/home/stirlingpdfuser \ VERSION_TAG=$VERSION_TAG \ JAVA_BASE_OPTS="-XX:+UnlockExperimentalVMOptions -XX:MaxRAMPercentage=75 -XX:InitiatingHeapOccupancyPercent=20 -XX:+G1PeriodicGCInvokesConcurrent -XX:G1PeriodicGCInterval=10000 -XX:+UseStringDeduplication -XX:G1PeriodicGCSystemLoadThreshold=70" \ JAVA_CUSTOM_OPTS="" \ PUID=1000 \ PGID=1000 \ UMASK=022 \ STIRLING_TEMPFILES_DIRECTORY=/tmp/stirling-pdf \ TMPDIR=/tmp/stirling-pdf \ TEMP=/tmp/stirling-pdf \ TMP=/tmp/stirling-pdf # Copy necessary files COPY scripts/init-without-ocr.sh /scripts/init-without-ocr.sh COPY scripts/installFonts.sh /scripts/installFonts.sh COPY --from=build --chown=stirlingpdfuser:stirlingpdfgroup /app/app/core/build/libs/*.jar /app.jar COPY --from=build --chown=stirlingpdfuser:stirlingpdfgroup /app/build/libs/restart-helper.jar /restart-helper.jar # Set up necessary directories and permissions RUN apk add --no-cache bash \ && ln -sf /bin/bash /bin/sh \ && printf '%s\n' \ 'https://dl-cdn.alpinelinux.org/alpine/edge/main' \ 'https://dl-cdn.alpinelinux.org/alpine/edge/community' \ 'https://dl-cdn.alpinelinux.org/alpine/edge/testing' \ > /etc/apk/repositories && \ apk upgrade --no-cache -a && \ apk add --no-cache \ ca-certificates \ tzdata \ tini \ bash \ curl \ shadow \ su-exec \ openjdk21-jre \ ghostscript \ fontforge && \ # User permissions mkdir -p /configs /logs /customFiles /usr/share/fonts/opentype/noto /tmp/stirling-pdf /pipeline/watchedFolders /pipeline/finishedFolders && \ chmod +x /scripts/*.sh && \ addgroup -S stirlingpdfgroup && adduser -S stirlingpdfuser -G stirlingpdfgroup && \ chown -R stirlingpdfuser:stirlingpdfgroup $HOME /scripts /pipeline /configs /customFiles /pipeline /tmp/stirling-pdf && \ chown stirlingpdfuser:stirlingpdfgroup /app.jar /restart-helper.jar && \ ln -sf /bin/busybox /bin/sh # Set environment variables ENV ENDPOINTS_GROUPS_TO_REMOVE=CLI EXPOSE 8080/tcp # Run the application ENTRYPOINT ["tini", "--", "/scripts/init-without-ocr.sh"] CMD []