From 998bf6cd342973f32e28e2edba42eb775b0c4193 Mon Sep 17 00:00:00 2001 From: Anindra Date: Tue, 17 Nov 2026 18:05:55 +0530 Subject: [PATCH] fix: stop using ./mvnw inside the image build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The v0.2.0 release failed at the container step: Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. process "chmod +x mvnw && ./mvnw -B -q -DskipTests dependency:go-offline" exit code 1 The pin is correct — the same URL hashes to 9c1ef917... locally, and the wrapper downloads and verifies it with a clean $HOME. What differs is the image: the wrapper shells out to curl/wget/unzip, which eclipse-temurin does not fully ship, so it produced a file that failed the checksum. The build stage now installs those tools and fetches Maven with an explicit sha256sum -c against the pin in .mvn/wrapper/maven-wrapper.properties. That keeps one source of truth, removes the wrapper's shell logic from the image, and fails with a usable message if the pin is ever wrong. Verified the exact RUN body locally: download, checksum OK, unpack, mvn -v reports 3.10.1 from /opt/apache-maven-3.10.1. --- Dockerfile | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index e1f2740..8aaa443 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,32 @@ FROM eclipse-temurin:21-jdk AS build WORKDIR /app -COPY .mvn/ .mvn/ -COPY mvnw pom.xml ./ -RUN chmod +x mvnw && ./mvnw -B -q -DskipTests dependency:go-offline + +# Fetch Maven here instead of through ./mvnw. The wrapper's download produced a file that +# failed its own SHA-256 check inside this image, so every image build broke. Doing it +# explicitly keeps .mvn/wrapper/maven-wrapper.properties as the single source of truth and +# fails loudly if the artifact ever stops matching the pin. +RUN apt-get update \ + && apt-get install -y --no-install-recommends curl unzip ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +COPY .mvn/wrapper/maven-wrapper.properties /tmp/maven-wrapper.properties +RUN set -eux; \ + URL="$(sed -n 's/^distributionUrl=//p' /tmp/maven-wrapper.properties | tr -d '[:space:]')"; \ + SUM="$(sed -n 's/^distributionSha256Sum=//p' /tmp/maven-wrapper.properties | tr -d '[:space:]')"; \ + test -n "$URL"; \ + test -n "$SUM"; \ + curl -fsSL --retry 3 -o /tmp/maven.zip "$URL"; \ + echo "$SUM /tmp/maven.zip" | sha256sum -c -; \ + unzip -q /tmp/maven.zip -d /opt; \ + ln -sfn "$(echo /opt/apache-maven-*/bin/mvn)" /usr/local/bin/mvn; \ + rm -f /tmp/maven.zip /tmp/maven-wrapper.properties; \ + mvn -v + +COPY pom.xml ./ +RUN mvn -B -q -DskipTests dependency:go-offline + COPY src/ src/ -RUN ./mvnw -B -q -DskipTests package +RUN mvn -B -q -DskipTests package FROM eclipse-temurin:21-jre WORKDIR /app @@ -14,7 +36,6 @@ COPY --from=build /app/target/path-*.jar app.jar # and the generated master key. RUN groupadd --system --gid 1001 path \ && useradd --system --uid 1001 --gid path --home-dir /app --shell /usr/sbin/nologin path \ - && mkdir -p /app/data \ && chown -R path:path /app USER path