From 849b1471a2cbe9dd3ea1c5bc59e48a7fb3e78283 Mon Sep 17 00:00:00 2001 From: EdgarEldy Date: Sat, 19 Sep 2026 11:24:30 +0400 Subject: [PATCH 1/9] build(docker): let the Maven wrapper into the build context The ignore file excludes everything except what the image builds need. The native image is built by a Mandrel builder image that ships no Maven, so it runs the project's Maven wrapper, and the wrapper script and its .mvn directory must therefore be part of the context. Everything else stays excluded, so the context remains small and free of local files such as keys and build output. --- .dockerignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.dockerignore b/.dockerignore index f685a3c..5f628d0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,3 +2,5 @@ * !pom.xml !src/ +!mvnw +!.mvn/ From 505baf779cb13ce5ee1e5d3604949f39dcee70d6 Mon Sep 17 00:00:00 2001 From: EdgarEldy Date: Sat, 19 Sep 2026 11:24:30 +0400 Subject: [PATCH 2/9] build(docker): add the multi-stage Dockerfile.native The first stage compiles the application to a native executable with Mandrel, Red Hat's GraalVM distribution, through the pom's native profile. The second stage copies only that binary onto a micro runtime image with the few C libraries it links against: no JVM, no Maven and no sources ship, which is where the small image and the fast start come from. It mirrors Dockerfile.jvm on purpose, with the dependency download cached before the sources are copied, tests skipped in the build stage because Dev Services needs a Docker daemon, and a non-root user at runtime. --- Dockerfile.native | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Dockerfile.native diff --git a/Dockerfile.native b/Dockerfile.native new file mode 100644 index 0000000..b6115f6 --- /dev/null +++ b/Dockerfile.native @@ -0,0 +1,30 @@ +# Multi-stage image for the GraalVM native executable. +# Stage 1 compiles the application to a native binary with Mandrel (Red Hat's GraalVM distribution), +# stage 2 keeps only that binary on a minimal runtime image: no JVM, no Maven, no sources. + +FROM quay.io/quarkus/ubi9-quarkus-mandrel-builder-image:jdk-21 AS build +USER root +WORKDIR /build + +# The builder image ships Mandrel but not Maven, so the Maven wrapper is used. Copying the wrapper and +# the pom alone first lets Docker cache the dependency download until the pom changes. +COPY mvnw . +COPY .mvn .mvn +COPY pom.xml . +RUN ./mvnw -B -q dependency:go-offline + +COPY src ./src +# -Dnative switches on the pom's native profile. Tests are skipped here: they rely on Dev Services, +# which needs a Docker daemon a build stage does not have, and they run in CI with mvn verify. +RUN ./mvnw -B -q package -Dnative -DskipTests + +# The runtime image only needs the C libraries the native binary links against. +FROM quay.io/quarkus/ubi9-quarkus-micro-image:2.0 +WORKDIR /work + +# Same idea as Dockerfile.jvm: never run as root. +COPY --from=build --chown=1001:root --chmod=0755 /build/target/*-runner /work/application + +EXPOSE 8080 +USER 1001 +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] From ad8b01b92527fe5bd62748dd41a618edbb7c901f Mon Sep 17 00:00:00 2001 From: EdgarEldy Date: Sat, 19 Sep 2026 11:24:30 +0400 Subject: [PATCH 3/9] build(scripts): add a startup and memory measurement script The script starts the application in the mode it is given, waits for the readiness endpoint, sends the same fixed mix of requests, and prints one table row with the time until ready, the startup time Quarkus reports and the resident memory after the load. Running the identical script on the JVM jar and on the native binary is what makes the comparison fair. The memory is read after the load and not at idle, since a JVM grows once it has served traffic while a native binary starts close to its steady size. --- scripts/measure-startup.sh | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 scripts/measure-startup.sh diff --git a/scripts/measure-startup.sh b/scripts/measure-startup.sh new file mode 100755 index 0000000..03ae30a --- /dev/null +++ b/scripts/measure-startup.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# Starts the application, waits until it is ready, sends a fixed request load, then prints one +# markdown table row: time until /q/health/ready answers, the startup time Quarkus itself reports, +# and the resident memory of the process after the load. +# +# Usage: scripts/measure-startup.sh