Use default tag when pulling run image
Prior to this commit, a default tag of 'latest' was used when no tag was included in the builder image name used when building an image in the Maven and Gradle plugins, but the tag for the run image was left empty if it was not provided. This resulted in errors when pulling the run image from an image repository. This commit applies the same tag defaulting logic to the run image name. Fixes gh-21532
This commit is contained in:
parent
146ebf107c
commit
ed4a7d4ba0
|
|
@ -34,6 +34,7 @@ import org.springframework.util.StringUtils;
|
|||
* Central API for running buildpack operations.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Scott Frederick
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public class Builder {
|
||||
|
|
@ -89,7 +90,7 @@ public class Builder {
|
|||
private ImageReference getRunImageReference(Stack stack) {
|
||||
String name = stack.getRunImage().getImage();
|
||||
Assert.state(StringUtils.hasText(name), "Run image must be specified");
|
||||
return ImageReference.of(name);
|
||||
return ImageReference.of(name).inTaggedForm();
|
||||
}
|
||||
|
||||
private Image pullRunImage(BuildRequest request, ImageReference name) throws IOException {
|
||||
|
|
|
|||
|
|
@ -86,6 +86,26 @@ class BuilderTests {
|
|||
verify(docker.image()).remove(archive.getValue().getTag(), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildInvokesBuilderWithDefaultImageTags() throws Exception {
|
||||
TestPrintStream out = new TestPrintStream();
|
||||
DockerApi docker = mockDockerApi();
|
||||
Image builderImage = loadImage("image-with-no-run-image-tag.json");
|
||||
Image runImage = loadImage("run-image.json");
|
||||
given(docker.image().pull(eq(ImageReference.of("gcr.io/paketo-buildpacks/builder:latest")), any()))
|
||||
.willAnswer(withPulledImage(builderImage));
|
||||
given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:latest")), any()))
|
||||
.willAnswer(withPulledImage(runImage));
|
||||
Builder builder = new Builder(BuildLog.to(out), docker);
|
||||
BuildRequest request = getTestRequest().withBuilder(ImageReference.of("gcr.io/paketo-buildpacks/builder"));
|
||||
builder.build(request);
|
||||
assertThat(out.toString()).contains("Running creator");
|
||||
assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
|
||||
ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
|
||||
verify(docker.image()).load(archive.capture(), any());
|
||||
verify(docker.image()).remove(archive.getValue().getTag(), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildWhenStackIdDoesNotMatchThrowsException() throws Exception {
|
||||
TestPrintStream out = new TestPrintStream();
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue