Skip to content

Commit 5fb4107

Browse files
detach old eol annotations (#13979)
1 parent 42590a9 commit 5fb4107

1 file changed

Lines changed: 48 additions & 4 deletions

File tree

.pipelines/containerSourceData/scripts/PublishContainers.sh

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,52 @@ function acr_login {
9595
# $1: image name
9696
function oras_attach {
9797
local image_name=$1
98+
local max_retries=3
99+
local retry_count=0
100+
101+
while [ $retry_count -lt $max_retries ]; do
102+
echo "+++ Attempting to attach lifecycle annotation to $image_name (attempt $((retry_count + 1))/$max_retries)"
103+
104+
if oras attach \
105+
--artifact-type "application/vnd.microsoft.artifact.lifecycle" \
106+
--annotation "vnd.microsoft.artifact.lifecycle.end-of-life.date=$END_OF_LIFE_1_YEAR" \
107+
"$image_name"; then
108+
echo "+++ Successfully attached lifecycle annotation to $image_name"
109+
return 0
110+
else
111+
retry_count=$((retry_count + 1))
112+
if [ $retry_count -lt $max_retries ]; then
113+
echo "+++ Failed to attach lifecycle annotation to $image_name. Retrying in 5 seconds..."
114+
sleep 5
115+
else
116+
echo "+++ Failed to attach lifecycle annotation to $image_name after $max_retries attempts"
117+
return 1
118+
fi
119+
fi
120+
done
121+
}
122+
123+
# Detach the end-of-life annotation from the container image.
124+
# $1: image name
125+
function oras_detach {
126+
local image_name=$1
127+
lifecycle_manifests=$(oras discover -o json --artifact-type "application/vnd.microsoft.artifact.lifecycle" "$image_name")
128+
manifests=$(echo "$lifecycle_manifests" | jq -r '.manifests')
129+
130+
if [[ -z $manifests ]]; then
131+
echo "+++ No lifecycle manifests found for $image_name"
132+
return
133+
fi
98134

99-
oras attach \
100-
--artifact-type "application/vnd.microsoft.artifact.lifecycle" \
101-
--annotation "vnd.microsoft.artifact.lifecycle.end-of-life.date=$END_OF_LIFE_1_YEAR" \
102-
"$image_name"
135+
echo "+++ Found lifecycle manifests for $image_name: $manifests"
136+
# Loop through the manifests and delete them.
137+
manifest_count=$(echo "$manifests" | jq length)
138+
for (( i=0; i<manifest_count; i++ )); do
139+
digest=$(echo "$lifecycle_manifests" | jq -r ".manifests[$i].digest")
140+
echo "Deleting manifest with digest: $digest"
141+
imageNameWithoutTag=${image_name%:*}
142+
oras manifest delete --force "$imageNameWithoutTag@$digest"
143+
done
103144
}
104145

105146
function create_multi_arch_tags {
@@ -194,6 +235,7 @@ function create_multi_arch_tags {
194235
echo "+++ push $full_multiarch_tag tag"
195236
docker manifest push "$full_multiarch_tag"
196237
echo "+++ $full_multiarch_tag tag pushed successfully"
238+
oras_detach "$full_multiarch_tag"
197239
oras_attach "$full_multiarch_tag"
198240

199241
# Save the multi-arch tag to a file.
@@ -282,6 +324,7 @@ do
282324
docker image tag "$amd64_image" "$amd64_retagged_image_name"
283325
docker rmi "$amd64_image"
284326
docker image push "$amd64_retagged_image_name"
327+
oras_detach "$amd64_retagged_image_name"
285328
oras_attach "$amd64_retagged_image_name"
286329

287330
if [[ $ARCHITECTURE_TO_BUILD == *"ARM64"* ]]; then
@@ -290,6 +333,7 @@ do
290333
docker image tag "$arm64_image" "$arm64_retagged_image_name"
291334
docker rmi "$arm64_image"
292335
docker image push "$arm64_retagged_image_name"
336+
oras_detach "$arm64_retagged_image_name"
293337
oras_attach "$arm64_retagged_image_name"
294338
fi
295339

0 commit comments

Comments
 (0)