diff --git a/build/package/postgres-bump.sh b/build/package/postgres-bump.sh index 618ec9ff..31d8e02e 100755 --- a/build/package/postgres-bump.sh +++ b/build/package/postgres-bump.sh @@ -66,15 +66,41 @@ done # Ask the new base image, once per published platform, which builds its pgdg # source offers now. pgdg can publish a build for one architecture before the # other, so a pin moves only to a version both offer. +# Each run uses the platform's own manifest digest: Docker's containerd image +# store refuses to pull one index digest for a second platform ("cannot +# overwrite digest"). The index is read once. +if ! index=$(docker buildx imagetools inspect "$postgres_image" --raw); then + echo "could not read the image index for $postgres_image" >&2 + exit 1 +fi +platform_digest() { + jq -er --arg arch "$1" \ + 'first(.manifests[]? | select(.platform.os == "linux" and .platform.architecture == $arch) | .digest)' \ + <<<"$index" +} candidates() { - docker run --rm --platform "$1" "$postgres_image" sh -c ' + docker run --rm --platform "linux/$1" "${postgres_image%@*}@$2" sh -c ' apt-get update -qq >/dev/null || { echo "apt-get update failed" >&2; exit 1; } for package in "$@"; do printf "%s %s\n" "$package" "$(apt-cache policy "$package" | sed -n "s/^ *Candidate: //p")" done' sh "${names[@]}" } -amd64=$(candidates linux/amd64) -arm64=$(candidates linux/arm64) +amd64="" +arm64="" +for arch in amd64 arm64; do + if ! digest=$(platform_digest "$arch"); then + echo "$postgres_image has no linux/$arch image" >&2 + exit 1 + fi + if ! result=$(candidates "$arch" "$digest"); then + echo "could not list pgdg candidates for linux/$arch" >&2 + exit 1 + fi + case "$arch" in + amd64) amd64=$result ;; + arm64) arm64=$result ;; + esac +done for entry in "${packages[@]}"; do name=${entry%%=*}