Skip to content

Commit

Permalink
chore: jlink improvements from jenkinsci/docker (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemeurherve committed May 7, 2024
1 parent e70fd41 commit a172d06
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
19 changes: 9 additions & 10 deletions alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 20 additions & 16 deletions debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions debian/preview/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit a172d06

Please sign in to comment.