Allow digest builder references

Update `BuildRequest` to also allow digest based references.

Closes gh-21879
This commit is contained in:
Phillip Webb 2020-06-11 12:31:29 -07:00
parent 8a249daf1a
commit 1e7da4d3ca
2 changed files with 11 additions and 2 deletions

View File

@ -84,8 +84,9 @@ public class BuildRequest {
*/
public BuildRequest withBuilder(ImageReference builder) {
Assert.notNull(builder, "Builder must not be null");
return new BuildRequest(this.name, this.applicationContent, builder.inTaggedForm(), this.creator, this.env,
this.cleanCache, this.verboseLogging);
builder = (builder.getDigest() != null) ? builder : builder.inTaggedForm();
return new BuildRequest(this.name, this.applicationContent, builder, this.creator, this.env, this.cleanCache,
this.verboseLogging);
}
/**

View File

@ -98,6 +98,14 @@ public class BuildRequestTests {
assertThat(request.getBuilder().toString()).isEqualTo("docker.io/spring/builder:latest");
}
@Test
void withBuilderWhenHasDigestUpdatesBuilder() throws IOException {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar")).withBuilder(ImageReference
.of("spring/builder:@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d"));
assertThat(request.getBuilder().toString()).isEqualTo(
"docker.io/spring/builder:@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d");
}
@Test
void withCreatorUpdatesCreator() throws IOException {
BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar"));