From a172d065122098dcdb0ef6fb901451504f799188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Le=20Meur?= <91831478+lemeurherve@users.noreply.github.com> Date: Tue, 7 May 2024 05:38:37 +0200 Subject: [PATCH] chore: jlink improvements from jenkinsci/docker (#799) --- alpine/Dockerfile | 19 +++++++++---------- debian/Dockerfile | 36 ++++++++++++++++++++---------------- debian/preview/Dockerfile | 4 ++-- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/alpine/Dockerfile b/alpine/Dockerfile index 7a0a4669c..affdc4d1f 100644 --- a/alpine/Dockerfile +++ b/alpine/Dockerfile @@ -23,22 +23,21 @@ ARG JAVA_VERSION=17.0.10_7 ARG ALPINE_TAG=3.19.1 FROM eclipse-temurin:"${JAVA_VERSION}"-jdk-alpine AS jre-build -RUN if [ "$TARGETPLATFORM" != 'linux/arm/v7' ]; then \ - case "$(jlink --version 2>&1)" in \ +RUN case "$(jlink --version 2>&1)" in \ # jlink version 11 has less features than JDK17+ - "11."*) strip_java_debug_flags="--strip-debug" ;; \ - *) strip_java_debug_flags="--strip-java-debug-attributes" ;; \ + "11."*) set -- "--strip-debug" "--compress=2" ;; \ + "17."*) set -- "--strip-java-debug-attributes" "--compress=2" ;; \ + # the compression argument is different for JDK21 + "21."*) set -- "--strip-java-debug-attributes" "--compress=zip-6" ;; \ + *) echo "ERROR: unmanaged jlink version pattern" && exit 1 ;; \ esac; \ jlink \ + "$1" \ + "$2" \ --add-modules ALL-MODULE-PATH \ - "$strip_java_debug_flags" \ --no-man-pages \ --no-header-files \ - --compress=2 \ - --output /javaruntime; \ - else \ - cp -r /opt/java/openjdk /javaruntime; \ - fi + --output /javaruntime ## Agent image target FROM alpine:"${ALPINE_TAG}" AS agent diff --git a/debian/Dockerfile b/debian/Dockerfile index 0b00657f3..88bceb564 100644 --- a/debian/Dockerfile +++ b/debian/Dockerfile @@ -32,22 +32,26 @@ SHELL ["/bin/bash","-e", "-u", "-o", "pipefail", "-c"] # Generate smaller java runtime without unneeded files # for now we include the full module path to maintain compatibility # while still saving space (approx 200mb from the full distribution) -RUN if test "${TARGETPLATFORM}" != 'linux/arm/v7'; then \ - case "$(jlink --version 2>&1)" in \ - # jlink version 11 has less features than JDK17+ - "11."*) strip_java_debug_flags=("--strip-debug") ;; \ - *) strip_java_debug_flags=("--strip-java-debug-attributes") ;; \ - esac; \ - jlink \ - --add-modules ALL-MODULE-PATH \ - "${strip_java_debug_flags[@]}" \ - --no-man-pages \ - --no-header-files \ - --compress=2 \ - --output /javaruntime; \ - # It is acceptable to have a larger image in arm/v7 (arm 32 bits) environment. - # Because jlink fails with the error "jmods: Value too large for defined data type" error. - else cp -r /opt/java/openjdk /javaruntime; \ +RUN if [[ "${TARGETPLATFORM}" != "linux/arm/v7" ]]; then \ + case "$(jlink --version 2>&1)" in \ + # jlink version 11 has less features than JDK17+ + "11."*) set -- "--strip-debug" "--compress=2" ;; \ + "17."*) set -- "--strip-java-debug-attributes" "--compress=2" ;; \ + # the compression argument is different for JDK21 + "21."*) set -- "--strip-java-debug-attributes" "--compress=zip-6" ;; \ + *) echo "ERROR: unmanaged jlink version pattern" && exit 1 ;; \ + esac; \ + jlink \ + "$1" \ + "$2" \ + --add-modules ALL-MODULE-PATH \ + --no-man-pages \ + --no-header-files \ + --output /javaruntime; \ + else \ + # It is acceptable to have a larger image in arm/v7 (arm 32 bits) environment. + # Because jlink fails with the error "jmods: Value too large for defined data type" error. + cp -r /opt/java/openjdk /javaruntime; \ fi ## Agent image target diff --git a/debian/preview/Dockerfile b/debian/preview/Dockerfile index b92989c8f..19936ed65 100644 --- a/debian/preview/Dockerfile +++ b/debian/preview/Dockerfile @@ -26,9 +26,9 @@ RUN set -x; apt-get update \ && tar -xzf /tmp/jdk.tar.gz -C /opt/ \ && rm -f /tmp/jdk.tar.gz -ENV PATH=/opt/jdk-${JAVA_VERSION}/bin:$PATH +ENV PATH="/opt/jdk-${JAVA_VERSION}/bin:${PATH}" -RUN if test "${TARGETPLATFORM}" != 'linux/arm/v7'; then \ +RUN if [[ "${TARGETPLATFORM}" != "linux/arm/v7" ]]; then \ jlink \ --add-modules ALL-MODULE-PATH \ --no-man-pages \