Repository: moby/moby (language: go)

Issue:
Dockerfile: use TARGETPLATFORM with scopeo for frozen images stage
- this is the first commit from https://github.com/moby/moby/pull/43529

frozen-images stage doesn't use the download-frozen-image-v2.sh
anymore so we can effectively use TARGETPLATFORM from global scope.
The test util has been updated accordingly.

In a follow-up we can remove download-frozen-image-v2.sh script but
needs to look first at Dockerfile.e2e which seems not used anymore
in our pipeline.


**- A picture of a cute animal (not mandatory but encouraged)**




Discussion / hints:
Interesting; doesn't look related, but not sure I've seen this particular error before (integration-test (windows-2022, containerd, `./...`));

```
=== Failed
=== FAIL: github.com/docker/docker/integration/container TestWaitNonBlocked/wait-nonblocking-exit-random (1.64s)
    wait_test.go:44: assertion failed: error is not nil: Error response from daemon: failed to create shim task: hcs::CreateComputeSystem 5d19c8e979a045bb8db34788add4046c27e44e698d6d61a9c9be601bfb68a3cc: The parameter is incorrect.: unknown
    --- FAIL: TestWaitNonBlocked/wait-nonblocking-exit-random (1.64s)

=== FAIL: github.com/docker/docker/integration/container TestWaitNonBlocked (0.02s)
```
> Is there any reason to keep contrib/download-frozen-image-v2.sh around?

No _strong_ reason, other than that, at some point, it was used by many Kubernetes users to load images in their cluster. That said, I think someone already forked it as a standalone project, so perhaps it's fine to remove as well (it's a nice "reference" though on "how pull works").
> Is there any reason to keep `contrib/download-frozen-image-v2.sh` around?

Yeah we can remove download-frozen-image-v2.sh script in follow-up but needs to look first at Dockerfile.e2e which seems not used anymore in our pipeline. Didn't want to add too much refactoring in https://github.com/moby/moby/pull/43529
@tianon this lgty?
Discussed in the maintainers meeting, and possibly we can fix the same issue by adjusting the bash-script to take variant into account; @crazy-max will have a look if that's an option

Fix patch:
diff --git a/Dockerfile b/Dockerfile
index f4e7ea825de96..299159a697bba 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -74,6 +74,9 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
         && git checkout -q "$GO_SWAGGER_COMMIT" \
         && go build -o /build/swagger github.com/go-swagger/go-swagger/cmd/swagger
 
+# frozen-images
+# See also frozenImages in "testutil/environment/protect.go" (which needs to
+# be updated when adding images to this list)
 FROM debian:${BASE_DEBIAN_DISTRO} AS frozen-images
 ARG DEBIAN_FRONTEND
 RUN --mount=type=cache,sharing=locked,id=moby-frozen-images-aptlib,target=/var/lib/apt \
@@ -85,13 +88,13 @@ RUN --mount=type=cache,sharing=locked,id=moby-frozen-images-aptlib,target=/var/l
 # Get useful and necessary Hub images so we can "docker load" locally instead of pulling
 COPY contrib/download-frozen-image-v2.sh /
 ARG TARGETARCH
+ARG TARGETVARIANT
 RUN /download-frozen-image-v2.sh /build \
         busybox:latest@sha256:95cf004f559831017cdf4628aaf1bb30133677be8702a8c5f2994629f637a209 \
         busybox:glibc@sha256:1f81263701cddf6402afe9f33fca0266d9fff379e59b1748f33d3072da71ee85 \
         debian:bullseye-slim@sha256:dacf278785a4daa9de07596ec739dbc07131e189942772210709c5c0777e8437 \
         hello-world:latest@sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9 \
         arm32v7/hello-world:latest@sha256:50b8560ad574c779908da71f7ce370c0a2471c098d44d1c8f6b513c5a55eeeb1
-# See also frozenImages in "testutil/environment/protect.go" (which needs to be updated when adding images to this list)
 
 FROM base AS cross-false
 
diff --git a/contrib/download-frozen-image-v2.sh b/contrib/download-frozen-image-v2.sh
index b5e05b181aab1..e50f5ebdcc787 100755
--- a/contrib/download-frozen-image-v2.sh
+++ b/contrib/download-frozen-image-v2.sh
@@ -261,6 +261,10 @@ get_target_arch() {
 	echo amd64
 }
 
+get_target_variant() {
+	echo "${TARGETVARIANT:-}"
+}
+
 while [ $# -gt 0 ]; do
 	imageTag="$1"
 	shift
@@ -311,11 +315,13 @@ while [ $# -gt 0 ]; do
 
 					found=""
 					targetArch="$(get_target_arch)"
+					targetVariant="$(get_target_variant)"
 					# parse first level multi-arch manifest
 					for i in "${!layers[@]}"; do
 						layerMeta="${layers[$i]}"
 						maniArch="$(echo "$layerMeta" | jq --raw-output '.platform.architecture')"
-						if [ "$maniArch" = "${targetArch}" ]; then
+						maniVariant="$(echo "$layerMeta" | jq --raw-output '.platform.variant')"
+						if [[ "$maniArch" = "${targetArch}" ]] && [[ -z "${targetVariant}" || "$maniVariant" = "${targetVariant}" ]]; then
 							digest="$(echo "$layerMeta" | jq --raw-output '.digest')"
 							# get second level single manifest
 							submanifestJson="$(
@@ -332,7 +338,7 @@ while [ $# -gt 0 ]; do
 						fi
 					done
 					if [ -z "$found" ]; then
-						echo >&2 "error: manifest for $maniArch is not found"
+						echo >&2 "error: manifest for ${targetArch}${targetVariant:+/${targetVariant}} is not found"
 						exit 1
 					fi
 					;;


Test patch: