From c83e8de920cb604fc55a18fe1c5f2c1d872f6f74 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Fri, 13 May 2022 15:25:56 +0200 Subject: Use a custom OpenJDK base container image. Change-Id: I9b24bdaf5f07974de12ae408df3b9a25e8268a48 --- src/main/docker/runtime/.gitignore | 6 ++++++ src/main/docker/runtime/Dockerfile | 30 ++++++++++++++++++++++++++ src/main/docker/runtime/build | 36 +++++++++++++++++++++++++++++++ src/main/docker/runtime/prepare | 16 ++++++++++++++ src/main/resources/application.properties | 3 +-- 5 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 src/main/docker/runtime/.gitignore create mode 100644 src/main/docker/runtime/Dockerfile create mode 100755 src/main/docker/runtime/build create mode 100755 src/main/docker/runtime/prepare diff --git a/src/main/docker/runtime/.gitignore b/src/main/docker/runtime/.gitignore new file mode 100644 index 0000000..3ed2fbd --- /dev/null +++ b/src/main/docker/runtime/.gitignore @@ -0,0 +1,6 @@ +# SPDX-FileCopyrightText: © 2022 Matthias Andreas Benkard +# +# SPDX-License-Identifier: GPL-3.0-or-later + +/cache +/jdk-dist diff --git a/src/main/docker/runtime/Dockerfile b/src/main/docker/runtime/Dockerfile new file mode 100644 index 0000000..80d5b05 --- /dev/null +++ b/src/main/docker/runtime/Dockerfile @@ -0,0 +1,30 @@ +# SPDX-FileCopyrightText: © 2022 Matthias Andreas Benkard +# +# SPDX-License-Identifier: GPL-3.0-or-later + +FROM registry.access.redhat.com/ubi8/ubi-minimal:latest AS ubi-minimal + +# Add OpenJDK (complete). +ADD jdk-dist/latest.tar.gz /jdk + +# JLink a trimmed JDK. +RUN microdnf --assumeyes --nodocs install binutils +RUN /jdk/*/bin/jlink \ + -J-XX:MaxRAMPercentage=75 \ + --add-modules ALL-MODULE-PATH \ + --compress=1 \ + --no-man-pages \ + --strip-debug \ + --output /java +RUN /java/bin/java -Xshare:dump + +# Set mtimes to @0 for reproducibility. +RUN microdnf --assumeyes --nodocs install findutils +RUN find /java -exec touch --date=@0 '{}' ';' + +# Build the final image. +FROM registry.access.redhat.com/ubi8/ubi-micro:latest +COPY --from=ubi-minimal /lib64/libz.so.1 /lib64/ +COPY --from=ubi-minimal /java /java +ENV JAVA_HOME=/java +ENV PATH=/java/bin:$PATH diff --git a/src/main/docker/runtime/build b/src/main/docker/runtime/build new file mode 100755 index 0000000..01347d7 --- /dev/null +++ b/src/main/docker/runtime/build @@ -0,0 +1,36 @@ +#! /bin/sh +# SPDX-FileCopyrightText: © 2022 Matthias Andreas Benkard +# +# SPDX-License-Identifier: GPL-3.0-or-later + +set -euo pipefail + +cd "$(dirname $(readlink -e "$0"))" + +image=docker.benkard.de/mulk/openjdk-runtime:latest +use_kaniko=no + +./prepare + +if [[ "${use_kaniko}" == yes ]]; then + docker run \ + --mount type=bind,src="$PWD",target=/workspace \ + gcr.io/kaniko-project/warmer:latest \ + --cache-dir=/workspace/cache \ + --image=registry.access.redhat.com/ubi8/ubi-micro:latest \ + --image=registry.access.redhat.com/ubi8/ubi-minimal:latest + + docker run \ + --mount type=bind,src="$PWD",target=/workspace \ + --mount type=bind,src="$HOME/.docker",target=/root/.docker,ro=true \ + gcr.io/kaniko-project/executor:latest \ + --dockerfile Dockerfile \ + --destination "${image}" \ + --context dir:///workspace/ \ + --cache=true \ + --cache-ttl=16800h0m0s \ + --reproducible=true +else + docker build -t "${image}" . + docker push "${image}" +fi diff --git a/src/main/docker/runtime/prepare b/src/main/docker/runtime/prepare new file mode 100755 index 0000000..f0fddba --- /dev/null +++ b/src/main/docker/runtime/prepare @@ -0,0 +1,16 @@ +#! /bin/sh +# SPDX-FileCopyrightText: © 2022 Matthias Andreas Benkard +# +# SPDX-License-Identifier: GPL-3.0-or-later + +set -euo pipefail + +cd "$(dirname $(readlink -e "$0"))" + +openjdk_package_info=$(curl "https://api.foojay.io/disco/v2.0/packages?package_type=jdk&latest=per_distro&directly_downloadable=true&release_status=ga&javafx_bundled=false&operating_system=linux&architecture=x64&archive_type=tar.gz&distro=oracle_open_jdk") + +openjdk_package_uri=$(jq -r '.result[0].links.pkg_download_redirect' <<<"${openjdk_package_info}") +openjdk_package_filename=$(jq -r '.result[0].filename' <<<"${openjdk_package_info}") +curl --fail --create-dirs -C - -o "jdk-dist/${openjdk_package_filename}" "${openjdk_package_uri}" + +ln -svf "${openjdk_package_filename}" "jdk-dist/latest.tar.gz" diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2c21fee..bd9db97 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -86,8 +86,7 @@ quarkus.container-image.group = mulk quarkus.container-image.name = mulkcms2 quarkus.container-image.registry = docker.benkard.de -quarkus.jib.base-jvm-image = container-registry.oracle.com/java/openjdk:latest -#quarkus.jib.jvm-arguments = -XX:+UseShenandoahGC,-XX:ShenandoahGCHeuristics=compact +quarkus.jib.base-jvm-image = docker.benkard.de/mulk/openjdk-runtime:latest quarkus.jib.jvm-arguments = -XX:G1PeriodicGCInterval=300000,-XX:G1PeriodicGCSystemLoadThreshold=0 quarkus.native.container-runtime = docker -- cgit v1.2.3