Use Paketo tiny builder by default for JVM and native apps

Closes gh-40859
This commit is contained in:
Scott Frederick 2024-06-28 11:30:43 -05:00
parent 99904d0307
commit 26b59ae912
13 changed files with 17 additions and 22 deletions

View File

@ -267,7 +267,6 @@ publishing.publications.withType(MavenPublication) {
delegate.artifactId('spring-boot-maven-plugin') delegate.artifactId('spring-boot-maven-plugin')
configuration { configuration {
image { image {
delegate.builder("paketobuildpacks/builder-jammy-tiny:latest");
env { env {
delegate.BP_NATIVE_IMAGE("true") delegate.BP_NATIVE_IMAGE("true")
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2023 the original author or authors. * Copyright 2012-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,7 +45,7 @@ import org.springframework.util.Assert;
*/ */
public class BuildRequest { public class BuildRequest {
static final String DEFAULT_BUILDER_IMAGE_NAME = "paketobuildpacks/builder-jammy-base:latest"; static final String DEFAULT_BUILDER_IMAGE_NAME = "paketobuildpacks/builder-jammy-tiny:latest";
private static final ImageReference DEFAULT_BUILDER = ImageReference.of(DEFAULT_BUILDER_IMAGE_NAME); private static final ImageReference DEFAULT_BUILDER = ImageReference.of(DEFAULT_BUILDER_IMAGE_NAME);

View File

@ -119,7 +119,7 @@ The following table summarizes the available properties and their default values
| `builder` | `builder`
| `--builder` | `--builder`
| Name of the Builder image to use. | Name of the Builder image to use.
| `paketobuildpacks/builder-jammy-base:latest` or `paketobuildpacks/builder-jammy-tiny:latest` when {url-native-build-tools-docs-gradle-plugin}[GraalVM Native Image plugin] is applied. | `paketobuildpacks/builder-jammy-tiny:latest`
| `runImage` | `runImage`
| `--runImage` | `--runImage`
@ -237,7 +237,10 @@ Application contents will also be in this location in the generated image.
NOTE: The plugin detects the target Java compatibility of the project using the JavaPlugin's `targetCompatibility` property. NOTE: The plugin detects the target Java compatibility of the project using the JavaPlugin's `targetCompatibility` property.
When using the default Paketo builder and buildpacks, the plugin instructs the buildpacks to install the same Java version. When using the default Paketo builder and buildpacks, the plugin instructs the buildpacks to install the same Java version.
You can override this behaviour as shown in the xref:packaging-oci-image.adoc#build-image.examples.builder-configuration[builder configuration] examples. You can override this behavior as shown in the xref:packaging-oci-image.adoc#build-image.examples.builder-configuration[builder configuration] examples.
NOTE: The default builder `paketobuildpacks/builder-jammy-tiny:latest` does not include a shell.
Applications that require a shell to run a start script, as might be the case when the {url-gradle-docs-application-plugin}[`application` plugin] has been applied to generate a distribution zip archive, should override the `builder` configuration to use one that includes a shell, such as `paketobuildpacks/builder-jammy-base:latest` or `paketobuildpacks/builder-jammy-full:latest`.

View File

@ -89,6 +89,6 @@ When the {url-native-build-tools-docs-gradle-plugin}[GraalVM Native Image plugin
. Configures the GraalVM extension to disable Toolchain detection. . Configures the GraalVM extension to disable Toolchain detection.
. Configures each GraalVM native binary to require GraalVM 22.3 or later. . Configures each GraalVM native binary to require GraalVM 22.3 or later.
. Configures the `bootJar` task to include the reachability metadata produced by the `collectReachabilityMetadata` task in its jar. . Configures the `bootJar` task to include the reachability metadata produced by the `collectReachabilityMetadata` task in its jar.
. Configures the `bootBuildImage` task to use `paketobuildpacks/builder-jammy-tiny:latest` as its builder and to set `BP_NATIVE_IMAGE` to `true` in its environment. . Configures the `bootBuildImage` task to set `BP_NATIVE_IMAGE` to `true` in its environment.

View File

@ -105,10 +105,7 @@ class NativeImagePluginAction implements PluginApplicationAction {
private void configureBootBuildImageToProduceANativeImage(Project project) { private void configureBootBuildImageToProduceANativeImage(Project project) {
project.getTasks() project.getTasks()
.named(SpringBootPlugin.BOOT_BUILD_IMAGE_TASK_NAME, BootBuildImage.class) .named(SpringBootPlugin.BOOT_BUILD_IMAGE_TASK_NAME, BootBuildImage.class)
.configure((bootBuildImage) -> { .configure((bootBuildImage) -> bootBuildImage.getEnvironment().put("BP_NATIVE_IMAGE", "true"));
bootBuildImage.getBuilder().convention("paketobuildpacks/builder-jammy-tiny:latest");
bootBuildImage.getEnvironment().put("BP_NATIVE_IMAGE", "true");
});
} }
private void configureJarManifestNativeAttribute(Project project) { private void configureJarManifestNativeAttribute(Project project) {

View File

@ -92,8 +92,7 @@ class NativeImagePluginActionIntegrationTests {
void bootBuildImageIsConfiguredToBuildANativeImage() { void bootBuildImageIsConfiguredToBuildANativeImage() {
writeDummySpringApplicationAotProcessorMainClass(); writeDummySpringApplicationAotProcessorMainClass();
BuildResult result = this.gradleBuild.build("bootBuildImageConfiguration"); BuildResult result = this.gradleBuild.build("bootBuildImageConfiguration");
assertThat(result.getOutput()).contains("paketobuildpacks/builder-jammy-tiny") assertThat(result.getOutput()).contains("BP_NATIVE_IMAGE = true");
.contains("BP_NATIVE_IMAGE = true");
} }
@TestTemplate @TestTemplate

View File

@ -173,7 +173,7 @@ class BootBuildImageTests {
@Test @Test
void whenNoBuilderIsConfiguredThenRequestHasDefaultBuilder() { void whenNoBuilderIsConfiguredThenRequestHasDefaultBuilder() {
assertThat(this.buildImage.createRequest().getBuilder().getName()) assertThat(this.buildImage.createRequest().getBuilder().getName())
.isEqualTo("paketobuildpacks/builder-jammy-base"); .isEqualTo("paketobuildpacks/builder-jammy-tiny");
} }
@Test @Test

View File

@ -7,7 +7,6 @@ apply plugin: 'org.graalvm.buildtools.native'
task('bootBuildImageConfiguration') { task('bootBuildImageConfiguration') {
doFirst { doFirst {
println "builder = ${tasks.getByName('bootBuildImage').builder.get()}"
println "BP_NATIVE_IMAGE = ${tasks.getByName('bootBuildImage').environment.get()['BP_NATIVE_IMAGE']}" println "BP_NATIVE_IMAGE = ${tasks.getByName('bootBuildImage').environment.get()['BP_NATIVE_IMAGE']}"
} }
} }

View File

@ -135,7 +135,7 @@ The following table summarizes the available parameters and their default values
| `builder` + | `builder` +
(`spring-boot.build-image.builder`) (`spring-boot.build-image.builder`)
| Name of the Builder image to use. | Name of the Builder image to use.
| `paketobuildpacks/builder-jammy-base:latest` | `paketobuildpacks/builder-jammy-tiny:latest`
| `runImage` + | `runImage` +
(`spring-boot.build-image.runImage`) (`spring-boot.build-image.runImage`)

View File

@ -69,7 +69,7 @@ class ImageTests {
void getBuildRequestWhenNoCustomizationsUsesDefaults() { void getBuildRequestWhenNoCustomizationsUsesDefaults() {
BuildRequest request = new Image().getBuildRequest(createArtifact(), mockApplicationContent()); BuildRequest request = new Image().getBuildRequest(createArtifact(), mockApplicationContent());
assertThat(request.getName()).hasToString("docker.io/library/my-app:0.0.1-SNAPSHOT"); assertThat(request.getName()).hasToString("docker.io/library/my-app:0.0.1-SNAPSHOT");
assertThat(request.getBuilder().toString()).contains("paketobuildpacks/builder-jammy-base"); assertThat(request.getBuilder().toString()).contains("paketobuildpacks/builder-jammy-tiny");
assertThat(request.getRunImage()).isNull(); assertThat(request.getRunImage()).isNull();
assertThat(request.getEnv()).isEmpty(); assertThat(request.getEnv()).isEmpty();
assertThat(request.isCleanCache()).isFalse(); assertThat(request.isCleanCache()).isFalse();

View File

@ -274,13 +274,9 @@ class PaketoBuilderTests {
"paketo-buildpacks/apache-tomcat", "paketo-buildpacks/dist-zip", "paketo-buildpacks/apache-tomcat", "paketo-buildpacks/dist-zip",
"paketo-buildpacks/spring-boot"); "paketo-buildpacks/spring-boot");
metadata.processOfType("web") metadata.processOfType("web")
.satisfiesExactly((command) -> assertThat(command).endsWith("sh"), .containsSubsequence("java", "org.apache.catalina.startup.Bootstrap", "start");
(arg) -> assertThat(arg).endsWith("catalina.sh"),
(arg) -> assertThat(arg).isEqualTo("run"));
metadata.processOfType("tomcat") metadata.processOfType("tomcat")
.satisfiesExactly((command) -> assertThat(command).endsWith("sh"), .containsSubsequence("java", "org.apache.catalina.startup.Bootstrap", "start");
(arg) -> assertThat(arg).endsWith("catalina.sh"),
(arg) -> assertThat(arg).isEqualTo("run"));
}); });
assertImageHasJvmSbomLayer(imageReference, config); assertImageHasJvmSbomLayer(imageReference, config);
assertImageHasDependenciesSbomLayer(imageReference, config, "apache-tomcat"); assertImageHasDependenciesSbomLayer(imageReference, config, "apache-tomcat");

View File

@ -38,5 +38,6 @@ application {
bootBuildImage { bootBuildImage {
archiveFile = bootDistZip.archiveFile archiveFile = bootDistZip.archiveFile
builder = "paketobuildpacks/builder-jammy-base:latest"
environment = ['BP_JVM_VERSION': java.targetCompatibility.getMajorVersion()] environment = ['BP_JVM_VERSION': java.targetCompatibility.getMajorVersion()]
} }

View File

@ -38,5 +38,6 @@ application {
bootBuildImage { bootBuildImage {
archiveFile = distZip.archiveFile archiveFile = distZip.archiveFile
builder = "paketobuildpacks/builder-jammy-base:latest"
environment = ['BP_JVM_VERSION': java.targetCompatibility.getMajorVersion()] environment = ['BP_JVM_VERSION': java.targetCompatibility.getMajorVersion()]
} }