Skip to content

Commit

Permalink
simplify script
Browse files Browse the repository at this point in the history
  • Loading branch information
ghidalgo3 committed Mar 29, 2024
1 parent 019faf1 commit 6836418
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions scripts/cipublish
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,26 @@ function install_oras() {
}

function deprecate_image() {
local full_image_name=$1
local previous_full_image_digest=$(az acr manifest show-metadata $full_image_name | jq -r .digest)
deprecated_since=$(date --iso-8601=seconds)
echo "Deprecating previous image $full_image_name@$previous_full_image_digest"
local full_image_name_with_digest=$1
deprecated_since=$(date --utc --iso-8601=seconds)
echo "Deprecating previous image $full_image_name_with_digest"
oras attach \
--artifact-type "application/vnd.microsoft.artifact.lifecycle" \
--annotation "vnd.microsoft.artifact.lifecycle.end-of-life.date=$deprecated_since" \
"$full_image_name@$previous_full_image_digest"
"$full_image_name_with_digest"
}

function set_lineage() {
local full_image_name=$1
local new_image_digest=$(az acr manifest show-metadata $full_image_name | jq -r .digest)
local full_image_name_with_digest=$1
# if the annotation already exists, do not add it again
if oras discover $full_image_name@$new_image_digest -o json | jq '.manifests[].annotations."vnd.microsoft.artifact.lineage.rolling-tag"' | grep -q $IMAGE_TAG; then
if oras discover $full_image_name_with_digest -o json | jq '.manifests[].annotations."vnd.microsoft.artifact.lineage.rolling-tag"' | grep -q $IMAGE_TAG; then
echo "Lineage annotation for $IMAGE_TAG already exists, skip."
else
echo "Adding $full_image_name@$new_image_digest to lineage $IMAGE_TAG"
echo "Adding $full_image_name_with_digest to lineage $IMAGE_TAG"
oras attach \
--artifact-type "application/vnd.microsoft.artifact.lineage" \
--annotation "vnd.microsoft.artifact.lineage.rolling-tag=$IMAGE_TAG" \
"$full_image_name@$new_image_digest"
"$full_image_name_with_digest"
fi
}

Expand All @@ -97,15 +95,16 @@ function publish_image() {
if [ "$local_image_digest" != "$remote_image_digest" ]; then
# Image rolling tag exists in the registry, update the end-of-life
# annotation for the existing image.
deprecate_image $full_image_name
deprecate_image "$full_image_name@$remote_image_digest"
else
echo "No changes, licycle metadata annotation will not be attached."
fi

echo "Publishing ${local_image} to ${full_image_name}"
docker tag "${local_image}" "${full_image_name}"
docker push "${full_image_name}"
set_lineage $full_image_name
local remote_image_digest=$(az acr manifest show-metadata $full_image_name | jq -r .digest)
set_lineage "$full_image_name@$remote_image_digest"
}

if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
Expand Down

0 comments on commit 6836418

Please sign in to comment.