@@ -221,27 +221,38 @@ runs:
221221 shell : bash
222222 run : |
223223 CHECK_EXISTING_TAGS="master-${GITHUB_SHA::8} main-${GITHUB_SHA::8}"
224- CONTENT_TYPE="application/vnd.docker.distribution.manifest.v2+json"
224+ # Accept both single-arch manifests and multi-arch manifest lists/indexes
225+ ACCEPT_HEADER="application/vnd.docker.distribution.manifest.v2+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.oci.image.index.v1+json"
225226
226227 echo "CHECK_EXISTING_TAGS: ${CHECK_EXISTING_TAGS}"
227228 echo "RELEASE_TAG: ${RELEASE_TAG:1}"
228229 echo "Check if an image already exists for ${{ inputs.docker-image }}:main|master-${GITHUB_SHA::8} 🐋 ⬇"
229230
230231 foundImage=false
232+ DETECTED_CONTENT_TYPE=""
233+ DIGEST=""
231234
232235 end=$((SECONDS+300))
233236 while [ $SECONDS -lt $end ]; do
234237
235238 MANIFEST=""
236239 for tag in $CHECK_EXISTING_TAGS; do
237- MANIFEST=$(curl -H "Accept: ${CONTENT_TYPE}" -u '${{ inputs.docker-username }}:${{ inputs.docker-password }}' "${{ inputs.docker-registry-api }}${{ inputs.docker-image}}/manifests/${tag}")
240+ # Dump headers to file to extract Content-Type and Digest later
241+ MANIFEST=$(curl -s -D headers.txt -H "Accept: ${ACCEPT_HEADER}" -u '${{ inputs.docker-username }}:${{ inputs.docker-password }}' "${{ inputs.docker-registry-api }}${{ inputs.docker-image}}/manifests/${tag}")
238242
239243 if [[ $MANIFEST == *"errors"* ]]; then
240244 echo "No image found for ${{ inputs.docker-image }}:${tag} 🚫"
241245 continue
242246 else
243247 echo "Image found for ${{ inputs.docker-image }}:${tag} 🐋 ⬇"
244248 foundImage=true
249+
250+ # Extract the Content-Type returned by registry
251+ DETECTED_CONTENT_TYPE=$(grep -i "^Content-Type:" headers.txt | cut -d' ' -f2 | tr -d '\r')
252+
253+ # Extract the correct digest from headers (works for lists and single images)
254+ DIGEST=$(grep -i "^Docker-Content-Digest:" headers.txt | cut -d' ' -f2 | tr -d '\r')
255+
245256 break 2
246257 fi
247258 done
@@ -255,11 +266,12 @@ runs:
255266 fi
256267
257268 echo "Retagging image with release version and :latest tags for ${{ inputs.docker-image }} 🏷"
258- curl --fail-with-body -X PUT -H "Content-Type: ${CONTENT_TYPE}" -u '${{ inputs.docker-username }}:${{ inputs.docker-password }}' -d "${MANIFEST}" "${{ inputs.docker-registry-api }}${{ inputs.docker-image}}/manifests/${{ steps.preparation.outputs.tag }}"
259- curl --fail-with-body -X PUT -H "Content-Type: ${CONTENT_TYPE}" -u '${{ inputs.docker-username }}:${{ inputs.docker-password }}' -d "${MANIFEST}" "${{ inputs.docker-registry-api }}${{ inputs.docker-image}}/manifests/${{ steps.preparation.outputs.latest }}"
269+ echo "Using Content-Type: ${DETECTED_CONTENT_TYPE}"
270+
271+ # Use the detected Content-Type to PUT the manifest back
272+ curl --fail-with-body -X PUT -H "Content-Type: ${DETECTED_CONTENT_TYPE}" -u '${{ inputs.docker-username }}:${{ inputs.docker-password }}' -d "${MANIFEST}" "${{ inputs.docker-registry-api }}${{ inputs.docker-image}}/manifests/${{ steps.preparation.outputs.tag }}"
273+ curl --fail-with-body -X PUT -H "Content-Type: ${DETECTED_CONTENT_TYPE}" -u '${{ inputs.docker-username }}:${{ inputs.docker-password }}' -d "${MANIFEST}" "${{ inputs.docker-registry-api }}${{ inputs.docker-image}}/manifests/${{ steps.preparation.outputs.latest }}"
260274
261- # Get the digest of the image
262- DIGEST=$(echo $MANIFEST | jq .config.digest | tr -d '"')
263275 echo "digest=$DIGEST" >> $GITHUB_OUTPUT
264276
265277 - name : Checkout GitOps Repository
0 commit comments