Merge branch '2.5.x' into 2.6.x

Closes gh-28922
pull/29089/head
Scott Frederick 3 years ago
commit 3555837845

@ -54,14 +54,15 @@ final class ImageBuildpack implements Buildpack {
private final ExportedLayers exportedLayers; private final ExportedLayers exportedLayers;
private ImageBuildpack(BuildpackResolverContext context, ImageReference imageReference) { private ImageBuildpack(BuildpackResolverContext context, ImageReference imageReference) {
ImageReference reference = imageReference.inTaggedOrDigestForm();
try { try {
Image image = context.fetchImage(imageReference, ImageType.BUILDPACK); Image image = context.fetchImage(reference, ImageType.BUILDPACK);
BuildpackMetadata buildpackMetadata = BuildpackMetadata.fromImage(image); BuildpackMetadata buildpackMetadata = BuildpackMetadata.fromImage(image);
this.coordinates = BuildpackCoordinates.fromBuildpackMetadata(buildpackMetadata); this.coordinates = BuildpackCoordinates.fromBuildpackMetadata(buildpackMetadata);
this.exportedLayers = new ExportedLayers(context, imageReference); this.exportedLayers = new ExportedLayers(context, reference);
} }
catch (IOException | DockerEngineException ex) { catch (IOException | DockerEngineException ex) {
throw new IllegalArgumentException("Error pulling buildpack image '" + imageReference + "'", ex); throw new IllegalArgumentException("Error pulling buildpack image '" + reference + "'", ex);
} }
} }

@ -31,6 +31,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.springframework.boot.buildpack.platform.docker.type.Image; import org.springframework.boot.buildpack.platform.docker.type.Image;
import org.springframework.boot.buildpack.platform.docker.type.ImageReference;
import org.springframework.boot.buildpack.platform.io.IOBiConsumer; import org.springframework.boot.buildpack.platform.io.IOBiConsumer;
import org.springframework.boot.buildpack.platform.io.TarArchive; import org.springframework.boot.buildpack.platform.io.TarArchive;
import org.springframework.boot.buildpack.platform.json.AbstractJsonTests; import org.springframework.boot.buildpack.platform.json.AbstractJsonTests;
@ -40,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
import static org.assertj.core.api.Assertions.fail; import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.tuple; import static org.assertj.core.api.Assertions.tuple;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willAnswer; import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -64,10 +66,11 @@ class ImageBuildpackTests extends AbstractJsonTests {
@Test @Test
void resolveWhenFullyQualifiedReferenceReturnsBuilder() throws Exception { void resolveWhenFullyQualifiedReferenceReturnsBuilder() throws Exception {
Image image = Image.of(getContent("buildpack-image.json")); Image image = Image.of(getContent("buildpack-image.json"));
ImageReference imageReference = ImageReference.of("example/buildpack1:1.0.0");
BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class); BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class);
given(resolverContext.fetchImage(any(), any())).willReturn(image); given(resolverContext.fetchImage(eq(imageReference), eq(ImageType.BUILDPACK))).willReturn(image);
willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(any(), any()); willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(eq(imageReference), any());
BuildpackReference reference = BuildpackReference.of("docker://example/buildpack1:latest"); BuildpackReference reference = BuildpackReference.of("docker://example/buildpack1:1.0.0");
Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference); Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference);
assertThat(buildpack.getCoordinates()).hasToString("example/hello-universe@0.0.1"); assertThat(buildpack.getCoordinates()).hasToString("example/hello-universe@0.0.1");
assertHasExpectedLayers(buildpack); assertHasExpectedLayers(buildpack);
@ -76,10 +79,38 @@ class ImageBuildpackTests extends AbstractJsonTests {
@Test @Test
void resolveWhenUnqualifiedReferenceReturnsBuilder() throws Exception { void resolveWhenUnqualifiedReferenceReturnsBuilder() throws Exception {
Image image = Image.of(getContent("buildpack-image.json")); Image image = Image.of(getContent("buildpack-image.json"));
ImageReference imageReference = ImageReference.of("example/buildpack1:1.0.0");
BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class); BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class);
given(resolverContext.fetchImage(any(), any())).willReturn(image); given(resolverContext.fetchImage(eq(imageReference), eq(ImageType.BUILDPACK))).willReturn(image);
willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(any(), any()); willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(eq(imageReference), any());
BuildpackReference reference = BuildpackReference.of("example/buildpack1:latest"); BuildpackReference reference = BuildpackReference.of("example/buildpack1:1.0.0");
Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference);
assertThat(buildpack.getCoordinates()).hasToString("example/hello-universe@0.0.1");
assertHasExpectedLayers(buildpack);
}
@Test
void resolveReferenceWithoutTagUsesLatestTag() throws Exception {
Image image = Image.of(getContent("buildpack-image.json"));
ImageReference imageReference = ImageReference.of("example/buildpack1:latest");
BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class);
given(resolverContext.fetchImage(eq(imageReference), eq(ImageType.BUILDPACK))).willReturn(image);
willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(eq(imageReference), any());
BuildpackReference reference = BuildpackReference.of("example/buildpack1");
Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference);
assertThat(buildpack.getCoordinates()).hasToString("example/hello-universe@0.0.1");
assertHasExpectedLayers(buildpack);
}
@Test
void resolveReferenceWithDigestUsesDigest() throws Exception {
Image image = Image.of(getContent("buildpack-image.json"));
String digest = "sha256:4acb6bfd6c4f0cabaf7f3690e444afe51f1c7de54d51da7e63fac709c56f1c30";
ImageReference imageReference = ImageReference.of("example/buildpack1@" + digest);
BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class);
given(resolverContext.fetchImage(eq(imageReference), eq(ImageType.BUILDPACK))).willReturn(image);
willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(eq(imageReference), any());
BuildpackReference reference = BuildpackReference.of("example/buildpack1@" + digest);
Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference); Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference);
assertThat(buildpack.getCoordinates()).hasToString("example/hello-universe@0.0.1"); assertThat(buildpack.getCoordinates()).hasToString("example/hello-universe@0.0.1");
assertHasExpectedLayers(buildpack); assertHasExpectedLayers(buildpack);
@ -89,7 +120,7 @@ class ImageBuildpackTests extends AbstractJsonTests {
void resolveWhenWhenImageNotPulledThrowsException() throws Exception { void resolveWhenWhenImageNotPulledThrowsException() throws Exception {
BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class); BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class);
given(resolverContext.fetchImage(any(), any())).willThrow(IOException.class); given(resolverContext.fetchImage(any(), any())).willThrow(IOException.class);
BuildpackReference reference = BuildpackReference.of("docker://example/buildpack1:latest"); BuildpackReference reference = BuildpackReference.of("docker://example/buildpack1");
assertThatIllegalArgumentException().isThrownBy(() -> ImageBuildpack.resolve(resolverContext, reference)) assertThatIllegalArgumentException().isThrownBy(() -> ImageBuildpack.resolve(resolverContext, reference))
.withMessageContaining("Error pulling buildpack image") .withMessageContaining("Error pulling buildpack image")
.withMessageContaining("example/buildpack1:latest"); .withMessageContaining("example/buildpack1:latest");

Loading…
Cancel
Save