@@ -92,11 +92,52 @@ function acr_login {
9292# $1: image name
9393function oras_attach {
9494 local image_name=$1
95+ local max_retries=3
96+ local retry_count=0
97+
98+ while [ $retry_count -lt $max_retries ]; do
99+ echo " +++ Attempting to attach lifecycle annotation to $image_name (attempt $(( retry_count + 1 )) /$max_retries )"
100+
101+ if oras attach \
102+ --artifact-type " application/vnd.microsoft.artifact.lifecycle" \
103+ --annotation " vnd.microsoft.artifact.lifecycle.end-of-life.date=$END_OF_LIFE_1_YEAR " \
104+ " $image_name " ; then
105+ echo " +++ Successfully attached lifecycle annotation to $image_name "
106+ return 0
107+ else
108+ retry_count=$(( retry_count + 1 ))
109+ if [ $retry_count -lt $max_retries ]; then
110+ echo " +++ Failed to attach lifecycle annotation to $image_name . Retrying in 5 seconds..."
111+ sleep 5
112+ else
113+ echo " +++ Failed to attach lifecycle annotation to $image_name after $max_retries attempts"
114+ return 1
115+ fi
116+ fi
117+ done
118+ }
119+
120+ # Detach the end-of-life annotation from the container image.
121+ # $1: image name
122+ function oras_detach {
123+ local image_name=$1
124+ lifecycle_manifests=$( oras discover -o json --artifact-type " application/vnd.microsoft.artifact.lifecycle" " $image_name " )
125+ manifests=$( echo " $lifecycle_manifests " | jq -r ' .manifests' )
126+
127+ if [[ -z $manifests ]]; then
128+ echo " +++ No lifecycle manifests found for $image_name "
129+ return
130+ fi
95131
96- oras attach \
97- --artifact-type " application/vnd.microsoft.artifact.lifecycle" \
98- --annotation " vnd.microsoft.artifact.lifecycle.end-of-life.date=$END_OF_LIFE_1_YEAR " \
99- " $image_name "
132+ echo " +++ Found lifecycle manifests for $image_name : $manifests "
133+ # Loop through the manifests and delete them.
134+ manifest_count=$( echo " $manifests " | jq length)
135+ for (( i= 0 ; i< manifest_count; i++ )) ; do
136+ digest=$( echo " $lifecycle_manifests " | jq -r " .manifests[$i ].digest" )
137+ echo " Deleting manifest with digest: $digest "
138+ imageNameWithoutTag=${image_name%:* }
139+ oras manifest delete --force " $imageNameWithoutTag @$digest "
140+ done
100141}
101142
102143function create_multi_arch_tags {
@@ -191,6 +232,7 @@ function create_multi_arch_tags {
191232 echo " +++ push $full_multiarch_tag tag"
192233 docker manifest push " $full_multiarch_tag "
193234 echo " +++ $full_multiarch_tag tag pushed successfully"
235+ oras_detach " $full_multiarch_tag "
194236 oras_attach " $full_multiarch_tag "
195237
196238 # Save the multi-arch tag to a file.
281323 docker image tag " $amd64_image " " $amd64_retagged_image_name "
282324 docker rmi " $amd64_image "
283325 docker image push " $amd64_retagged_image_name "
326+ oras_detach " $amd64_retagged_image_name "
284327 oras_attach " $amd64_retagged_image_name "
285328
286329 if [[ $ARCHITECTURE_TO_BUILD == * " ARM64" * ]]; then
289332 docker image tag " $arm64_image " " $arm64_retagged_image_name "
290333 docker rmi " $arm64_image "
291334 docker image push " $arm64_retagged_image_name "
335+ oras_detach " $arm64_retagged_image_name "
292336 oras_attach " $arm64_retagged_image_name "
293337 fi
294338
0 commit comments