Search code examples
spring-bootbuildpack

Spring Boot Buildpacks BP_JVM_JLINK_ENABLED fails to build in Gitlab CI


Hopefully someone can help me here.

Locally it all works but when I try running spring boot bootBuildImage in gitlab ci with BP_JVM_JLINK_ENABLED = true it fails with

[creator]         Expanding to /layers/paketo-buildpacks_bellsoft-liberica/jdk
    [creator]         Adding 137 container CA certificates to JVM truststore
    [creator]         Writing env.build/JAVA_HOME.override
    [creator]         Writing env.build/JDK_HOME.override
    [creator]       JLink: Contributing to layer
    [creator]     unable to invoke layer creator
    [creator]     unable to retrieve list of JVM modules for jlink
    [creator]     unable to list modules
    [creator]     exit status 1
    [creator]     ERROR: failed to build: exit status 1

> Task :bootBuildImage FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootBuildImage'.
> Builder lifecycle 'creator' failed with status code 51

The application is a simple spring boot app from https://start.spring.io/ nothing special.

The gradle file is also pretty simple

tasks.named("bootBuildImage") {
    environment["BP_JVM_VERSION"] = "17"
    environment["BP_JVM_JLINK_ENABLED"] = "true"
} 

If disable BP_JVM_JLINK_ENABLED, it works fine in the CI CD pipeline, but I'm hoping to trim the image size but I can't seem to get it to work.

full console log

