Skip to content

Commit e6e07a3

Browse files
authored
chore: fix docker-build-and-push-images (#1498)
Signed-off-by: dkarpele <karpelevich@gmail.com>
1 parent aef9615 commit e6e07a3

1 file changed

Lines changed: 33 additions & 27 deletions

File tree

.github/workflows/build-push-images.yaml

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -94,42 +94,48 @@ jobs:
9494
IMAGE_NAME="quay.io/argoprojlabs/argocd-image-updater"
9595
VERSION_TAG="${{ steps.version-tag.outputs.version-tag }}"
9696
97-
# Build list of platform-specific tags that exist
98-
MANIFEST_TAGS=""
99-
100-
# Check if amd64 image exists
101-
if docker manifest inspect ${IMAGE_NAME}:${VERSION_TAG}-amd64 >/dev/null 2>&1; then
102-
MANIFEST_TAGS="${MANIFEST_TAGS} ${IMAGE_NAME}:${VERSION_TAG}-amd64"
97+
# Resolve each platform tag to a single-image digest reference (image@sha256:...).
98+
# Registry or build may expose -amd64/-arm64 as manifest lists; we take the platform digest.
99+
# We must use digest refs only; mixing tag refs in the list can make Quay reject the push.
100+
get_platform_ref() {
101+
local tag=$1
102+
local arch=$2
103+
local inspect
104+
inspect=$(docker manifest inspect "${IMAGE_NAME}:${tag}" 2>/dev/null) || return 1
105+
if echo "${inspect}" | jq -e '.manifests' >/dev/null 2>&1; then
106+
local digest
107+
digest=$(echo "${inspect}" | jq -r --arg a "${arch}" '.manifests[] | select(.platform.architecture == $a) | .digest' | head -n1)
108+
[ -n "${digest}" ] && echo "${IMAGE_NAME}@${digest}" || return 1
109+
else
110+
local digest
111+
digest=$(docker buildx imagetools inspect "${IMAGE_NAME}:${tag}" --format '{{.Digest}}' 2>/dev/null) || return 1
112+
[ -n "${digest}" ] && echo "${IMAGE_NAME}@${digest}" || return 1
113+
fi
114+
}
115+
116+
# Resolve each platform once (used for create and annotate)
117+
REF_AMD64=""
118+
REF_ARM64=""
119+
if ref=$(get_platform_ref "${VERSION_TAG}-amd64" amd64); then
120+
REF_AMD64="${ref}"
103121
fi
104122
105-
# Check if arm64 image exists
106-
if docker manifest inspect ${IMAGE_NAME}:${VERSION_TAG}-arm64 >/dev/null 2>&1; then
107-
MANIFEST_TAGS="${MANIFEST_TAGS} ${IMAGE_NAME}:${VERSION_TAG}-arm64"
123+
if ref=$(get_platform_ref "${VERSION_TAG}-arm64" arm64); then
124+
REF_ARM64="${ref}"
108125
fi
109126
110-
# Remove leading space
111-
MANIFEST_TAGS=$(echo ${MANIFEST_TAGS} | sed 's/^ //')
112-
113-
if [ -z "${MANIFEST_TAGS}" ]; then
127+
REFS=$(echo "${REF_AMD64} ${REF_ARM64}" | sed 's/^ *//;s/ *$//')
128+
if [ -z "${REFS}" ]; then
114129
echo "No platform-specific images found, skipping manifest creation"
115130
exit 0
116131
fi
117132
118-
# Create manifest list
119-
docker manifest create ${IMAGE_NAME}:${VERSION_TAG} ${MANIFEST_TAGS}
133+
# Create manifest list from single-image refs
134+
docker manifest create ${IMAGE_NAME}:${VERSION_TAG} ${REFS}
120135
121-
# Annotate each platform that exists
122-
if docker manifest inspect ${IMAGE_NAME}:${VERSION_TAG}-amd64 >/dev/null 2>&1; then
123-
docker manifest annotate ${IMAGE_NAME}:${VERSION_TAG} \
124-
${IMAGE_NAME}:${VERSION_TAG}-amd64 \
125-
--os linux --arch amd64
126-
fi
127-
128-
if docker manifest inspect ${IMAGE_NAME}:${VERSION_TAG}-arm64 >/dev/null 2>&1; then
129-
docker manifest annotate ${IMAGE_NAME}:${VERSION_TAG} \
130-
${IMAGE_NAME}:${VERSION_TAG}-arm64 \
131-
--os linux --arch arm64
132-
fi
136+
# Annotate each platform (reuse refs from above)
137+
[ -n "${REF_AMD64}" ] && docker manifest annotate ${IMAGE_NAME}:${VERSION_TAG} "${REF_AMD64}" --os linux --arch amd64
138+
[ -n "${REF_ARM64}" ] && docker manifest annotate ${IMAGE_NAME}:${VERSION_TAG} "${REF_ARM64}" --os linux --arch arm64
133139
134140
# Push the manifest
135141
docker manifest push ${IMAGE_NAME}:${VERSION_TAG}

0 commit comments

Comments
 (0)