Add command-line properties for Maven build-image options

This commit adds support for setting the image name and builder
parameters of the Maven spring-boot:build-image goal using command-line
properties as an alternative to plugin configuration in pom.xml. Per
Maven conventions, a value in pom.xml configuration will override a
command-line property when both are provided.

Fixes gh-20520
This commit is contained in:
Scott Frederick
2020-03-17 18:40:37 -05:00
parent f470f27666
commit 08e96427de
5 changed files with 94 additions and 21 deletions

View File

@@ -67,21 +67,45 @@ public class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithCustomImageName(MavenBuild mavenBuild) {
mavenBuild.project("build-image-custom-name").goals("package").execute((project) -> {
File jar = new File(project, "target/build-image-custom-name-0.0.1.BUILD-SNAPSHOT.jar");
assertThat(jar).isFile();
File original = new File(project, "target/build-image-custom-name-0.0.1.BUILD-SNAPSHOT.jar.original");
assertThat(original).doesNotExist();
assertThat(buildLog(project)).contains("Building image")
.contains("example.com/test/build-image:0.0.1.BUILD-SNAPSHOT").contains("Successfully built image");
ImageReference imageReference = ImageReference.of("example.com/test/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-custom-name").goals("package")
.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");
assertThat(jar).isFile();
File original = new File(project,
"target/build-image-custom-name-0.0.1.BUILD-SNAPSHOT.jar.original");
assertThat(original).doesNotExist();
assertThat(buildLog(project)).contains("Building image")
.contains("example.com/test/build-image:0.0.1.BUILD-SNAPSHOT")
.contains("Successfully built image");
ImageReference imageReference = ImageReference
.of("example.com/test/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 whenBuildImageIsInvokedWithCommandLineParameters(MavenBuild mavenBuild) {
mavenBuild.project("build-image").goals("package")
.systemProperty("spring-boot.build-image.imageName", "example.com/test/cmd-property-name:v1")
.systemProperty("spring-boot.build-image.builder", "cloudfoundry/cnb:0.0.43-bionic")
.execute((project) -> {
assertThat(buildLog(project)).contains("Building image")
.contains("example.com/test/cmd-property-name:v1")
.contains("cloudfoundry/cnb:0.0.43-bionic").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();
}
finally {
removeImage(imageReference);
}
});
}
@TestTemplate