Skip to content

Commit

Permalink
chore: shrink docker image using adoptium buildpack with jlink enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
VonDerBeck committed Aug 30, 2023
1 parent 4c74c19 commit 437f770
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions examples/sso-kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 11 additions & 2 deletions examples/sso-kubernetes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>

<docker.buildPack>paketobuildpacks/builder-jammy-tiny</docker.buildPack>
<docker.imageName>gunnaraccso/camunda-showcase-keycloak:${version}</docker.imageName>
</properties>

Expand Down Expand Up @@ -158,7 +157,17 @@
<enabled>true</enabled>
</layers>
<image>
<builder>${docker.buildPack}</builder>
<builder>paketobuildpacks/builder:tiny</builder>
<buildpacks>
<buildpack>gcr.io/paketo-buildpacks/adoptium</buildpack>
<buildpack>paketo-buildpacks/java</buildpack>
</buildpacks>
<env>
<BP_JVM_VERSION>${version.java}</BP_JVM_VERSION>
<BP_JVM_TYPE>JRE</BP_JVM_TYPE>
<BP_JVM_JLINK_ENABLED>true</BP_JVM_JLINK_ENABLED>
<BP_JVM_JLINK_ARGS>--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</BP_JVM_JLINK_ARGS>
</env>
</image>
<imageName>${docker.imageName}</imageName>
</configuration>
Expand Down

0 comments on commit 437f770

Please sign in to comment.