From 437f770b1f0de52dd8431caaf2f0d04de2fcfafb Mon Sep 17 00:00:00 2001 From: Gunnar von der Beck Date: Wed, 30 Aug 2023 14:34:45 +0200 Subject: [PATCH] chore: shrink docker image using adoptium buildpack with jlink enabled --- examples/sso-kubernetes/README.md | 10 ++++++++++ examples/sso-kubernetes/pom.xml | 13 +++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/examples/sso-kubernetes/README.md b/examples/sso-kubernetes/README.md index f5b5d14f..87c98783 100644 --- a/examples/sso-kubernetes/README.md +++ b/examples/sso-kubernetes/README.md @@ -339,6 +339,16 @@ Finally - a quick introduction on how to setup Keycloak and this showcase on Kub Before we turn to Kubernetes it is necessary to build the Docker image. As we included the ``spring-boot-maven-plugin`` everything is quite simple, just run ``mvn spring-boot:build-image``. +The Docker Image Build is using the `gcr.io/paketo-buildpacks/adoptium` Buildpack having JDK's jlink tool at build time enabled to generate a custom slim JRE. + +#### Java module dependencies & jlinked Java 17 + +Just for the records - how to find out java module dependencies and shrink your JRE: +* Extract ``target/camunda-platform-7-keycloak-examples-sso-kubernetes.jar/BOOT-INF/lib`` to `target/lib`` +* Open a shell in ``target`` and run ``jdeps -cp lib/* -R --multi-release 17 --print-module-deps --ignore-missing-deps camunda-platform-7-keycloak-examples-sso-kubernetes.jar`` + +The result goes to the jlink `add-modules` option in the `BP_JVM_JLINK_ARGS` environment parameter of the `spring-boot-maven-plugin` image configuration. + ### Kubernetes The Kubernetes setup can be found in directory ``k8s``. It contains a subfolder ``keycloak`` setting up the Keycloak test server. diff --git a/examples/sso-kubernetes/pom.xml b/examples/sso-kubernetes/pom.xml index cbb02cd4..f44b4fbd 100644 --- a/examples/sso-kubernetes/pom.xml +++ b/examples/sso-kubernetes/pom.xml @@ -16,7 +16,6 @@ false - paketobuildpacks/builder-jammy-tiny gunnaraccso/camunda-showcase-keycloak:${version} @@ -158,7 +157,17 @@ true - ${docker.buildPack} + paketobuildpacks/builder:tiny + + gcr.io/paketo-buildpacks/adoptium + paketo-buildpacks/java + + + ${version.java} + JRE + true + --no-man-pages --no-header-files --strip-debug --compress=2 --add-modules java.base,java.compiler,java.desktop,java.instrument,java.net.http,java.prefs,java.rmi,java.scripting,java.security.jgss,java.security.sasl,java.sql.rowset,jdk.attach,jdk.jdi,jdk.jfr,jdk.management,jdk.net,jdk.unsupported + ${docker.imageName}