Skip to content

Commit 82749c0

Browse files
committed
Attach lifecycle annotations for rolling tags
1 parent c074f94 commit 82749c0

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

  • EV2Specs/ServiceGroupRoot/Shell/Run

EV2Specs/ServiceGroupRoot/Shell/Run/Run.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ try {
128128
$imgJsonFileContent = Get-Content -Path $pathToImgMetadataJson | ConvertFrom-Json
129129
$images = $imgJsonFileContent.$channel
130130

131+
# Create variables for lifecycle annotations
132+
$endOfLifeDate = Get-Date -Format "yyyy-MM-ddTHH:mm:00Z"
133+
131134
Write-Verbose -Verbose "Push images to ACR"
132135
foreach ($image in $images)
133136
{
@@ -151,6 +154,28 @@ try {
151154
foreach ($tag in $tags)
152155
{
153156
Write-Verbose -Verbose "tag: $tag"
157+
158+
# check if this rolling tag is associated with an image
159+
$mcrImageFullName = "mcr.microsoft.com/powershell:$tag"
160+
oras manifest fetch $mcrImageFullName > $null
161+
$rollingTagExists = $?
162+
163+
if ($rollingTagExists)
164+
{
165+
# If the lineage's rolling tag is already associated with an existing image, attach lifecycle metadata to the existing image to indicate that it is outdated
166+
# Resolve image's digest
167+
$imageDigest = oras resolve $mcrImageName
168+
169+
# Import (old) image by digest from MCR into our ACR
170+
$mcrImageNameDigest = "mcr.microsoft.com/powershell@$imageDigest"
171+
$acrEOLImageTag = "$tag-EOL"
172+
az acr import --name $env:DESTINATION_ACR_NAME --source $mcrImageNameDigest --image $acrEOLImageTag
173+
174+
# Attach lifecycle annotation, which will eventually get synced to MCR
175+
$acrImageNameDigest = "$env:DESTINATION_ACR_NAME.azurecr.io/public/powershell@$imageDigest"
176+
oras attach --artifact-type "application/vnd.microsoft.artifact.lifecycle" --annotation "vnd.microsoft.artifact.lifecycle.end-of-life.date=$endOfLifeDate" $acrImageNameDigest
177+
}
178+
154179
# Need to push image for each tag
155180
$destination_image_full_name = "$env:DESTINATION_ACR_NAME.azurecr.io/public/powershell:${tag}"
156181
Write-Verbose -Verbose "dest img full name: $destination_image_full_name"

0 commit comments

Comments
 (0)