paketo-buildpacks / spring-boot

A Cloud Native Buildpack that contributes Spring Boot dependency information and slices an application into multiple layers
Apache License 2.0
170 stars 22 forks source link

Spring Boot Buildpacks with BP_JVM_JLINK_ENABLED fails in Gitlab CI #464

Closed jd1289 closed 5 months ago

jd1289 commented 5 months ago

Hi, I hope someone can shed some light on this, i'm a bit stumped on :)

Using a standard spring initializr project with build packs enabled runs in local mac and gitlab ci.

If BP_JVM_JLINK_ENABLED = true, it will build in local mac but the same process does not run in Gitlab CI.

Extract from CI console below. Just wondering if this feature works for anyone? Kind of stumped why enabling BP_JVM_JLINK_ENABLED stop the build only in Gitlab CI.

Your help would be much appreciated.

Gradle config, nothing special

plugins {
    id 'org.springframework.boot' version '2.7.18'
    id 'io.spring.dependency-management' version '1.0.14.RELEASE'
    id 'java'
    id 'jacoco'
    id 'maven-publish'
    id 'com.diffplug.spotless' version '6.25.0'
}

jar {
    enabled = false
}

apply plugin: 'jacoco'
apply plugin: 'com.diffplug.spotless'

group = 'com.example.playground'
sourceCompatibility = '17'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenLocal()
    google()
    mavenCentral()
}

sourceSets {
    main {
        java.srcDir file("${buildDir}/generated-src")
    }

    integrationTest {
        java.srcDir file('src/integration-test/java')
        resources.srcDir file('src/integration-test/resources')

        compileClasspath += main.output + test.output
        runtimeClasspath += main.output + test.output
    }
}

task integrationTest(type: Test) {
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath
    outputs.upToDateWhen { false }

    group("verification")
}

check.dependsOn integrationTest
integrationTest.mustRunAfter test

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.kafka:spring-kafka:2.9.13'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.kafka:spring-kafka-test'
}

spotless {
    java {
        importOrder()
        googleJavaFormat()
        removeUnusedImports()
        trimTrailingWhitespace()
    }
}

test {
    useJUnitPlatform()
    finalizedBy jacocoTestReport
    reports {
        junitXml.getRequired().set(true)
    }
}

jacoco {
    toolVersion = "0.8.11"
    reportsDirectory = file("build/jacoco")
}

jacocoTestReport {
    dependsOn test
    reports {
        xml.enabled true
        xml.destination file("build/reports/jacoco.xml")
        sourceSets sourceSets.main
        executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")
    }
}

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

console output:

[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
dmikusa commented 5 months ago

https://stackoverflow.com/questions/78317955/spring-boot-buildpacks-bp-jvm-jlink-enabled-fails-to-build-in-gitlab-ci/78318755