@@ -107,27 +107,35 @@ jobs:
107107 token=$(curl -sX GET \
108108 "https://ghcr.io/token?scope=repository%3A{{ better_vars.LS_USER }}%2F{{ project_name }}%3Apull" \
109109 | jq -r '.token')
110- {% if better_vars .MULTIARCH == 'true' %}
111110 multidigest=$(curl -s \
112111 --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
113112 --header "Accept: application/vnd.oci.image.index.v1+json" \
114113 --header "Authorization: Bearer ${token}" \
115114 "https://ghcr.io/v2/${image}/manifests/${tag}")
116- multidigest=$(jq -r ".manifests[] | select(.platform.architecture == \"amd64\").digest?" <<< "${multidigest}")
117- digest=$(curl -s \
118- --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
119- --header "Accept: application/vnd.oci.image.manifest.v1+json" \
120- --header "Authorization: Bearer ${token}" \
121- "https://ghcr.io/v2/${image}/manifests/${multidigest}" \
122- | jq -r '.config.digest')
123- {% else %}
124- digest=$(curl -s \
125- --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
126- --header "Accept: application/vnd.oci.image.manifest.v1+json" \
127- --header "Authorization: Bearer ${token}" \
128- "https://ghcr.io/v2/${image}/manifests/${tag}" \
129- | jq -r '.config.digest')
130- {% endif %}
115+ if jq -e '.layers // empty' <<< "${multidigest}" >/dev/null 2>&1 ; then
116+ # If there's a layer element it's a single-arch manifest so just get that digest
117+ digest=$(jq -r '.config.digest' <<< "${multidigest}")
118+ else
119+ # Otherwise it's multi-arch or has manifest annotations
120+ if jq -e '.manifests[]?.annotations // empty' <<< "${multidigest}" >/dev/null 2>&1 ; then
121+ # Check for manifest annotations and delete if found
122+ multidigest=$(jq 'del(.manifests[] | select(.annotations))' <<< "${multidigest}")
123+ fi
124+ if [[ $(jq '.manifests | length' <<< "${multidigest}") -gt 1 ]]; then
125+ # If there's still more than one digest, it's multi-arch
126+ multidigest=$(jq -r ".manifests[] | select(.platform.architecture == \"amd64\").digest?" <<< "${multidigest}")
127+ else
128+ # Otherwise it's single arch
129+ multidigest=$(jq -r ".manifests[].digest?" <<< "${multidigest}")
130+ fi
131+ if digest=$(curl -s \
132+ --header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
133+ --header "Accept: application/vnd.oci.image.manifest.v1+json" \
134+ --header "Authorization: Bearer ${token}" \
135+ "https://ghcr.io/v2/${image}/manifests/${multidigest}"); then
136+ digest=$(jq -r '.config.digest' <<< "${digest}");
137+ fi
138+ fi
131139 image_info=$(curl -sL \
132140 --header "Authorization: Bearer ${token}" \
133141 "https://ghcr.io/v2/${image}/blobs/${digest}")
0 commit comments