Skip to content

Commit

Permalink
chore: jlink improvements from jenkinsci/docker (#405)
Browse files Browse the repository at this point in the history
* chore: jlink improvements from jenkinsci/docker

* fixup debian jdk21 preview
  • Loading branch information
lemeurherve authored May 14, 2024
1 parent 57304f3 commit 50ae6ca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 53 deletions.
19 changes: 9 additions & 10 deletions alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,21 @@ ARG JAVA_VERSION=17.0.11_9
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

FROM alpine:"${ALPINE_TAG}" AS build

Expand Down
32 changes: 13 additions & 19 deletions debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,21 @@ 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>/dev/null)" in \
# jlink version 11 has less features than JDK17+
"11."*) strip_java_debug_flags=("--strip-debug") ;; \
*) strip_java_debug_flags=("--strip-java-debug-attributes") ;; \
RUN 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; \
if test "${TARGETPLATFORM}" != 'linux/amd/64'; then \
# posix_spawn (default for JDK12+) fails erratically with qemu on non x86 CPUs - https://github.com/openzipkin/docker-java/issues/34#issuecomment-721673618
export JAVA_TOOL_OPTIONS='-Djdk.lang.Process.launchMechanism=vfork'; \
fi; \
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; \
fi
"$1" \
"$2" \
--add-modules ALL-MODULE-PATH \
--no-man-pages \
--no-header-files \
--output /javaruntime

FROM debian:"${DEBIAN_RELEASE}"

Expand Down
27 changes: 3 additions & 24 deletions debian/preview/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,9 @@ RUN apt-get update \

ENV PATH="/opt/jdk-${JAVA_VERSION}/bin:${PATH}"

# 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>/dev/null)" 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; \
if test "${TARGETPLATFORM}" != 'linux/amd/64'; then \
# posix_spawn (default for JDK12+) fails erratically with qemu on non x86 CPUs - https://github.com/openzipkin/docker-java/issues/34#issuecomment-721673618
export JAVA_TOOL_OPTIONS='-Djdk.lang.Process.launchMechanism=vfork'; \
fi; \
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/jdk-${JAVA_VERSION}" /javaruntime; \
fi
# 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.
RUN cp -r "/opt/jdk-${JAVA_VERSION}" /javaruntime

FROM debian:"${DEBIAN_RELEASE}"

Expand Down

0 comments on commit 50ae6ca

Please sign in to comment.