Add runImage option for image building

This commit adds a runImage property to the Maven plugin build-image
goal and the Gradle bootBuildImage task. The property allows the user
to override the run image reference provided in the builder metadata
with an alternate run image. The runImage property can be specified
in the build file or on the command line.

Fixes gh-21534
This commit is contained in:
Scott Frederick
2020-06-11 16:20:39 -05:00
parent 025d7aaac8
commit 6119d69679
27 changed files with 427 additions and 89 deletions

View File

@@ -89,13 +89,14 @@ class BootBuildImageIntegrationTests {
}
@TestTemplate
void buildsImageWithCustomBuilder() throws IOException {
void buildsImageWithCustomBuilderAndRunImage() throws IOException {
writeMainClass();
writeLongNameResource();
BuildResult result = this.gradleBuild.build("bootBuildImage");
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput()).contains("example/test-image-custom");
assertThat(result.getOutput()).contains("paketo-buildpacks/builder:full-cf-platform-api-0.3");
assertThat(result.getOutput()).contains("paketo-buildpacks/run:full-cnb-cf");
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();
@@ -110,10 +111,12 @@ class BootBuildImageIntegrationTests {
writeMainClass();
writeLongNameResource();
BuildResult result = this.gradleBuild.build("bootBuildImage", "--imageName=example/test-image-cmd",
"--builder=gcr.io/paketo-buildpacks/builder:full-cf-platform-api-0.3");
"--builder=gcr.io/paketo-buildpacks/builder:full-cf-platform-api-0.3",
"--runImage=gcr.io/paketo-buildpacks/run:full-cnb-cf");
assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
assertThat(result.getOutput()).contains("example/test-image-cmd");
assertThat(result.getOutput()).contains("paketo-buildpacks/builder:full-cf-platform-api-0.3");
assertThat(result.getOutput()).contains("paketo-buildpacks/run:full-cnb-cf");
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();

View File

@@ -183,4 +183,15 @@ class BootBuildImageTests {
assertThat(this.buildImage.createRequest().getBuilder().getName()).isEqualTo("test/builder");
}
@Test
void whenNoRunImageIsConfiguredThenRequestUsesDefaultRunImage() {
assertThat(this.buildImage.createRequest().getRunImage()).isNull();
}
@Test
void whenRunImageIsConfiguredThenRequestUsesSpecifiedRunImage() {
this.buildImage.setRunImage("example.com/test/run:1.0");
assertThat(this.buildImage.createRequest().getRunImage().getName()).isEqualTo("test/run");
}
}