Skip to content

Commit 9319625

Browse files
committed
Respect pulled digest when inspecting multi-arch images
Capture the digest emitted during the pull stream and inspect name@digest so the newly pulled manifest is always used. issue: #46674. Signed-off-by: hojooo <ghwn5833@gmail.com>
1 parent 6230392 commit 9319625

File tree

2 files changed

+13
-4
lines changed
  • buildpack/spring-boot-buildpack-platform/src

2 files changed

+13
-4
lines changed

buildpack/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/DockerApi.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ public Image pull(ImageReference reference, @Nullable ImagePlatform platform,
239239
listener.onUpdate(event);
240240
});
241241
}
242-
return inspect((platform != null) ? PLATFORM_API_VERSION : API_VERSION, reference);
242+
String digest = digestCapture.getDigest();
243+
ImageReference inspectReference = (digest != null) ? reference.withDigest(digest) : reference;
244+
return inspect((platform != null) ? PLATFORM_API_VERSION : API_VERSION, inspectReference);
243245
}
244246
finally {
245247
listener.onFinish();
@@ -564,6 +566,10 @@ public void onUpdate(ProgressUpdateEvent event) {
564566
}
565567
}
566568

569+
private @Nullable String getDigest() {
570+
return this.digest;
571+
}
572+
567573
}
568574

569575
/**

buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/DockerApiTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ void pullWhenListenerIsNullThrowsException() {
207207
void pullPullsImageAndProducesEvents() throws Exception {
208208
ImageReference reference = ImageReference.of("docker.io/paketobuildpacks/builder:base");
209209
URI createUri = new URI(IMAGES_URL + "/create?fromImage=docker.io%2Fpaketobuildpacks%2Fbuilder%3Abase");
210-
URI imageUri = new URI(IMAGES_URL + "/docker.io/paketobuildpacks/builder:base/json");
210+
URI imageUri = new URI(IMAGES_URL
211+
+ "/docker.io/paketobuildpacks/builder@sha256:4acb6bfd6c4f0cabaf7f3690e444afe51f1c7de54d51da7e63fac709c56f1c30/json");
211212
given(http().post(eq(createUri), isNull())).willReturn(responseOf("pull-stream.json"));
212213
given(http().get(imageUri)).willReturn(responseOf("type/image.json"));
213214
Image image = this.api.pull(reference, null, this.pullListener);
@@ -222,7 +223,8 @@ void pullPullsImageAndProducesEvents() throws Exception {
222223
void pullWithRegistryAuthPullsImageAndProducesEvents() throws Exception {
223224
ImageReference reference = ImageReference.of("docker.io/paketobuildpacks/builder:base");
224225
URI createUri = new URI(IMAGES_URL + "/create?fromImage=docker.io%2Fpaketobuildpacks%2Fbuilder%3Abase");
225-
URI imageUri = new URI(IMAGES_URL + "/docker.io/paketobuildpacks/builder:base/json");
226+
URI imageUri = new URI(IMAGES_URL
227+
+ "/docker.io/paketobuildpacks/builder@sha256:4acb6bfd6c4f0cabaf7f3690e444afe51f1c7de54d51da7e63fac709c56f1c30/json");
226228
given(http().post(eq(createUri), eq("auth token"))).willReturn(responseOf("pull-stream.json"));
227229
given(http().get(imageUri)).willReturn(responseOf("type/image.json"));
228230
Image image = this.api.pull(reference, null, this.pullListener, "auth token");
@@ -239,7 +241,8 @@ void pullWithPlatformPullsImageAndProducesEvents() throws Exception {
239241
ImagePlatform platform = ImagePlatform.of("linux/arm64/v1");
240242
URI createUri = new URI(PLATFORM_IMAGES_URL
241243
+ "/create?fromImage=gcr.io%2Fpaketo-buildpacks%2Fbuilder%3Abase&platform=linux%2Farm64%2Fv1");
242-
URI imageUri = new URI(PLATFORM_IMAGES_URL + "/gcr.io/paketo-buildpacks/builder:base/json");
244+
URI imageUri = new URI(PLATFORM_IMAGES_URL
245+
+ "/gcr.io/paketo-buildpacks/builder@sha256:4acb6bfd6c4f0cabaf7f3690e444afe51f1c7de54d51da7e63fac709c56f1c30/json");
243246
given(http().head(eq(new URI(PING_URL))))
244247
.willReturn(responseWithHeaders(new BasicHeader(DockerApi.API_VERSION_HEADER_NAME, "1.41")));
245248
given(http().post(eq(createUri), isNull())).willReturn(responseOf("pull-stream.json"));

0 commit comments

Comments
 (0)