paketo-buildpacks / native-image

A Cloud Native Buildpack that creates native images from Java applications
Apache License 2.0
50 stars 9 forks source link

Configure `--no-fallback` flag by default #195

Closed sdeleuze closed 1 year ago

sdeleuze commented 1 year ago

Current default behavior for native-image is to switch to requiring a JVM when a native build fails. This can be super confusing for users, like in this use case.

If a Spring Boot 3 developer configures:

bootBuildImage {
    builder = "paketobuildpacks/builder:tiny"
    environment = [
            "BP_NATIVE_IMAGE" : "true"
    ]
}

But forget to enable Spring AOT/native support when building the app (currently triggered by adding the Native Build Tools plugin with Spring Boot 3), he gets a pretty weird behavior with those messages during the build:

    [creator]     Warning: Serialization method java.io.ObjectOutputStream.writeObject invoked at ch.qos.logback.core.net.AutoFlushingObjectWriter.write(AutoFlushingObjectWriter.java:46)
...
    [creator]     Warning: Image '/layers/paketo-buildpacks_native-image/native-image/com.example.springboot.Application' is a fallback image that requires a JDK for execution (use --no-fallback to suppress fallback image generation and to print more detailed information why a fallback image was necessary).

And then running the app fails with:

docker run docker.io/library/spring-boot:0.0.1-SNAPSHOT
Error: No bin/java and no environment variable JAVA_HOME

There are discussion to make --no-fallback the default behavior of GraalVM native-image but that won't happen until native passes the TCK. In the meantime, Spring Boot 3 set --no-fallback by default when AOT/native support is enabled. But here this support is not enabled.

So my proposal is to set --no-fallback by default, maybe by defining BP_NATIVE_IMAGE_BUILD_ARGUMENTS = --no-fallback by default to allow to disable it in case of, and document that in https://github.com/paketo-buildpacks/native-image#configuration. This buildpack is designed to build a native image to this default configuration would make sense to me.

sdeleuze commented 1 year ago

So my proposal is to set --no-fallback by default, maybe by defining BP_NATIVE_IMAGE_BUILD_ARGUMENTS = --no-fallback by default to allow to disable it in case of, and document that in https://github.com/paketo-buildpacks/native-image#configuration.

A better option proposed by @pivotal-david-osullivan is to configure --no-fallback only when --auto-fallback and --force-fallback are not passed to BP_NATIVE_IMAGE_BUILD_ARGUMENTS.