diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java index 14e2b8e4c4e0..1a236180bb29 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java @@ -56,11 +56,10 @@ class BootBuildImageIntegrationTests { void buildsImageWithDefaultBuilder() throws IOException { writeMainClass(); writeLongNameResource(); - BuildResult result = this.gradleBuild.build("bootBuildImage"); + BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT"); String projectName = this.gradleBuild.getProjectDir().getName(); assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); assertThat(result.getOutput()).contains("docker.io/library/" + projectName); - assertThat(result.getOutput()).contains("paketobuildpacks/builder"); ImageReference imageReference = ImageReference.of(ImageName.of(projectName)); try (GenericContainer container = new GenericContainer<>(imageReference.toString())) { container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start(); @@ -74,10 +73,9 @@ void buildsImageWithDefaultBuilder() throws IOException { void buildsImageWithCustomName() throws IOException { writeMainClass(); writeLongNameResource(); - BuildResult result = this.gradleBuild.build("bootBuildImage"); + BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT"); assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); assertThat(result.getOutput()).contains("example/test-image-name"); - assertThat(result.getOutput()).contains("paketobuildpacks/builder"); ImageReference imageReference = ImageReference.of(ImageName.of("example/test-image-name")); try (GenericContainer container = new GenericContainer<>(imageReference.toString())) { container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start(); @@ -91,11 +89,9 @@ void buildsImageWithCustomName() throws IOException { void buildsImageWithCustomBuilderAndRunImage() throws IOException { writeMainClass(); writeLongNameResource(); - BuildResult result = this.gradleBuild.build("bootBuildImage"); + BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT"); assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); assertThat(result.getOutput()).contains("example/test-image-custom"); - assertThat(result.getOutput()).contains("paketobuildpacks/builder:full"); - assertThat(result.getOutput()).contains("paketobuildpacks/run:full"); ImageReference imageReference = ImageReference.of(ImageName.of("example/test-image-custom")); try (GenericContainer container = new GenericContainer<>(imageReference.toString())) { container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start(); @@ -109,12 +105,11 @@ void buildsImageWithCustomBuilderAndRunImage() throws IOException { void buildsImageWithCommandLineOptions() throws IOException { writeMainClass(); writeLongNameResource(); - BuildResult result = this.gradleBuild.build("bootBuildImage", "--imageName=example/test-image-cmd", - "--builder=paketobuildpacks/builder:full", "--runImage=paketobuildpacks/run:full-cnb"); + BuildResult result = this.gradleBuild.build("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT", + "--imageName=example/test-image-cmd", "--builder=paketobuildpacks/builder:full", + "--runImage=paketobuildpacks/run:full-cnb"); assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); assertThat(result.getOutput()).contains("example/test-image-cmd"); - assertThat(result.getOutput()).contains("paketobuildpacks/builder:full"); - assertThat(result.getOutput()).contains("paketobuildpacks/run:full"); ImageReference imageReference = ImageReference.of(ImageName.of("example/test-image-cmd")); try (GenericContainer container = new GenericContainer<>(imageReference.toString())) { container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start(); @@ -162,7 +157,7 @@ void failsWithLaunchScript() { void failsWithBuilderError() { writeMainClass(); writeLongNameResource(); - BuildResult result = this.gradleBuild.buildAndFail("bootBuildImage"); + BuildResult result = this.gradleBuild.buildAndFail("bootBuildImage", "--pullPolicy=IF_NOT_PRESENT"); assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.FAILED); assertThat(result.getOutput()).containsPattern("Builder lifecycle '.*' failed with status code"); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildImageTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildImageTests.java index aa86ae63f8bd..5a39c40d5de0 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildImageTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildImageTests.java @@ -47,27 +47,31 @@ public class BuildImageTests extends AbstractArchiveIntegrationTests { @TestTemplate void whenBuildImageIsInvokedWithoutRepackageTheArchiveIsRepackagedOnTheFly(MavenBuild mavenBuild) { - mavenBuild.project("build-image").goals("package").prepare(this::writeLongNameResource).execute((project) -> { - File jar = new File(project, "target/build-image-0.0.1.BUILD-SNAPSHOT.jar"); - assertThat(jar).isFile(); - File original = new File(project, "target/build-image-0.0.1.BUILD-SNAPSHOT.jar.original"); - assertThat(original).doesNotExist(); - assertThat(buildLog(project)).contains("Building image").contains("paketobuildpacks/builder") - .contains("docker.io/library/build-image:0.0.1.BUILD-SNAPSHOT") - .contains("Successfully built image"); - ImageReference imageReference = ImageReference.of(ImageName.of("build-image"), "0.0.1.BUILD-SNAPSHOT"); - try (GenericContainer container = new GenericContainer<>(imageReference.toString())) { - container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start(); - } - finally { - removeImage(imageReference); - } - }); + mavenBuild.project("build-image").goals("package") + .systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT") + .prepare(this::writeLongNameResource).execute((project) -> { + File jar = new File(project, "target/build-image-0.0.1.BUILD-SNAPSHOT.jar"); + assertThat(jar).isFile(); + File original = new File(project, "target/build-image-0.0.1.BUILD-SNAPSHOT.jar.original"); + assertThat(original).doesNotExist(); + assertThat(buildLog(project)).contains("Building image") + .contains("docker.io/library/build-image:0.0.1.BUILD-SNAPSHOT") + .contains("Successfully built image"); + ImageReference imageReference = ImageReference.of(ImageName.of("build-image"), + "0.0.1.BUILD-SNAPSHOT"); + try (GenericContainer container = new GenericContainer<>(imageReference.toString())) { + container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start(); + } + finally { + removeImage(imageReference); + } + }); } @TestTemplate void whenBuildImageIsInvokedWithCustomImageName(MavenBuild mavenBuild) { mavenBuild.project("build-image-custom-name").goals("package") + .systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT") .systemProperty("spring-boot.build-image.imageName", "example.com/test/property-ignored:pom-preferred") .execute((project) -> { File jar = new File(project, "target/build-image-custom-name-0.0.1.BUILD-SNAPSHOT.jar"); @@ -92,13 +96,13 @@ void whenBuildImageIsInvokedWithCustomImageName(MavenBuild mavenBuild) { @TestTemplate void whenBuildImageIsInvokedWithCommandLineParameters(MavenBuild mavenBuild) { mavenBuild.project("build-image").goals("package") + .systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT") .systemProperty("spring-boot.build-image.imageName", "example.com/test/cmd-property-name:v1") .systemProperty("spring-boot.build-image.builder", "paketobuildpacks/builder:full") .systemProperty("spring-boot.build-image.runImage", "paketobuildpacks/run:full-cnb") .execute((project) -> { assertThat(buildLog(project)).contains("Building image") - .contains("example.com/test/cmd-property-name:v1").contains("paketobuildpacks/builder:full") - .contains("paketobuildpacks/run:full").contains("Successfully built image"); + .contains("example.com/test/cmd-property-name:v1").contains("Successfully built image"); ImageReference imageReference = ImageReference.of("example.com/test/cmd-property-name:v1"); try (GenericContainer container = new GenericContainer<>(imageReference.toString())) { container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start(); @@ -111,27 +115,28 @@ void whenBuildImageIsInvokedWithCommandLineParameters(MavenBuild mavenBuild) { @TestTemplate void whenBuildImageIsInvokedWithCustomBuilderImageAndRunImage(MavenBuild mavenBuild) { - mavenBuild.project("build-image-custom-builder").goals("package").execute((project) -> { - assertThat(buildLog(project)).contains("Building image").contains("paketobuildpacks/builder:full") - .contains("paketobuildpacks/run:full") - .contains("docker.io/library/build-image-v2-builder:0.0.1.BUILD-SNAPSHOT") - .contains("Successfully built image"); - ImageReference imageReference = ImageReference - .of("docker.io/library/build-image-v2-builder:0.0.1.BUILD-SNAPSHOT"); - try (GenericContainer container = new GenericContainer<>(imageReference.toString())) { - container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start(); - } - finally { - removeImage(imageReference); - } - }); + mavenBuild.project("build-image-custom-builder").goals("package") + .systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT").execute((project) -> { + assertThat(buildLog(project)).contains("Building image") + .contains("docker.io/library/build-image-v2-builder:0.0.1.BUILD-SNAPSHOT") + .contains("Successfully built image"); + ImageReference imageReference = ImageReference + .of("docker.io/library/build-image-v2-builder:0.0.1.BUILD-SNAPSHOT"); + try (GenericContainer container = new GenericContainer<>(imageReference.toString())) { + container.waitingFor(Wait.forLogMessage("Launched\\n", 1)).start(); + } + finally { + removeImage(imageReference); + } + }); } @TestTemplate void whenBuildImageIsInvokedWithEmptyEnvEntry(MavenBuild mavenBuild) { - mavenBuild.project("build-image-empty-env-entry").goals("package").prepare(this::writeLongNameResource) - .execute((project) -> { - assertThat(buildLog(project)).contains("Building image").contains("paketobuildpacks/builder") + mavenBuild.project("build-image-empty-env-entry").goals("package") + .systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT") + .prepare(this::writeLongNameResource).execute((project) -> { + assertThat(buildLog(project)).contains("Building image") .contains("docker.io/library/build-image-empty-env-entry:0.0.1.BUILD-SNAPSHOT") .contains("Successfully built image"); ImageReference imageReference = ImageReference.of(ImageName.of("build-image-empty-env-entry"), @@ -154,6 +159,7 @@ void failsWhenPublishWithoutPublishRegistryConfigured(MavenBuild mavenBuild) { @TestTemplate void failsWhenBuilderFails(MavenBuild mavenBuild) { mavenBuild.project("build-image-builder-error").goals("package") + .systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT") .executeAndFail((project) -> assertThat(buildLog(project)).contains("Building image") .containsPattern("Builder lifecycle '.*' failed with status code")); }