Skip to content

Commit

Permalink
Use default tag when pulling run image
Browse files Browse the repository at this point in the history
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
  • Loading branch information
scottfrederick committed May 21, 2020
1 parent 146ebf1 commit ed4a7d4
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* Central API for running buildpack operations.
*
* @author Phillip Webb
* @author Scott Frederick
* @since 2.3.0
*/
public class Builder {
Expand Down Expand Up @@ -89,7 +90,7 @@ private Image pullBuilder(BuildRequest request) throws IOException {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ void buildInvokesBuilder() throws Exception {
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();
Expand Down

0 comments on commit ed4a7d4

Please sign in to comment.