[32;1m$ ./gradlew build bootBuildImage --imageName=playground:abc�

Welcome to Gradle 7.5.1!

Here are the highlights of this release:

Support for Java 18
Support for building with Groovy 4
Much more responsive continuous builds
Improved diagnostics for dependency resolution
For more details see https://docs.gradle.org/7.5.1/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

Task :compileJava
Task :processResources
Task :classes
Task :bootJarMainClassName
Task :bootJar
Task :jar SKIPPED
Task :assemble
Task :compileTestJava
Task :processTestResources NO-SOURCE
Task :testClasses
Task :test
Task :compileIntegrationTestJava NO-SOURCE
Task :processIntegrationTestResources NO-SOURCE
Task :integrationTestClasses UP-TO-DATE
Task :integrationTest NO-SOURCE
Task :spotlessInternalRegisterDependencies
Task :spotlessJava
Task :spotlessJavaCheck
Task :spotlessCheck

Task :jacocoTestReport
..
Task :check
Task :build

Task :bootBuildImage
Building image 'playground:abc'

Pulling builder image 'docker.io/paketobuildpacks/builder-jammy-base:latest' ..................................................
Pulled builder image 'paketobuildpacks/builder-jammy-base@sha256:ff47160c561329011180fcec8f3ae32c18c044ab9c57c3d981157309734693e9'
Pulling run image 'docker.io/paketobuildpacks/run-jammy-base:latest' ..................................................
Pulled run image 'paketobuildpacks/run-jammy-base@sha256:436a84a3ae3bdbc9f0534b7e6a80122d05f734048137691fcfec36f8132758b1'
Executing lifecycle version v0.19.3
Using build cache volume 'pack-cache-4bc4e9944d46.build'

Running creator
[creator] ===> ANALYZING
[creator] Image with name "playground:abc" not found
[creator] ===> DETECTING
[creator] 6 of 26 buildpacks participating
[creator] paketo-buildpacks/ca-certificates 3.6.8
[creator] paketo-buildpacks/bellsoft-liberica 10.5.5
[creator] paketo-buildpacks/syft 1.45.0
[creator] paketo-buildpacks/executable-jar 6.8.5
[creator] paketo-buildpacks/dist-zip 5.6.10
[creator] paketo-buildpacks/spring-boot 5.27.11
[creator] ===> RESTORING
[creator] ===> BUILDING
[creator]
[creator] Paketo Buildpack for CA Certificates 3.6.8
[creator] https://github.com/paketo-buildpacks/ca-certificates
[creator] Launch Helper: Contributing to layer
[creator] Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
[creator]
[creator] Paketo Buildpack for BellSoft Liberica 10.5.5
[creator] https://github.com/paketo-buildpacks/bellsoft-liberica
[creator] Build Configuration:
[creator] $BP_JVM_JLINK_ARGS --no-man-pages --no-header-files --strip-debug --compress=1 configure custom link arguments (--output must be omitted)
[creator] $BP_JVM_JLINK_ENABLED true enables running jlink tool to generate custom JRE
[creator] $BP_JVM_TYPE JRE the JVM type - JDK or JRE
[creator] $BP_JVM_VERSION 17 the Java version
[creator] Launch Configuration:
[creator] $BPL_DEBUG_ENABLED false enables Java remote debugging support
[creator] $BPL_DEBUG_PORT 8000 configure the remote debugging port
[creator] $BPL_DEBUG_SUSPEND false configure whether to suspend execution until a debugger has attached
[creator] $BPL_HEAP_DUMP_PATH write heap dumps on error to this path
[creator] $BPL_JAVA_NMT_ENABLED true enables Java Native Memory Tracking (NMT)
[creator] $BPL_JAVA_NMT_LEVEL summary configure level of NMT, summary or detail
[creator] $BPL_JFR_ARGS configure custom Java Flight Recording (JFR) arguments
[creator] $BPL_JFR_ENABLED false enables Java Flight Recording (JFR)
[creator] $BPL_JMX_ENABLED false enables Java Management Extensions (JMX)
[creator] $BPL_JMX_PORT 5000 configure the JMX port
[creator] $BPL_JVM_HEAD_ROOM 0 the headroom in memory calculation
[creator] $BPL_JVM_LOADED_CLASS_COUNT 35% of classes the number of loaded classes in memory calculation
[creator] $BPL_JVM_THREAD_COUNT 250 the number of threads in memory calculation
[creator] $JAVA_TOOL_OPTIONS the JVM launch flags
[creator] Using Java version 17 from BP_JVM_VERSION
[creator] BellSoft Liberica JDK 17.0.10: Contributing to layer
[creator] Downloading from https://github.com/bell-sw/Liberica/releases/download/17.0.10+13/bellsoft-jdk17.0.10+13-linux-amd64.tar.gz
[creator] Verifying checksum
[creator] Expanding to /layers/paketo-buildpacks_bellsoft-liberica/jdk
[creator] Adding 137 container CA certificates to JVM truststore
[creator] Writing env.build/JAVA_HOME.override
[creator] Writing env.build/JDK_HOME.override
[creator] JLink: Contributing to layer
[creator] unable to invoke layer creator
[creator] unable to retrieve list of JVM modules for jlink
[creator] unable to list modules
[creator] exit status 1
[creator] ERROR: failed to build: exit status 1

Task :bootBuildImage FAILED

FAILURE: Build failed with an exception.

What went wrong:
Execution failed for task ':bootBuildImage'.
Builder lifecycle 'creator' failed with status code 51


Solution

  • You have enabled JLink which triggers the buildpack to run java --list-modules. It then reads the list that's output by your version of Java, strips off all of the jdk modules and dynamically generates a list of just the jre modules. This gives you a smaller footprint.

    The problem in your case is that java --list-modules is failing. That's what this output is telling us.

    [creator] unable to invoke layer creator
    [creator] unable to retrieve list of JVM modules for jlink
    [creator] unable to list modules
    [creator] exit status 1
    

    The buildpack is set up to write anything from STDERR to the output as well, but as you can see there's nothing else there so there's not providing us with any indication as to why it might be failing. I don't see anything that looks wrong with your setup either. You've got Java 9+, and you're using Bellsoft JDK, which should all be OK.

    What you can do to work around this error is to set BP_JVM_JLINK_ARGS to --no-man-pages --no-header-files --strip-debug --compress=1 --add-modules <module-list> where <module-list> is the comma separate list of modules you want jlink to include. You can run java --list-modules yourself to get the full list of modules. When you add this argument, it will bypass the call to java --list-modules in the buildpack. This will get you past the error above, and hopefully a working build.

    The other thing you can do is to not use jlink. The Bellsoft buildpack will install a JRE, so that will result in a very similar reduction in size. By running with jlink, you're only going to get something marginally smaller with the default argument list the buildpack creates.

    I saw that you opened a Github Issue as well. We'll try to reproduce this and get to the bottom of it, but for now this should get you building again.