From c3ff469a4941c66b3a13899ca1c22b54de1bf535 Mon Sep 17 00:00:00 2001 From: "Steven E. Harris" Date: Thu, 20 Jun 2024 08:25:40 -0400 Subject: [PATCH] fix: accumulate image manifests in oci_image_index In the recent #386, when we replaced use of the "yq" tool with the "jq" tool, we translated the "oci_image_index" rule's accumulation of image manifests incorrectly, such that we lose all but the last index that we add to the index. In "jq", the "update-assignment" operator (|=) does not append to an array supplied as its left-hand context value automatically. Instead, one must use a "complex assignment", mentioning the context value explicitly together with the addition operator. --- examples/multi_architecture_image/BUILD.bazel | 2 +- oci/private/image_index.sh.tpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/multi_architecture_image/BUILD.bazel b/examples/multi_architecture_image/BUILD.bazel index 5a961c9d..c5ed73a6 100644 --- a/examples/multi_architecture_image/BUILD.bazel +++ b/examples/multi_architecture_image/BUILD.bazel @@ -43,5 +43,5 @@ genrule( assert_contains( name = "check_digest", actual = ":hash", - expected = "sha256:9163db354e086c5ef0170ce0ec318312dde887f660552c4a438926863d473d3c", + expected = "sha256:9cc41e3583d5385aa6adc686c15f4e4625ec46fceabde54146add048aa95e716", ) diff --git a/oci/private/image_index.sh.tpl b/oci/private/image_index.sh.tpl index 6b420bb7..531d72fc 100644 --- a/oci/private/image_index.sh.tpl +++ b/oci/private/image_index.sh.tpl @@ -24,7 +24,7 @@ function add_image() { local platform=$("${JQ}" -c '{"os": .os, "architecture": .architecture, "variant": .variant, "os.version": .["os.version"], "os.features": .["os.features"]} | with_entries(select( .value != null ))' "${image_path}/blobs/${config_blob_path}") "${JQ}" --argjson platform "${platform}" \ --argjson manifest "${manifest}" \ - '.manifests |= [$manifest + {"platform": $platform}]'\ + '.manifests += [$manifest + {"platform": $platform}]'\ "${output_path}/manifest_list.json" > "${output_path}/manifest_list.new.json" "${COREUTILS}" cp --no-preserve=mode "${output_path}/manifest_list.new.json" "${output_path}/manifest_list.json" done