From c65eb94596b0690032ff0fccbd1213aae96b1afe Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 14:59:11 +1100 Subject: [PATCH 01/67] Pipeline - Adding acr img clean up TODO Fixed #2210 --- .../workflows/weekly-acr-images-cleanup.yml | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/weekly-acr-images-cleanup.yml diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml new file mode 100644 index 000000000..ac22d67b5 --- /dev/null +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -0,0 +1,44 @@ +name: Weekly docker image cleanup + +on: + schedule: + # Monday at 12 PM UTC - https://cron.help/#0_12_*_*_MON + - cron: "0 12 * * MON" + workflow_dispatch: + pull_request: + branches: + - main + +env: + GH_TOKEN: ${{ github.token }} + +defaults: + run: + shell: pwsh + +permissions: + id-token: write + contents: read + +jobs: + check-pr-slots: + runs-on: ubuntu-latest + + steps: + - name: Checking out + uses: actions/checkout@v4 + + - name: Load .env file + uses: xom9ikk/dotenv@v2 + with: + path: ./.github + + - name: ACR - Login + run: | + az acr login --name ${{ env.ACR_LOGIN_SERVER }} + + - name: Get list of acr images + id: imageList + run: | + $slots = $(az acr repository show-tags --name ${{ secrets.ACR_NAME }} --repository ${{ secrets.ACR_REPOSITORY }} --orderby time_desc --detail --output tsv --query "[?tags[?name=='$env:GITHUB_REF']].{tag:tags[0].name, digest:tags[0].digest}") + echo "$slots" From dcc35be000023153b95a1324e2db6ad9487cea53 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:01:44 +1100 Subject: [PATCH 02/67] Adding step to login into Azure --- .github/workflows/weekly-acr-images-cleanup.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index ac22d67b5..2cdc72d79 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -37,6 +37,13 @@ jobs: run: | az acr login --name ${{ env.ACR_LOGIN_SERVER }} + - name: Azure CLI - Login + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + - name: Get list of acr images id: imageList run: | From 74ce1017ffe791467384aa420fbf2e9a8ba7b16a Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:03:17 +1100 Subject: [PATCH 03/67] Updating job name and order of azure login step --- .github/workflows/weekly-acr-images-cleanup.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 2cdc72d79..ec58a011a 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -21,7 +21,7 @@ permissions: contents: read jobs: - check-pr-slots: + check-acr-images: runs-on: ubuntu-latest steps: @@ -33,10 +33,6 @@ jobs: with: path: ./.github - - name: ACR - Login - run: | - az acr login --name ${{ env.ACR_LOGIN_SERVER }} - - name: Azure CLI - Login uses: azure/login@v1 with: @@ -44,6 +40,10 @@ jobs: tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + - name: ACR - Login + run: | + az acr login --name ${{ env.ACR_LOGIN_SERVER }} + - name: Get list of acr images id: imageList run: | From 57394a38f4208dcef3728b4dcad4f9fc77225137 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:05:49 +1100 Subject: [PATCH 04/67] Updating cli command --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index ec58a011a..f3d709f63 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -47,5 +47,5 @@ jobs: - name: Get list of acr images id: imageList run: | - $slots = $(az acr repository show-tags --name ${{ secrets.ACR_NAME }} --repository ${{ secrets.ACR_REPOSITORY }} --orderby time_desc --detail --output tsv --query "[?tags[?name=='$env:GITHUB_REF']].{tag:tags[0].name, digest:tags[0].digest}") + $slots = $(az acr repository show-tags --name ${{ secrets.ACR_NAME }} --repository ${{ secrets.ACR_REPOSITORY }} ) echo "$slots" From 93485ef030f4c692d9f3991b249d8655899accf6 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:13:18 +1100 Subject: [PATCH 05/67] Updating cli to get the list of acr images --- .github/workflows/weekly-acr-images-cleanup.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index f3d709f63..042bc0053 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -47,5 +47,7 @@ jobs: - name: Get list of acr images id: imageList run: | - $slots = $(az acr repository show-tags --name ${{ secrets.ACR_NAME }} --repository ${{ secrets.ACR_REPOSITORY }} ) - echo "$slots" + $slots = az acr repository list show-tags ` + --name ${{ secrets.ACR_NAME }} --repository ` + ${{ secrets.ACR_REPOSITORY }} + Write-Output "$slots" From adfbae4ed85d5525494a7231025cc960bf6c80e9 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:19:39 +1100 Subject: [PATCH 06/67] Adding ACR name and correct image name to get the list --- .github/.env | 1 + .github/workflows/weekly-acr-images-cleanup.yml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/.env b/.github/.env index cc47acd96..23ea90212 100644 --- a/.github/.env +++ b/.github/.env @@ -1,4 +1,5 @@ ACR_LOGIN_SERVER=acrsswwebsite.azurecr.io +ACR_NAME=acrsswwebsite APP_SERVICE_NAME=app-sswwebsite-9eb3 AZURE_RESOURCE_GROUP=ssw.com.au AZURE_RESOURCE_GROUP_LOCATION=australiaeast diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 042bc0053..6f814cd3c 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -48,6 +48,6 @@ jobs: id: imageList run: | $slots = az acr repository list show-tags ` - --name ${{ secrets.ACR_NAME }} --repository ` - ${{ secrets.ACR_REPOSITORY }} + --name ${{ env.ACR_NAME }} --repository ` + ${{ env.IMAGE_NAME }} Write-Output "$slots" From dd1ba7367657c9c499d6c9ae507b730aeeefb5c6 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:21:19 +1100 Subject: [PATCH 07/67] removing show-tags from the cmd --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 6f814cd3c..e6fb1e9e4 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -47,7 +47,7 @@ jobs: - name: Get list of acr images id: imageList run: | - $slots = az acr repository list show-tags ` + $slots = az acr repository list ` --name ${{ env.ACR_NAME }} --repository ` ${{ env.IMAGE_NAME }} Write-Output "$slots" From e78c5d9844abb825bdb6a0ada3168771d8516265 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:43:30 +1100 Subject: [PATCH 08/67] Adding image tag for the list --- .github/workflows/weekly-acr-images-cleanup.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index e6fb1e9e4..7b552d655 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -48,6 +48,6 @@ jobs: id: imageList run: | $slots = az acr repository list ` - --name ${{ env.ACR_NAME }} --repository ` - ${{ env.IMAGE_NAME }} + --name ${{ env.ACR_NAME }} ` + --image ${{ env.IMAGE_NAME }} Write-Output "$slots" From 90167add467b80b213833554accc24b97741817a Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:45:23 +1100 Subject: [PATCH 09/67] removing extra tags for the list --- .github/workflows/weekly-acr-images-cleanup.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 7b552d655..d5e62c0d1 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -48,6 +48,5 @@ jobs: id: imageList run: | $slots = az acr repository list ` - --name ${{ env.ACR_NAME }} ` - --image ${{ env.IMAGE_NAME }} + --name ${{ env.ACR_NAME }} Write-Output "$slots" From 91e06594a4a6c81004703e2e9c0c7bd88bad8c1b Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:51:29 +1100 Subject: [PATCH 10/67] updating cmd to get the tags --- .github/workflows/weekly-acr-images-cleanup.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index d5e62c0d1..ddfe72a72 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -47,6 +47,7 @@ jobs: - name: Get list of acr images id: imageList run: | - $slots = az acr repository list ` - --name ${{ env.ACR_NAME }} + $slots = az acr repository show-tags ` + --name ${{ env.ACR_NAME }} --repository ${{ env.IMAGE_NAME }} ` + --output json | ConvertFrom-Json Write-Output "$slots" From 4ef799e6c593bcce5a5fe119bf4e378e04f8e972 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:57:39 +1100 Subject: [PATCH 11/67] Filtering out the tags --- .github/workflows/weekly-acr-images-cleanup.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index ddfe72a72..a6f8d16b4 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -50,4 +50,6 @@ jobs: $slots = az acr repository show-tags ` --name ${{ env.ACR_NAME }} --repository ${{ env.IMAGE_NAME }} ` --output json | ConvertFrom-Json - Write-Output "$slots" + # Filter tags that start with "pr-" + $filteredTags = $tags | Where-Object { $_ -like "pr-*" } + Write-Output "$filteredTags" From 3d7bd89b47b02a2ede8c5c1bb3bfc65995f832be Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:02:19 +1100 Subject: [PATCH 12/67] Adding order by command for the repo --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index a6f8d16b4..ab6972abb 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -49,7 +49,7 @@ jobs: run: | $slots = az acr repository show-tags ` --name ${{ env.ACR_NAME }} --repository ${{ env.IMAGE_NAME }} ` - --output json | ConvertFrom-Json + --top 10 --orderby time_desc --output json | ConvertFrom-Json # Filter tags that start with "pr-" $filteredTags = $tags | Where-Object { $_ -like "pr-*" } Write-Output "$filteredTags" From f90853b990cd7ffad9f0acd36e8edb5f976866fb Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:04:01 +1100 Subject: [PATCH 13/67] Updating the variable name --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index ab6972abb..f2d4ebc2a 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -51,5 +51,5 @@ jobs: --name ${{ env.ACR_NAME }} --repository ${{ env.IMAGE_NAME }} ` --top 10 --orderby time_desc --output json | ConvertFrom-Json # Filter tags that start with "pr-" - $filteredTags = $tags | Where-Object { $_ -like "pr-*" } + $filteredTags = $slots | Where-Object { $_ -like "pr-*" } Write-Output "$filteredTags" From 8202bb38f8b66e357a26e614322cd64e7d646349 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:11:23 +1100 Subject: [PATCH 14/67] Removing limit on the query --- .github/workflows/weekly-acr-images-cleanup.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index f2d4ebc2a..5292d7927 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -49,7 +49,8 @@ jobs: run: | $slots = az acr repository show-tags ` --name ${{ env.ACR_NAME }} --repository ${{ env.IMAGE_NAME }} ` - --top 10 --orderby time_desc --output json | ConvertFrom-Json + --orderby time_asc --output tsv # Filter tags that start with "pr-" + Write-Output "$slots" $filteredTags = $slots | Where-Object { $_ -like "pr-*" } Write-Output "$filteredTags" From 1531f23d4cabb99316fc450cc2165887706eec9e Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:25:48 +1100 Subject: [PATCH 15/67] Adding comparison for the active PR and images --- .../workflows/weekly-acr-images-cleanup.yml | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 5292d7927..06bf7664a 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -44,13 +44,39 @@ jobs: run: | az acr login --name ${{ env.ACR_LOGIN_SERVER }} + - name: Get list of active PRs + id: prList + run: | + $active_prs=$(gh pr list --state open --json number | jq -r '.[].number') + echo "active_prs=$active_prs" >> $env:GITHUB_OUTPUT + - name: Get list of acr images id: imageList run: | - $slots = az acr repository show-tags ` + $images = az acr repository show-tags ` --name ${{ env.ACR_NAME }} --repository ${{ env.IMAGE_NAME }} ` --orderby time_asc --output tsv # Filter tags that start with "pr-" - Write-Output "$slots" - $filteredTags = $slots | Where-Object { $_ -like "pr-*" } + $filteredTags = $images | Where-Object { $_ -like "pr-*" } + # Remove the "pr-" prefix from filtered tags + $filteredTagsWithoutPrefix = $filteredTags -replace "^pr-", "" + echo "filteredTags=$filteredTagsWithoutPrefix" >> $env:GITHUB_OUTPUT Write-Output "$filteredTags" + + - name: Compare active PRs with existing docker images + id: comparision + run: | + # Comparing the number of images and PRs + $prList = "${{ steps.PRList.outputs.active_prs }}" -split ' ' + $imageList = "${{ steps.imageList.outputs.filteredTags }}" -split ' ' + + $imagesExistThatRequireDeletion = $imageList | Where-Object { $_ -notin $prList } + $imagesNeedDeletion = $imagesExistThatRequireDeletion.Length -gt 0 + + if ( ! $imagesNeedDeletion ) { + echo "✅ - Number of docker images are equal to number of active PRs - 🏃 Skipping next step" + } + else { + echo "❌ - Number of docker images are not equal to number of active PRs" + Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" + } From 8c840c5da7789409c720e2f00bfdd29edb2699b2 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:09:34 +1100 Subject: [PATCH 16/67] Adding pipeline to run the matrix --- .github/workflows/delete-images.yml | 33 +++++++++++++++++++ .../workflows/weekly-acr-images-cleanup.yml | 17 +++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/delete-images.yml diff --git a/.github/workflows/delete-images.yml b/.github/workflows/delete-images.yml new file mode 100644 index 000000000..a27d04a02 --- /dev/null +++ b/.github/workflows/delete-images.yml @@ -0,0 +1,33 @@ +name: Testing - Delete images when PR is closed + +on: + workflow_call: + inputs: + imageTags: + type: string + description: "image IDs" + required: true + +defaults: + run: + shell: pwsh + +env: + IMAGE_TAG: ${{ inputs.imageTags }} + IMAGE_PREFIX: pr- +permissions: + id-token: write + contents: read + +jobs: + delete-image: + runs-on: ubuntu-latest + strategy: + matrix: + SLOT_NAME: ${{ fromJson(inputs.imageTags) }} + + steps: + - uses: actions/checkout@v4 + + - name: Showing tag + run: echo ${{ matrix.SLOT_NAME }} diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 06bf7664a..174415fcf 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -23,6 +23,8 @@ permissions: jobs: check-acr-images: runs-on: ubuntu-latest + outputs: + imagesExistThatRequireDeletion: ${{ steps.comparision.outputs.imagesExistThatRequireDeletion }} steps: - name: Checking out @@ -55,7 +57,7 @@ jobs: run: | $images = az acr repository show-tags ` --name ${{ env.ACR_NAME }} --repository ${{ env.IMAGE_NAME }} ` - --orderby time_asc --output tsv + --top 20 --orderby time_asc --output tsv # Filter tags that start with "pr-" $filteredTags = $images | Where-Object { $_ -like "pr-*" } # Remove the "pr-" prefix from filtered tags @@ -80,3 +82,16 @@ jobs: echo "❌ - Number of docker images are not equal to number of active PRs" Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" } + + invokeDeleteImage: + name: Invoking PR Close/Delete + needs: + - check-acr-images #Adding second check to avoid running this flow + if: needs.check-acr-images.outputs.imagesExistThatRequireDeletion != '' + uses: ./.github/workflows/delete-images.yml + with: + imageTags: ${{ toJson(needs.check-acr-images.outputs.imagesExistThatRequireDeletion) }} + permissions: + id-token: write + contents: read + secrets: inherit From 3d1cc1e12f461d39a88b852977e69837ecb0d1bf Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:15:08 +1100 Subject: [PATCH 17/67] Adding output for the comparison step --- .github/workflows/weekly-acr-images-cleanup.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 174415fcf..3b2bc7bad 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -82,6 +82,7 @@ jobs: echo "❌ - Number of docker images are not equal to number of active PRs" Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" } + echo "imagesExistThatRequireDeletion=$imagesExistThatRequireDeletion" >> $env:GITHUB_OUTPUT invokeDeleteImage: name: Invoking PR Close/Delete From 341ad35958b4eb9cbfd8c3b85e0b6d2c77b48a18 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:55:18 +1100 Subject: [PATCH 18/67] Adding prop as JSON param --- .github/workflows/weekly-acr-images-cleanup.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 3b2bc7bad..6fcf8eb63 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest outputs: imagesExistThatRequireDeletion: ${{ steps.comparision.outputs.imagesExistThatRequireDeletion }} - + matrix: ${{ steps.set-matrix.outputs.matrix }} steps: - name: Checking out uses: actions/checkout@v4 @@ -84,6 +84,18 @@ jobs: } echo "imagesExistThatRequireDeletion=$imagesExistThatRequireDeletion" >> $env:GITHUB_OUTPUT + - name: Converting slots into JSON Formatted Array + id: set-matrix + run: | + # TODO: Tech Debt - need to use it as JSON instead of space delimited - Github issue - https://github.com/SSWConsulting/SSW.Website/issues/1228 + $slotIDs = '${{ steps.comparision.outputs.imagesExistThatRequireDeletion }}' -split ' ' + $slotIDsInJSonArray = ConvertTo-Json -Compress @($slotIDs) + echo "matrix=$slotIDsInJSonArray" >> $env:GITHUB_OUTPUT + + - name: show matrix + run: | + echo "Matrix: ${{ steps.set-matrix.outputs.matrix }}" + invokeDeleteImage: name: Invoking PR Close/Delete needs: @@ -91,7 +103,7 @@ jobs: if: needs.check-acr-images.outputs.imagesExistThatRequireDeletion != '' uses: ./.github/workflows/delete-images.yml with: - imageTags: ${{ toJson(needs.check-acr-images.outputs.imagesExistThatRequireDeletion) }} + imageTags: ${{ needs.check-acr-images.outputs.matrix }} permissions: id-token: write contents: read From 50371270f1827d84e478fc54e28e1ff7f9e2ba82 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 10:50:51 +1100 Subject: [PATCH 19/67] Deleting test image --- .github/workflows/weekly-acr-images-cleanup.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 6fcf8eb63..fd7bb32c7 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -96,6 +96,10 @@ jobs: run: | echo "Matrix: ${{ steps.set-matrix.outputs.matrix }}" + - name: delete img + run: | + az acr repository delete --name ${{ env.ACR_NAME }} --image ${{ env.ACR_NAME }}:pr-102 --yes + invokeDeleteImage: name: Invoking PR Close/Delete needs: From ea147591dfcd940f8a97bde419cfbe8eed8605b0 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 10:53:20 +1100 Subject: [PATCH 20/67] Adding image name with tag to delete it --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index fd7bb32c7..22834f3e0 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -98,7 +98,7 @@ jobs: - name: delete img run: | - az acr repository delete --name ${{ env.ACR_NAME }} --image ${{ env.ACR_NAME }}:pr-102 --yes + az acr repository delete --name ${{ env.ACR_NAME }} --image ${{ env.IMAGE_NAME }}:pr-102 --yes invokeDeleteImage: name: Invoking PR Close/Delete From 9c4b4e1ce7bc82846a3548d24bd736796df54cc0 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 12:15:01 +1100 Subject: [PATCH 21/67] Updating schedule and adding login steps for Azure --- .github/workflows/delete-images.yml | 34 ++++++++++++++++--- .../workflows/weekly-acr-images-cleanup.yml | 8 ++--- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/.github/workflows/delete-images.yml b/.github/workflows/delete-images.yml index a27d04a02..71ebff544 100644 --- a/.github/workflows/delete-images.yml +++ b/.github/workflows/delete-images.yml @@ -7,13 +7,18 @@ on: type: string description: "image IDs" required: true - + workflow_dispatch: + inputs: + imageTag: + description: "Images Tags" + required: true + default: "" defaults: run: shell: pwsh env: - IMAGE_TAG: ${{ inputs.imageTags }} + IMAGE_TAG: ${{ inputs.imageTags || inputs.imageTag }} IMAGE_PREFIX: pr- permissions: id-token: write @@ -24,10 +29,31 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - SLOT_NAME: ${{ fromJson(inputs.imageTags) }} + IMAGE_TAG: ${{ fromJson(inputs.imageTags) }} steps: - uses: actions/checkout@v4 + - name: Load .env file + uses: xom9ikk/dotenv@v2 + with: + path: ./.github + + - name: Azure CLI - Login + uses: azure/login@v1 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: ACR - Login + run: | + az acr login --name ${{ env.ACR_LOGIN_SERVER }} + - name: Showing tag - run: echo ${{ matrix.SLOT_NAME }} + run: echo ${{ matrix.IMAGE_TAG }} + + # - name: ACR - Delete img + # run: | + # az acr repository delete --name ${{ env.ACR_NAME }} ` + # --image ${{ env.IMAGE_NAME }}:${{ env.IMAGE_PREFIX }}${{ matrix.IMAGE_TAG}} --yes diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 22834f3e0..549128041 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -2,8 +2,8 @@ name: Weekly docker image cleanup on: schedule: - # Monday at 12 PM UTC - https://cron.help/#0_12_*_*_MON - - cron: "0 12 * * MON" + # Monday at 2 PM UTC - https://cron.help/#0_14_*_*_MON + - cron: "0 14 * * MON" workflow_dispatch: pull_request: branches: @@ -96,10 +96,6 @@ jobs: run: | echo "Matrix: ${{ steps.set-matrix.outputs.matrix }}" - - name: delete img - run: | - az acr repository delete --name ${{ env.ACR_NAME }} --image ${{ env.IMAGE_NAME }}:pr-102 --yes - invokeDeleteImage: name: Invoking PR Close/Delete needs: From da247a3b5f53c4b011cae15c72a0040c325524e6 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 13:04:40 +1100 Subject: [PATCH 22/67] cleaning weekly check and adding updated checks --- ...delete-images.yml => delete-acr-image.yml} | 20 ++++---- .../workflows/weekly-acr-images-cleanup.yml | 50 ++++++++----------- 2 files changed, 31 insertions(+), 39 deletions(-) rename .github/workflows/{delete-images.yml => delete-acr-image.yml} (70%) diff --git a/.github/workflows/delete-images.yml b/.github/workflows/delete-acr-image.yml similarity index 70% rename from .github/workflows/delete-images.yml rename to .github/workflows/delete-acr-image.yml index 71ebff544..080cd34b3 100644 --- a/.github/workflows/delete-images.yml +++ b/.github/workflows/delete-acr-image.yml @@ -1,31 +1,31 @@ -name: Testing - Delete images when PR is closed +name: Delete - Docker image from ACR on: workflow_call: inputs: imageTags: type: string - description: "image IDs" + description: "Image Tags or PR numbers" required: true workflow_dispatch: inputs: imageTag: - description: "Images Tags" + description: "Images Tag or PR number" required: true - default: "" + defaults: run: shell: pwsh env: IMAGE_TAG: ${{ inputs.imageTags || inputs.imageTag }} - IMAGE_PREFIX: pr- + PREFIX: pr- permissions: id-token: write contents: read jobs: - delete-image: + delete-acr-image: runs-on: ubuntu-latest strategy: matrix: @@ -50,10 +50,8 @@ jobs: run: | az acr login --name ${{ env.ACR_LOGIN_SERVER }} - - name: Showing tag - run: echo ${{ matrix.IMAGE_TAG }} - - # - name: ACR - Delete img + # - name: ACR - Delete image # run: | # az acr repository delete --name ${{ env.ACR_NAME }} ` - # --image ${{ env.IMAGE_NAME }}:${{ env.IMAGE_PREFIX }}${{ matrix.IMAGE_TAG}} --yes + # --image ${{ env.IMAGE_NAME }}:${{ env.PREFIX }}${{ matrix.IMAGE_TAG}} --yes + # Write-Output "✅ ACR - ${{ env.IMAGE_NAME }}:${{ env.PREFIX }}${{ matrix.IMAGE_TAG}} image deleted successfully." diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 549128041..93b4c489a 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -1,4 +1,4 @@ -name: Weekly docker image cleanup +name: Weekly ACR images cleanup on: schedule: @@ -24,8 +24,7 @@ jobs: check-acr-images: runs-on: ubuntu-latest outputs: - imagesExistThatRequireDeletion: ${{ steps.comparision.outputs.imagesExistThatRequireDeletion }} - matrix: ${{ steps.set-matrix.outputs.matrix }} + imageTagList: ${{ steps.comparison.outputs.imageTagList }} steps: - name: Checking out uses: actions/checkout@v4 @@ -42,37 +41,40 @@ jobs: tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - name: ACR - Login - run: | - az acr login --name ${{ env.ACR_LOGIN_SERVER }} - - name: Get list of active PRs id: prList run: | $active_prs=$(gh pr list --state open --json number | jq -r '.[].number') echo "active_prs=$active_prs" >> $env:GITHUB_OUTPUT - - name: Get list of acr images - id: imageList + - name: ACR - Login + run: | + az acr login --name ${{ env.ACR_LOGIN_SERVER }} + + - name: Get list of ACR image tags + id: imageTags run: | $images = az acr repository show-tags ` --name ${{ env.ACR_NAME }} --repository ${{ env.IMAGE_NAME }} ` --top 20 --orderby time_asc --output tsv + # Filter tags that start with "pr-" $filteredTags = $images | Where-Object { $_ -like "pr-*" } + # Remove the "pr-" prefix from filtered tags $filteredTagsWithoutPrefix = $filteredTags -replace "^pr-", "" + echo "filteredTags=$filteredTagsWithoutPrefix" >> $env:GITHUB_OUTPUT Write-Output "$filteredTags" - - name: Compare active PRs with existing docker images - id: comparision + - name: Compare active PRs with existing ACR images + id: comparison run: | # Comparing the number of images and PRs $prList = "${{ steps.PRList.outputs.active_prs }}" -split ' ' - $imageList = "${{ steps.imageList.outputs.filteredTags }}" -split ' ' + $imageTags = "${{ steps.imageTags.outputs.filteredTags }}" -split ' ' - $imagesExistThatRequireDeletion = $imageList | Where-Object { $_ -notin $prList } + $imagesExistThatRequireDeletion = $imageTags | Where-Object { $_ -notin $prList } $imagesNeedDeletion = $imagesExistThatRequireDeletion.Length -gt 0 if ( ! $imagesNeedDeletion ) { @@ -82,28 +84,20 @@ jobs: echo "❌ - Number of docker images are not equal to number of active PRs" Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" } - echo "imagesExistThatRequireDeletion=$imagesExistThatRequireDeletion" >> $env:GITHUB_OUTPUT - - name: Converting slots into JSON Formatted Array - id: set-matrix - run: | - # TODO: Tech Debt - need to use it as JSON instead of space delimited - Github issue - https://github.com/SSWConsulting/SSW.Website/issues/1228 - $slotIDs = '${{ steps.comparision.outputs.imagesExistThatRequireDeletion }}' -split ' ' - $slotIDsInJSonArray = ConvertTo-Json -Compress @($slotIDs) - echo "matrix=$slotIDsInJSonArray" >> $env:GITHUB_OUTPUT + $tags = $imagesExistThatRequireDeletion -split ' ' + $imageTagList = ConvertTo-Json -Compress @($tags) - - name: show matrix - run: | - echo "Matrix: ${{ steps.set-matrix.outputs.matrix }}" + echo "imageTagList=$imageTagList" >> $env:GITHUB_OUTPUT invokeDeleteImage: - name: Invoking PR Close/Delete + name: Invoking delete-acr-image.yml needs: - check-acr-images #Adding second check to avoid running this flow - if: needs.check-acr-images.outputs.imagesExistThatRequireDeletion != '' - uses: ./.github/workflows/delete-images.yml + if: needs.check-acr-images.outputs.imageTagList != '[""]' + uses: ./.github/workflows/delete-acr-image.yml with: - imageTags: ${{ needs.check-acr-images.outputs.matrix }} + imageTags: ${{ needs.check-acr-images.outputs.imageTagList }} permissions: id-token: write contents: read From ad2b5cffca8d7d1788b84f5670a75a6012ee3f04 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 14:34:48 +1100 Subject: [PATCH 23/67] removing the tags limit --- .github/workflows/weekly-acr-images-cleanup.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 93b4c489a..6ec972e9a 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -56,7 +56,7 @@ jobs: run: | $images = az acr repository show-tags ` --name ${{ env.ACR_NAME }} --repository ${{ env.IMAGE_NAME }} ` - --top 20 --orderby time_asc --output tsv + --orderby time_asc --output tsv # Filter tags that start with "pr-" $filteredTags = $images | Where-Object { $_ -like "pr-*" } @@ -91,7 +91,7 @@ jobs: echo "imageTagList=$imageTagList" >> $env:GITHUB_OUTPUT invokeDeleteImage: - name: Invoking delete-acr-image.yml + name: Invoking delete-acr-image needs: - check-acr-images #Adding second check to avoid running this flow if: needs.check-acr-images.outputs.imageTagList != '[""]' From ec5b6d84e057753232e1450677cd17ce1b6fbffe Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 14:37:41 +1100 Subject: [PATCH 24/67] Adding limiting to 250 --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 6ec972e9a..fa065b113 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -56,7 +56,7 @@ jobs: run: | $images = az acr repository show-tags ` --name ${{ env.ACR_NAME }} --repository ${{ env.IMAGE_NAME }} ` - --orderby time_asc --output tsv + --top 250 --orderby time_asc --output tsv # Filter tags that start with "pr-" $filteredTags = $images | Where-Object { $_ -like "pr-*" } From cc59f3d5e14aa39bd75883282a48104df2cff3ff Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 14:46:14 +1100 Subject: [PATCH 25/67] Adding deletion step to clean up the image --- .github/workflows/delete-acr-image.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/delete-acr-image.yml b/.github/workflows/delete-acr-image.yml index 080cd34b3..075f806a3 100644 --- a/.github/workflows/delete-acr-image.yml +++ b/.github/workflows/delete-acr-image.yml @@ -50,8 +50,8 @@ jobs: run: | az acr login --name ${{ env.ACR_LOGIN_SERVER }} - # - name: ACR - Delete image - # run: | - # az acr repository delete --name ${{ env.ACR_NAME }} ` - # --image ${{ env.IMAGE_NAME }}:${{ env.PREFIX }}${{ matrix.IMAGE_TAG}} --yes - # Write-Output "✅ ACR - ${{ env.IMAGE_NAME }}:${{ env.PREFIX }}${{ matrix.IMAGE_TAG}} image deleted successfully." + - name: ACR - Delete image + run: | + az acr repository delete --name ${{ env.ACR_NAME }} ` + --image ${{ env.IMAGE_NAME }}:${{ env.PREFIX }}${{ matrix.IMAGE_TAG}} --yes + Write-Output "✅ ACR - ${{ env.IMAGE_NAME }}:${{ env.PREFIX }}${{ matrix.IMAGE_TAG}} image deleted successfully." From f88c419c59c40a88f1093fe5206a2fb48d29c55b Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:06:15 +1100 Subject: [PATCH 26/67] Adding comment and reducing noise --- .github/workflows/weekly-acr-images-cleanup.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index fa065b113..25e07ed1c 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -56,7 +56,7 @@ jobs: run: | $images = az acr repository show-tags ` --name ${{ env.ACR_NAME }} --repository ${{ env.IMAGE_NAME }} ` - --top 250 --orderby time_asc --output tsv + --top 250 --orderby time_asc --output tsv # Limiting to 250 tags because of the GitHub action matrix limit # Filter tags that start with "pr-" $filteredTags = $images | Where-Object { $_ -like "pr-*" } @@ -65,7 +65,6 @@ jobs: $filteredTagsWithoutPrefix = $filteredTags -replace "^pr-", "" echo "filteredTags=$filteredTagsWithoutPrefix" >> $env:GITHUB_OUTPUT - Write-Output "$filteredTags" - name: Compare active PRs with existing ACR images id: comparison From ae395366c38ace3d9a5fa4be23e4e7b79a81ec15 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:25:31 +1100 Subject: [PATCH 27/67] Adding non-pr prefixed tags --- .github/workflows/weekly-acr-images-cleanup.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 25e07ed1c..1216787b1 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -61,10 +61,14 @@ jobs: # Filter tags that start with "pr-" $filteredTags = $images | Where-Object { $_ -like "pr-*" } + # Filter tags that do not start with start with "pr-" + $tagsWithoutPRPrefix = $images | Where-Object { $_ -notlike "pr-*" } + # Remove the "pr-" prefix from filtered tags $filteredTagsWithoutPrefix = $filteredTags -replace "^pr-", "" echo "filteredTags=$filteredTagsWithoutPrefix" >> $env:GITHUB_OUTPUT + echo "tagsWithoutPRPrefix=$tagsWithoutPRTags" >> $env:GITHUB_OUTPUT - name: Compare active PRs with existing ACR images id: comparison @@ -84,6 +88,7 @@ jobs: Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" } + $mergedTags = $imagesExistThatRequireDeletion + ${{ steps.imageTags.outputs.tagsWithoutPRPrefix }} $tags = $imagesExistThatRequireDeletion -split ' ' $imageTagList = ConvertTo-Json -Compress @($tags) From d28cbfb61486c8d96b7825ea7f0db46bcd8afcd3 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:27:51 +1100 Subject: [PATCH 28/67] Tags - Wrapping it with quote --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 1216787b1..64a458bf2 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -88,7 +88,7 @@ jobs: Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" } - $mergedTags = $imagesExistThatRequireDeletion + ${{ steps.imageTags.outputs.tagsWithoutPRPrefix }} + $mergedTags = $imagesExistThatRequireDeletion + '${{ steps.imageTags.outputs.tagsWithoutPRPrefix }}' $tags = $imagesExistThatRequireDeletion -split ' ' $imageTagList = ConvertTo-Json -Compress @($tags) From ac184ff06ec8328f917784db4e66444a720f7622 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:31:10 +1100 Subject: [PATCH 29/67] Updating the variable name --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 64a458bf2..b09714adf 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -68,7 +68,7 @@ jobs: $filteredTagsWithoutPrefix = $filteredTags -replace "^pr-", "" echo "filteredTags=$filteredTagsWithoutPrefix" >> $env:GITHUB_OUTPUT - echo "tagsWithoutPRPrefix=$tagsWithoutPRTags" >> $env:GITHUB_OUTPUT + echo "tagsWithoutPRPrefix=$tagsWithoutPRPrefix" >> $env:GITHUB_OUTPUT - name: Compare active PRs with existing ACR images id: comparison From 73713cfa7d35f39a59210901402e28d0402fec53 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:33:19 +1100 Subject: [PATCH 30/67] echoing non-pr tags --- .github/workflows/weekly-acr-images-cleanup.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index b09714adf..3ee1adf0b 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -64,6 +64,8 @@ jobs: # Filter tags that do not start with start with "pr-" $tagsWithoutPRPrefix = $images | Where-Object { $_ -notlike "pr-*" } + Write-Host "$tagsWithoutPRPrefix" + # Remove the "pr-" prefix from filtered tags $filteredTagsWithoutPrefix = $filteredTags -replace "^pr-", "" From 82ff7cf80ef8864b8effc2abf50b3f5dd896b18b Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:36:01 +1100 Subject: [PATCH 31/67] merging non-pr tags --- .github/workflows/weekly-acr-images-cleanup.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 3ee1adf0b..3294d208e 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -89,8 +89,8 @@ jobs: echo "❌ - Number of docker images are not equal to number of active PRs" Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" } - - $mergedTags = $imagesExistThatRequireDeletion + '${{ steps.imageTags.outputs.tagsWithoutPRPrefix }}' + $non-pr-tags = "${{ steps.imageTags.outputs.tagsWithoutPRPrefix }}" + $mergedTags = $imagesExistThatRequireDeletion + $non-pr-tags $tags = $imagesExistThatRequireDeletion -split ' ' $imageTagList = ConvertTo-Json -Compress @($tags) From 2b1e64c57005bedc66094bd014ae17835bf8d7d4 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:37:34 +1100 Subject: [PATCH 32/67] Fixing the variable name --- .github/workflows/weekly-acr-images-cleanup.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 3294d208e..22bf6374d 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -89,8 +89,8 @@ jobs: echo "❌ - Number of docker images are not equal to number of active PRs" Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" } - $non-pr-tags = "${{ steps.imageTags.outputs.tagsWithoutPRPrefix }}" - $mergedTags = $imagesExistThatRequireDeletion + $non-pr-tags + $nonPRTags = "${{ steps.imageTags.outputs.tagsWithoutPRPrefix }}" + $mergedTags = $imagesExistThatRequireDeletion + $nonPRTags $tags = $imagesExistThatRequireDeletion -split ' ' $imageTagList = ConvertTo-Json -Compress @($tags) From 1015741dc7ffafa0be31c15769656b5278e4cb84 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:40:22 +1100 Subject: [PATCH 33/67] updating variable name --- .github/workflows/weekly-acr-images-cleanup.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 22bf6374d..4bd746356 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -64,8 +64,6 @@ jobs: # Filter tags that do not start with start with "pr-" $tagsWithoutPRPrefix = $images | Where-Object { $_ -notlike "pr-*" } - Write-Host "$tagsWithoutPRPrefix" - # Remove the "pr-" prefix from filtered tags $filteredTagsWithoutPrefix = $filteredTags -replace "^pr-", "" @@ -90,8 +88,8 @@ jobs: Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" } $nonPRTags = "${{ steps.imageTags.outputs.tagsWithoutPRPrefix }}" - $mergedTags = $imagesExistThatRequireDeletion + $nonPRTags - $tags = $imagesExistThatRequireDeletion -split ' ' + $allTags = $imagesExistThatRequireDeletion + $nonPRTags + $tags = $allTags -split ' ' $imageTagList = ConvertTo-Json -Compress @($tags) echo "imageTagList=$imageTagList" >> $env:GITHUB_OUTPUT From 57478683f92a22e1908a8aeb9099e0dfe383de48 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:05:33 +1100 Subject: [PATCH 34/67] Adding prefix condition for non-pr tags --- .github/workflows/delete-acr-image.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/delete-acr-image.yml b/.github/workflows/delete-acr-image.yml index 075f806a3..ce0206a4a 100644 --- a/.github/workflows/delete-acr-image.yml +++ b/.github/workflows/delete-acr-image.yml @@ -52,6 +52,12 @@ jobs: - name: ACR - Delete image run: | + if('${{ matrix.IMAGE_TAG }}'.Length -le 4) + { + $imageTagWithPrefix = ${{ env.PREFIX }}${{ matrix.IMAGE_TAG}} + }else{ + $imageTagWithPrefix = ${{ matrix.IMAGE_TAG }} + } az acr repository delete --name ${{ env.ACR_NAME }} ` - --image ${{ env.IMAGE_NAME }}:${{ env.PREFIX }}${{ matrix.IMAGE_TAG}} --yes - Write-Output "✅ ACR - ${{ env.IMAGE_NAME }}:${{ env.PREFIX }}${{ matrix.IMAGE_TAG}} image deleted successfully." + --image ${{ env.IMAGE_NAME }}:$imageTagWithPrefix --yes + Write-Output "✅ ACR - ${{ env.IMAGE_NAME }}:$imageTagWithPrefix image deleted successfully." From fdf99279a8a7469b41f0507e8f1812aacc6ca856 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 16:10:33 +1100 Subject: [PATCH 35/67] wrapping text around input values --- .github/workflows/delete-acr-image.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/delete-acr-image.yml b/.github/workflows/delete-acr-image.yml index ce0206a4a..47bdbc7b4 100644 --- a/.github/workflows/delete-acr-image.yml +++ b/.github/workflows/delete-acr-image.yml @@ -52,11 +52,11 @@ jobs: - name: ACR - Delete image run: | - if('${{ matrix.IMAGE_TAG }}'.Length -le 4) + if('${{ matrix.IMAGE_TAG }}'.Length -le 4) # PR tags contain 4 digits { - $imageTagWithPrefix = ${{ env.PREFIX }}${{ matrix.IMAGE_TAG}} + $imageTagWithPrefix = '${{ env.PREFIX }}${{ matrix.IMAGE_TAG}}' }else{ - $imageTagWithPrefix = ${{ matrix.IMAGE_TAG }} + $imageTagWithPrefix = '${{ matrix.IMAGE_TAG }}' } az acr repository delete --name ${{ env.ACR_NAME }} ` --image ${{ env.IMAGE_NAME }}:$imageTagWithPrefix --yes From b1a3a768673cc4ea727d503769a1718090dc7b64 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:08:04 +1100 Subject: [PATCH 36/67] Adding additional checks to not delete production and staging acr --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 4bd746356..e020e3193 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -62,7 +62,7 @@ jobs: $filteredTags = $images | Where-Object { $_ -like "pr-*" } # Filter tags that do not start with start with "pr-" - $tagsWithoutPRPrefix = $images | Where-Object { $_ -notlike "pr-*" } + $tagsWithoutPRPrefix = $images | Where-Object { $_ -notlike "pr-*" -and $_ -notmatch "staging|production" } # Remove the "pr-" prefix from filtered tags $filteredTagsWithoutPrefix = $filteredTags -replace "^pr-", "" From 916af893ce2e0a7872aa60d49534b264a0aaea9c Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:16:17 +1100 Subject: [PATCH 37/67] Adding staging and production sha --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index e020e3193..ce16fb851 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -62,7 +62,7 @@ jobs: $filteredTags = $images | Where-Object { $_ -like "pr-*" } # Filter tags that do not start with start with "pr-" - $tagsWithoutPRPrefix = $images | Where-Object { $_ -notlike "pr-*" -and $_ -notmatch "staging|production" } + $tagsWithoutPRPrefix = $images | Where-Object { $_ -notlike "pr-*" -and $_ -notmatch "staging|production|a21f1263dfaa4e4977595912a8cc80c95f737f98|89a9bccde9c2a407b85105e3261d17ed27006160" } # Remove the "pr-" prefix from filtered tags $filteredTagsWithoutPrefix = $filteredTags -replace "^pr-", "" From d4f2cb19f3022430a6224f8430bfded65999b990 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:27:51 +1100 Subject: [PATCH 38/67] removing PRs for temporary --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index ce16fb851..05f628c41 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -88,7 +88,7 @@ jobs: Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" } $nonPRTags = "${{ steps.imageTags.outputs.tagsWithoutPRPrefix }}" - $allTags = $imagesExistThatRequireDeletion + $nonPRTags + $allTags = $nonPRTags $tags = $allTags -split ' ' $imageTagList = ConvertTo-Json -Compress @($tags) From 9f94c919bc1aebd53f900d8b2b2a67c25638702c Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:52:51 +1100 Subject: [PATCH 39/67] deleting based on digest value --- .github/workflows/delete-acr-image.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/delete-acr-image.yml b/.github/workflows/delete-acr-image.yml index 47bdbc7b4..170470187 100644 --- a/.github/workflows/delete-acr-image.yml +++ b/.github/workflows/delete-acr-image.yml @@ -58,6 +58,14 @@ jobs: }else{ $imageTagWithPrefix = '${{ matrix.IMAGE_TAG }}' } + + # Get the digest of the specific tag + $digest = az acr repository show-manifests --name ${{ env.ACR_NAME }} ` + --repository ${{ env.IMAGE_NAME }} --output json ` + --query "[?tags.contains('$imageTagWithPrefix')].digest" --output tsv + + # Delete the digest (and all associated tags) az acr repository delete --name ${{ env.ACR_NAME }} ` - --image ${{ env.IMAGE_NAME }}:$imageTagWithPrefix --yes - Write-Output "✅ ACR - ${{ env.IMAGE_NAME }}:$imageTagWithPrefix image deleted successfully." + --image ${{ env.IMAGE_NAME }} --digest $digest --yes + + Write-Output "✅ ACR - image deleted with $digest digest" From 2b2840ad5343fc78cd1abc18dc16c65b1d1d3dfb Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 19:51:18 +1100 Subject: [PATCH 40/67] Getting digest data for specific ACR --- .../workflows/weekly-acr-images-cleanup.yml | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 05f628c41..f58b6d086 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -94,15 +94,24 @@ jobs: echo "imageTagList=$imageTagList" >> $env:GITHUB_OUTPUT - invokeDeleteImage: - name: Invoking delete-acr-image - needs: - - check-acr-images #Adding second check to avoid running this flow - if: needs.check-acr-images.outputs.imageTagList != '[""]' - uses: ./.github/workflows/delete-acr-image.yml - with: - imageTags: ${{ needs.check-acr-images.outputs.imageTagList }} - permissions: - id-token: write - contents: read - secrets: inherit + - name: Set outputs + id: set-outputs + run: | + # Get the digest of the specific tag + $digest = az acr manifest list-metadata --name ${{ env.ACR_NAME }} ` + --repository ${{ env.IMAGE_NAME }} --output json ` + --query "[?tags.contains('pr-2226')].digest" --output tsv + Write-Host "Digest: $digest" + + # invokeDeleteImage: + # name: Invoking delete-acr-image + # needs: + # - check-acr-images #Adding second check to avoid running this flow + # if: needs.check-acr-images.outputs.imageTagList != '[""]' + # uses: ./.github/workflows/delete-acr-image.yml + # with: + # imageTags: ${{ needs.check-acr-images.outputs.imageTagList }} + # permissions: + # id-token: write + # contents: read + # secrets: inherit From 479a776bcf190b9f37e1d6b91b7cb9d6229514ec Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 19:53:02 +1100 Subject: [PATCH 41/67] replacing repository with registery --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index f58b6d086..17b0d7e85 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -99,7 +99,7 @@ jobs: run: | # Get the digest of the specific tag $digest = az acr manifest list-metadata --name ${{ env.ACR_NAME }} ` - --repository ${{ env.IMAGE_NAME }} --output json ` + --registry ${{ env.IMAGE_NAME }} --output json ` --query "[?tags.contains('pr-2226')].digest" --output tsv Write-Host "Digest: $digest" From 69206678d730e4d25150805b94d535cb03c22af1 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 20:04:10 +1100 Subject: [PATCH 42/67] manifest for the specific tag --- .github/workflows/weekly-acr-images-cleanup.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 17b0d7e85..60f89063d 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -98,9 +98,8 @@ jobs: id: set-outputs run: | # Get the digest of the specific tag - $digest = az acr manifest list-metadata --name ${{ env.ACR_NAME }} ` - --registry ${{ env.IMAGE_NAME }} --output json ` - --query "[?tags.contains('pr-2226')].digest" --output tsv + $digest = az acr manifest list --name ${{ env.ACR_NAME }} ` + --repository ${{ env.IMAGE_NAME }} --tag "pr-2226" Write-Host "Digest: $digest" # invokeDeleteImage: From 9aa1f0362db3ed9ce60a1d7cbdc7a46fb6e3f9a3 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 20:21:32 +1100 Subject: [PATCH 43/67] getting digest value in a different way --- .github/workflows/weekly-acr-images-cleanup.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 60f89063d..87e31d161 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -98,8 +98,8 @@ jobs: id: set-outputs run: | # Get the digest of the specific tag - $digest = az acr manifest list --name ${{ env.ACR_NAME }} ` - --repository ${{ env.IMAGE_NAME }} --tag "pr-2226" + $digest = az acr repository show -n ${{ env.ACR_NAME }} ` + --image '${{ env.IMAGE_NAME }}:pr-2226' --query "digest" -o tsv Write-Host "Digest: $digest" # invokeDeleteImage: From e4a7d0110490cdba38230f46eacdb0bfd909c1cd Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 20:36:45 +1100 Subject: [PATCH 44/67] removing test docker image --- .github/workflows/weekly-acr-images-cleanup.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 87e31d161..c34d6cb15 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -102,6 +102,9 @@ jobs: --image '${{ env.IMAGE_NAME }}:pr-2226' --query "digest" -o tsv Write-Host "Digest: $digest" + - name: delete pr-630 + run: | + az acr repository delete -n ${{ env.ACR_NAME }} --image '${{ env.IMAGE_NAME }}:pr-630' --yes # invokeDeleteImage: # name: Invoking delete-acr-image # needs: From 133852e53bb117af3ff4eb43a83cee2b66ea66a7 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 20:51:17 +1100 Subject: [PATCH 45/67] Adding github sha to track it --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index c34d6cb15..583166e0e 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -100,7 +100,7 @@ jobs: # Get the digest of the specific tag $digest = az acr repository show -n ${{ env.ACR_NAME }} ` --image '${{ env.IMAGE_NAME }}:pr-2226' --query "digest" -o tsv - Write-Host "Digest: $digest" + Write-Host "Digest: $digest and github sha: ${{ github.sha }}" - name: delete pr-630 run: | From e4f4e95b85488cbca7bf574564ea3281d5e02255 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Fri, 1 Mar 2024 20:54:48 +1100 Subject: [PATCH 46/67] adding period with the output --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 583166e0e..c4e2f09c4 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -100,7 +100,7 @@ jobs: # Get the digest of the specific tag $digest = az acr repository show -n ${{ env.ACR_NAME }} ` --image '${{ env.IMAGE_NAME }}:pr-2226' --query "digest" -o tsv - Write-Host "Digest: $digest and github sha: ${{ github.sha }}" + Write-Host "Digest: $digest and github sha: ${{ github.sha }} ." - name: delete pr-630 run: | From 330999199182d4214279c982281e580181e4e555 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Mon, 4 Mar 2024 09:52:26 +1100 Subject: [PATCH 47/67] Removing sha tag from the docker img --- .github/workflows/delete-acr-image.yml | 11 ++---- .github/workflows/template-build.yml | 1 - .../workflows/weekly-acr-images-cleanup.yml | 35 +++++++------------ 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/.github/workflows/delete-acr-image.yml b/.github/workflows/delete-acr-image.yml index 170470187..21a303d09 100644 --- a/.github/workflows/delete-acr-image.yml +++ b/.github/workflows/delete-acr-image.yml @@ -59,13 +59,6 @@ jobs: $imageTagWithPrefix = '${{ matrix.IMAGE_TAG }}' } - # Get the digest of the specific tag - $digest = az acr repository show-manifests --name ${{ env.ACR_NAME }} ` - --repository ${{ env.IMAGE_NAME }} --output json ` - --query "[?tags.contains('$imageTagWithPrefix')].digest" --output tsv - - # Delete the digest (and all associated tags) az acr repository delete --name ${{ env.ACR_NAME }} ` - --image ${{ env.IMAGE_NAME }} --digest $digest --yes - - Write-Output "✅ ACR - image deleted with $digest digest" + --image ${{ env.IMAGE_NAME }}:$imageTagWithPrefix --yes + Write-Output "✅ ACR - ${{ env.IMAGE_NAME }}:$imageTagWithPrefix image deleted successfully." diff --git a/.github/workflows/template-build.yml b/.github/workflows/template-build.yml index e09d4fc0f..2a12d09b8 100644 --- a/.github/workflows/template-build.yml +++ b/.github/workflows/template-build.yml @@ -123,5 +123,4 @@ jobs: NEXT_PUBLIC_CHATBASE_BOT_ID=${{ env.NEXT_PUBLIC_CHATBASE_BOT_ID }} SITE_URL=https://www.ssw.com.au tags: | - ${{ env.ACR_LOGIN_SERVER }}/${{ env.IMAGE_NAME }}:${{ github.sha }} ${{ env.ACR_LOGIN_SERVER }}/${{ env.IMAGE_NAME }}:${{ inputs.tag }} diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index c4e2f09c4..05f628c41 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -94,26 +94,15 @@ jobs: echo "imageTagList=$imageTagList" >> $env:GITHUB_OUTPUT - - name: Set outputs - id: set-outputs - run: | - # Get the digest of the specific tag - $digest = az acr repository show -n ${{ env.ACR_NAME }} ` - --image '${{ env.IMAGE_NAME }}:pr-2226' --query "digest" -o tsv - Write-Host "Digest: $digest and github sha: ${{ github.sha }} ." - - - name: delete pr-630 - run: | - az acr repository delete -n ${{ env.ACR_NAME }} --image '${{ env.IMAGE_NAME }}:pr-630' --yes - # invokeDeleteImage: - # name: Invoking delete-acr-image - # needs: - # - check-acr-images #Adding second check to avoid running this flow - # if: needs.check-acr-images.outputs.imageTagList != '[""]' - # uses: ./.github/workflows/delete-acr-image.yml - # with: - # imageTags: ${{ needs.check-acr-images.outputs.imageTagList }} - # permissions: - # id-token: write - # contents: read - # secrets: inherit + invokeDeleteImage: + name: Invoking delete-acr-image + needs: + - check-acr-images #Adding second check to avoid running this flow + if: needs.check-acr-images.outputs.imageTagList != '[""]' + uses: ./.github/workflows/delete-acr-image.yml + with: + imageTags: ${{ needs.check-acr-images.outputs.imageTagList }} + permissions: + id-token: write + contents: read + secrets: inherit From b5bbf922bd049438f3f61085e229ad9b141ecde6 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Mon, 4 Mar 2024 10:40:53 +1100 Subject: [PATCH 48/67] Adding prs tags only to delete --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 05f628c41..72332fd9a 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -88,7 +88,7 @@ jobs: Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" } $nonPRTags = "${{ steps.imageTags.outputs.tagsWithoutPRPrefix }}" - $allTags = $nonPRTags + $allTags = imagesExistThatRequireDeletion $tags = $allTags -split ' ' $imageTagList = ConvertTo-Json -Compress @($tags) From 4239e3300ffb60b0819fb6df17d7de2eed77bd8a Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Mon, 4 Mar 2024 10:43:21 +1100 Subject: [PATCH 49/67] prefixing with dollar sign --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 72332fd9a..f44105c6d 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -88,7 +88,7 @@ jobs: Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" } $nonPRTags = "${{ steps.imageTags.outputs.tagsWithoutPRPrefix }}" - $allTags = imagesExistThatRequireDeletion + $allTags = $imagesExistThatRequireDeletion $tags = $allTags -split ' ' $imageTagList = ConvertTo-Json -Compress @($tags) From 0050e35f7c2d240c1546487f19123acfc727838f Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Mon, 4 Mar 2024 10:52:48 +1100 Subject: [PATCH 50/67] Adding non-prs tags --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index f44105c6d..898d5c306 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -88,7 +88,7 @@ jobs: Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" } $nonPRTags = "${{ steps.imageTags.outputs.tagsWithoutPRPrefix }}" - $allTags = $imagesExistThatRequireDeletion + $allTags = $nonPRTags # + $imagesExistThatRequireDeletion $tags = $allTags -split ' ' $imageTagList = ConvertTo-Json -Compress @($tags) From c4fc3666f6b71be4d3e3045c28ef239afdba7e4c Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Mon, 4 Mar 2024 14:27:58 +1100 Subject: [PATCH 51/67] Changing the limit of tag list --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 898d5c306..04b23ba09 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -56,7 +56,7 @@ jobs: run: | $images = az acr repository show-tags ` --name ${{ env.ACR_NAME }} --repository ${{ env.IMAGE_NAME }} ` - --top 250 --orderby time_asc --output tsv # Limiting to 250 tags because of the GitHub action matrix limit + --top 50 --orderby time_asc --output tsv # Limiting to 250 tags because of the GitHub action matrix limit # Filter tags that start with "pr-" $filteredTags = $images | Where-Object { $_ -like "pr-*" } From 635eaefe229565e02f4c4c40f86d2af8dc725e6b Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:11:48 +1100 Subject: [PATCH 52/67] Cleaning up the steps for the delete slots --- .github/workflows/delete-acr-image.yml | 4 ++-- .github/workflows/pr-close-delete-env.yml | 20 ++++++++++++++++--- .../workflows/weekly-acr-images-cleanup.yml | 5 ++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/delete-acr-image.yml b/.github/workflows/delete-acr-image.yml index 21a303d09..d059fe7a9 100644 --- a/.github/workflows/delete-acr-image.yml +++ b/.github/workflows/delete-acr-image.yml @@ -10,7 +10,7 @@ on: workflow_dispatch: inputs: imageTag: - description: "Images Tag or PR number" + description: "Image Tag or PR number" required: true defaults: @@ -52,7 +52,7 @@ jobs: - name: ACR - Delete image run: | - if('${{ matrix.IMAGE_TAG }}'.Length -le 4) # PR tags contain 4 digits + if('${{ matrix.IMAGE_TAG }}'.Length -le 4) # PR tags consist of 4 digits (i.e pr-xxxx) { $imageTagWithPrefix = '${{ env.PREFIX }}${{ matrix.IMAGE_TAG}}' }else{ diff --git a/.github/workflows/pr-close-delete-env.yml b/.github/workflows/pr-close-delete-env.yml index 8477efb37..ee18e55d1 100644 --- a/.github/workflows/pr-close-delete-env.yml +++ b/.github/workflows/pr-close-delete-env.yml @@ -41,7 +41,7 @@ jobs: $slotIDsInJSonArray = ConvertTo-Json -Compress @($slotIDs) echo "matrix=$slotIDsInJSonArray" >> $env:GITHUB_OUTPUT - delete-slot: + delete-slot-permission-cleanup: runs-on: ubuntu-latest needs: setting-up-slot-ids strategy: @@ -63,7 +63,7 @@ jobs: tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - name: Cleanup ACR Pull & Key Vault permission + - name: Cleanup ACR and Key Vault Permissions run: | $acrId = az acr show ` --resource-group ${{ env.AZURE_RESOURCE_GROUP }} ` @@ -109,10 +109,24 @@ jobs: Write-Host '❌ Key Vault not found' } - - name: Delete slot on staging site + - name: Delete slot run: | az webapp deployment slot delete ` --resource-group ${{ env.AZURE_RESOURCE_GROUP }} ` --name ${{ env.APP_SERVICE_NAME }} ` --slot ${{ env.SLOT_PREFIX }}${{ matrix.SLOT_NAME }} ` --output none + + invokeDeleteImage: + name: Invoking Pdelete-acr-image + needs: + - setting-up-slot-ids + - delete-slot-permission-cleanup + if: needs.setting-up-slot-ids.outputs.matrix != '[""]' + uses: ./.github/workflows/delete-acr-image.yml + with: + imageTags: ${{ needs.setting-up-slot-ids.outputs.matrix }} + permissions: + id-token: write + contents: read + secrets: inherit diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 04b23ba09..43e456a42 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -87,9 +87,8 @@ jobs: echo "❌ - Number of docker images are not equal to number of active PRs" Write-Host "⚡- These images need to be deleted : $imagesExistThatRequireDeletion" } - $nonPRTags = "${{ steps.imageTags.outputs.tagsWithoutPRPrefix }}" - $allTags = $nonPRTags # + $imagesExistThatRequireDeletion - $tags = $allTags -split ' ' + # Convert string into Array + $tags = $imagesExistThatRequireDeletion -split ' ' $imageTagList = ConvertTo-Json -Compress @($tags) echo "imageTagList=$imageTagList" >> $env:GITHUB_OUTPUT From 05f95d4e853366334c4424ceda8473ae9a6851e8 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:31:06 +1100 Subject: [PATCH 53/67] Removing redundant steps --- .github/workflows/delete-acr-image.yml | 19 ++++++++++++------ .github/workflows/pr-close-delete-env.yml | 24 +++++++++-------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/.github/workflows/delete-acr-image.yml b/.github/workflows/delete-acr-image.yml index d059fe7a9..edb2f696a 100644 --- a/.github/workflows/delete-acr-image.yml +++ b/.github/workflows/delete-acr-image.yml @@ -18,18 +18,29 @@ defaults: shell: pwsh env: - IMAGE_TAG: ${{ inputs.imageTags || inputs.imageTag }} + IMAGE_TAGS: ${{ inputs.imageTags || inputs.imageTag }} PREFIX: pr- permissions: id-token: write contents: read jobs: + setting-up-img-tags: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Get image tags from input + id: set-matrix + run: | + echo "matrix=${{ env.IMAGE_TAGS }}" >> $env:GITHUB_OUTPUT + delete-acr-image: runs-on: ubuntu-latest + needs: setting-up-img-tags strategy: matrix: - IMAGE_TAG: ${{ fromJson(inputs.imageTags) }} + IMAGE_TAG: ${{ fromJson(needs.setting-up-img-tags.outputs.matrix) }} steps: - uses: actions/checkout@v4 @@ -46,10 +57,6 @@ jobs: tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - name: ACR - Login - run: | - az acr login --name ${{ env.ACR_LOGIN_SERVER }} - - name: ACR - Delete image run: | if('${{ matrix.IMAGE_TAG }}'.Length -le 4) # PR tags consist of 4 digits (i.e pr-xxxx) diff --git a/.github/workflows/pr-close-delete-env.yml b/.github/workflows/pr-close-delete-env.yml index ee18e55d1..aaf0fa451 100644 --- a/.github/workflows/pr-close-delete-env.yml +++ b/.github/workflows/pr-close-delete-env.yml @@ -41,7 +41,7 @@ jobs: $slotIDsInJSonArray = ConvertTo-Json -Compress @($slotIDs) echo "matrix=$slotIDsInJSonArray" >> $env:GITHUB_OUTPUT - delete-slot-permission-cleanup: + delete-slot-and-acr-cleanup: runs-on: ubuntu-latest needs: setting-up-slot-ids strategy: @@ -109,6 +109,14 @@ jobs: Write-Host '❌ Key Vault not found' } + - name: ACR - Delete image + run: | + $imageTagWithPrefix = '${{ env.SLOT_PREFIX }}${{ matrix.SLOT_NAME}}' + + az acr repository delete --name ${{ env.ACR_NAME }} ` + --image ${{ env.IMAGE_NAME }}:$imageTagWithPrefix --yes + Write-Output "✅ ACR - ${{ env.IMAGE_NAME }}:$imageTagWithPrefix image deleted successfully." + - name: Delete slot run: | az webapp deployment slot delete ` @@ -116,17 +124,3 @@ jobs: --name ${{ env.APP_SERVICE_NAME }} ` --slot ${{ env.SLOT_PREFIX }}${{ matrix.SLOT_NAME }} ` --output none - - invokeDeleteImage: - name: Invoking Pdelete-acr-image - needs: - - setting-up-slot-ids - - delete-slot-permission-cleanup - if: needs.setting-up-slot-ids.outputs.matrix != '[""]' - uses: ./.github/workflows/delete-acr-image.yml - with: - imageTags: ${{ needs.setting-up-slot-ids.outputs.matrix }} - permissions: - id-token: write - contents: read - secrets: inherit From 92d5dbf0acfa79b3686e126d4ae68fe7a33ea33d Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:34:05 +1100 Subject: [PATCH 54/67] wrapping the tags within a quote --- .github/workflows/delete-acr-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/delete-acr-image.yml b/.github/workflows/delete-acr-image.yml index edb2f696a..baa44e0d3 100644 --- a/.github/workflows/delete-acr-image.yml +++ b/.github/workflows/delete-acr-image.yml @@ -33,7 +33,7 @@ jobs: - name: Get image tags from input id: set-matrix run: | - echo "matrix=${{ env.IMAGE_TAGS }}" >> $env:GITHUB_OUTPUT + echo "matrix='${{ env.IMAGE_TAGS }}'" >> $env:GITHUB_OUTPUT delete-acr-image: runs-on: ubuntu-latest From e3600506a9a4f3f008380933013b5060951b87dc Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:37:11 +1100 Subject: [PATCH 55/67] Removing acr login --- .github/workflows/delete-acr-image.yml | 3 ++- .github/workflows/weekly-acr-images-cleanup.yml | 4 ---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/delete-acr-image.yml b/.github/workflows/delete-acr-image.yml index baa44e0d3..efb791bb9 100644 --- a/.github/workflows/delete-acr-image.yml +++ b/.github/workflows/delete-acr-image.yml @@ -33,7 +33,8 @@ jobs: - name: Get image tags from input id: set-matrix run: | - echo "matrix='${{ env.IMAGE_TAGS }}'" >> $env:GITHUB_OUTPUT + $imageTags = '${{ env.IMAGE_TAGS }}' + echo "matrix=$imageTags" >> $env:GITHUB_OUTPUT delete-acr-image: runs-on: ubuntu-latest diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 43e456a42..ed9417802 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -47,10 +47,6 @@ jobs: $active_prs=$(gh pr list --state open --json number | jq -r '.[].number') echo "active_prs=$active_prs" >> $env:GITHUB_OUTPUT - - name: ACR - Login - run: | - az acr login --name ${{ env.ACR_LOGIN_SERVER }} - - name: Get list of ACR image tags id: imageTags run: | From 83d0263120c85303a908af2ad28b468814de9cef Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:42:44 +1100 Subject: [PATCH 56/67] Adding condition to stop the second flow --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index ed9417802..0f884776b 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -93,7 +93,7 @@ jobs: name: Invoking delete-acr-image needs: - check-acr-images #Adding second check to avoid running this flow - if: needs.check-acr-images.outputs.imageTagList != '[""]' + if: needs.check-acr-images.outputs.imageTagList != '[]' uses: ./.github/workflows/delete-acr-image.yml with: imageTags: ${{ needs.check-acr-images.outputs.imageTagList }} From add3daa5c75b1661ddb96f2ecf7f67a6daa969c5 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:48:08 +1100 Subject: [PATCH 57/67] Removing PR trigger --- .github/workflows/weekly-acr-images-cleanup.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 0f884776b..aa56775c6 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -5,9 +5,6 @@ on: # Monday at 2 PM UTC - https://cron.help/#0_14_*_*_MON - cron: "0 14 * * MON" workflow_dispatch: - pull_request: - branches: - - main env: GH_TOKEN: ${{ github.token }} From 3bb174c97faea7963648a7d7a0e0e70faee0bf5c Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:01:02 +1100 Subject: [PATCH 58/67] Passing JSON to call delete pr flow --- .github/workflows/pr-close-delete-env.yml | 8 +++----- .github/workflows/weekly-slots-cleanup.yml | 12 ++++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pr-close-delete-env.yml b/.github/workflows/pr-close-delete-env.yml index aaf0fa451..10ed5c24d 100644 --- a/.github/workflows/pr-close-delete-env.yml +++ b/.github/workflows/pr-close-delete-env.yml @@ -33,13 +33,11 @@ jobs: outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} steps: - - name: Converting slots into JSON Formatted Array + - name: Get slot ids from input id: set-matrix run: | - # TODO: Tech Debt - need to use it as JSON instead of space delimited - Github issue - https://github.com/SSWConsulting/SSW.Website/issues/1228 - $slotIDs = '${{ env.SLOT_NAME }}' -split ' ' - $slotIDsInJSonArray = ConvertTo-Json -Compress @($slotIDs) - echo "matrix=$slotIDsInJSonArray" >> $env:GITHUB_OUTPUT + $slotIDs = '${{ env.SLOT_NAME }}' + echo "matrix=$slotIDs" >> $env:GITHUB_OUTPUT delete-slot-and-acr-cleanup: runs-on: ubuntu-latest diff --git a/.github/workflows/weekly-slots-cleanup.yml b/.github/workflows/weekly-slots-cleanup.yml index 70023b9c0..1cb603354 100644 --- a/.github/workflows/weekly-slots-cleanup.yml +++ b/.github/workflows/weekly-slots-cleanup.yml @@ -21,7 +21,7 @@ jobs: check-pr-slots: runs-on: ubuntu-latest outputs: - slotsExistThatRequireDeletion: ${{ steps.comparision.outputs.slotsExistThatRequireDeletion }} + slotList: ${{ steps.comparision.outputs.slotList }} steps: - name: Checking out @@ -74,16 +74,20 @@ jobs: echo "❌ - Number of slots are not equal to number of active PRs" Write-Host "⚡- These slots need to be deleted : $slotsExistThatRequireDeletion" } - echo "slotsExistThatRequireDeletion=$slotsExistThatRequireDeletion" >> $env:GITHUB_OUTPUT + # Convert string into Array + $slots = $slotsExistThatRequireDeletion -split ' ' + $slotList = ConvertTo-Json -Compress @($slots) + + echo "slotList=$slotList" >> $env:GITHUB_OUTPUT invokeDeleteSlot: name: Invoking PR Close/Delete needs: - check-pr-slots #Adding second check to avoid running this flow - if: needs.check-pr-slots.outputs.slotsExistThatRequireDeletion != '' + if: needs.check-pr-slots.outputs.slotList != '[]' uses: ./.github/workflows/pr-close-delete-env.yml with: - slotIDs: ${{ needs.check-pr-slots.outputs.slotsExistThatRequireDeletion }} + slotIDs: ${{ needs.check-pr-slots.outputs.slotList }} permissions: id-token: write contents: read From 51b33c53f2ff3561cfe39cdf2490e6f12733f24f Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Tue, 5 Mar 2024 10:13:58 +1100 Subject: [PATCH 59/67] Adding step to remove untagged digests --- .github/workflows/weekly-acr-images-cleanup.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index aa56775c6..16c83a937 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -38,6 +38,14 @@ jobs: tenant-id: ${{ secrets.AZURE_TENANT_ID }} subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + - name: Delete all untagged images + run: | + $untaggedDigests = az acr repository show-manifests -n ${{ env.ACR_NAME }} --repository ` + ${{ env.IMAGE_NAME }} --query "[?tags==null].digest" -o tsv + #%{ az acr repository delete -n ${{ env.ACR_NAME }} -t ${{ env.IMAGE_NAME }}@$_ } + Write-Host "$untaggedDigests" + Write-Host "$untaggedDigests.Length" + - name: Get list of active PRs id: prList run: | From 24f6d089db79afc801f42895fbec452fc9df71aa Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Tue, 5 Mar 2024 10:15:06 +1100 Subject: [PATCH 60/67] Adding PR trigger --- .github/workflows/weekly-acr-images-cleanup.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 16c83a937..fe5f225a9 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -5,6 +5,9 @@ on: # Monday at 2 PM UTC - https://cron.help/#0_14_*_*_MON - cron: "0 14 * * MON" workflow_dispatch: + pull_request: + branches: + - main env: GH_TOKEN: ${{ github.token }} From 559c60906256125b519675003f5af84013df2024 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Tue, 5 Mar 2024 10:21:06 +1100 Subject: [PATCH 61/67] Updating the query to retrieve the manifest --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index fe5f225a9..f52eec92f 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -43,7 +43,7 @@ jobs: - name: Delete all untagged images run: | - $untaggedDigests = az acr repository show-manifests -n ${{ env.ACR_NAME }} --repository ` + $untaggedDigests = az manifest list-metadata -n ${{ env.ACR_NAME }} --repository ` ${{ env.IMAGE_NAME }} --query "[?tags==null].digest" -o tsv #%{ az acr repository delete -n ${{ env.ACR_NAME }} -t ${{ env.IMAGE_NAME }}@$_ } Write-Host "$untaggedDigests" From b702566da15067d75512f8695dd4cc7e229cde8e Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Tue, 5 Mar 2024 10:22:48 +1100 Subject: [PATCH 62/67] Adding acr tag --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index f52eec92f..3eace5626 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -43,7 +43,7 @@ jobs: - name: Delete all untagged images run: | - $untaggedDigests = az manifest list-metadata -n ${{ env.ACR_NAME }} --repository ` + $untaggedDigests = az acr manifest list-metadata -n ${{ env.ACR_NAME }} --repository ` ${{ env.IMAGE_NAME }} --query "[?tags==null].digest" -o tsv #%{ az acr repository delete -n ${{ env.ACR_NAME }} -t ${{ env.IMAGE_NAME }}@$_ } Write-Host "$untaggedDigests" From 262141e14f99b84354e3c0f2ada511cb1fbece69 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Tue, 5 Mar 2024 10:51:36 +1100 Subject: [PATCH 63/67] Updating the props for the list --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 3eace5626..7e0f48536 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -43,7 +43,7 @@ jobs: - name: Delete all untagged images run: | - $untaggedDigests = az acr manifest list-metadata -n ${{ env.ACR_NAME }} --repository ` + $untaggedDigests = az acr manifest list-metadata -r ${{ env.ACR_NAME }} -n ` ${{ env.IMAGE_NAME }} --query "[?tags==null].digest" -o tsv #%{ az acr repository delete -n ${{ env.ACR_NAME }} -t ${{ env.IMAGE_NAME }}@$_ } Write-Host "$untaggedDigests" From 81cf5e721fdd3b7f0758136637a36a38e6c391a8 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Tue, 5 Mar 2024 11:00:57 +1100 Subject: [PATCH 64/67] adding delete command to delete untagged shas --- .github/workflows/weekly-acr-images-cleanup.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 7e0f48536..3271f6088 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -44,10 +44,9 @@ jobs: - name: Delete all untagged images run: | $untaggedDigests = az acr manifest list-metadata -r ${{ env.ACR_NAME }} -n ` - ${{ env.IMAGE_NAME }} --query "[?tags==null].digest" -o tsv - #%{ az acr repository delete -n ${{ env.ACR_NAME }} -t ${{ env.IMAGE_NAME }}@$_ } - Write-Host "$untaggedDigests" - Write-Host "$untaggedDigests.Length" + ${{ env.IMAGE_NAME }} --query "[?tags==null].digest" -o tsv | ` + %{ az acr repository delete -n ${{ env.ACR_NAME }} -t ${{ env.IMAGE_NAME }}@$_ } + Write-Host "✅ All untagged images have been deleted" - name: Get list of active PRs id: prList From 4fc906493afc9fcfc2f110ecffee9379f107afab Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Tue, 5 Mar 2024 11:03:11 +1100 Subject: [PATCH 65/67] Adding yes prop to confirm delete --- .github/workflows/weekly-acr-images-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 3271f6088..4c68748e6 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -45,7 +45,7 @@ jobs: run: | $untaggedDigests = az acr manifest list-metadata -r ${{ env.ACR_NAME }} -n ` ${{ env.IMAGE_NAME }} --query "[?tags==null].digest" -o tsv | ` - %{ az acr repository delete -n ${{ env.ACR_NAME }} -t ${{ env.IMAGE_NAME }}@$_ } + %{ az acr repository delete -n ${{ env.ACR_NAME }} -t ${{ env.IMAGE_NAME }}@$_ --yes} Write-Host "✅ All untagged images have been deleted" - name: Get list of active PRs From 55a273f059fe2c31d7be55abc9d5bea233cdd23a Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Tue, 5 Mar 2024 12:27:55 +1100 Subject: [PATCH 66/67] removing PR trigger --- .github/workflows/weekly-acr-images-cleanup.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 4c68748e6..94c7016c3 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -5,9 +5,6 @@ on: # Monday at 2 PM UTC - https://cron.help/#0_14_*_*_MON - cron: "0 14 * * MON" workflow_dispatch: - pull_request: - branches: - - main env: GH_TOKEN: ${{ github.token }} From 518ec5e5355e1aadbd868fdb14f919a1a2134189 Mon Sep 17 00:00:00 2001 From: "Aman Kumar [SSW]" <71385247+amankumarrr@users.noreply.github.com> Date: Tue, 5 Mar 2024 14:54:10 +1100 Subject: [PATCH 67/67] Removing testing scripts --- ...delete-acr-image.yml => template-delete-acr-image.yml} | 0 .github/workflows/weekly-acr-images-cleanup.yml | 8 ++------ 2 files changed, 2 insertions(+), 6 deletions(-) rename .github/workflows/{delete-acr-image.yml => template-delete-acr-image.yml} (100%) diff --git a/.github/workflows/delete-acr-image.yml b/.github/workflows/template-delete-acr-image.yml similarity index 100% rename from .github/workflows/delete-acr-image.yml rename to .github/workflows/template-delete-acr-image.yml diff --git a/.github/workflows/weekly-acr-images-cleanup.yml b/.github/workflows/weekly-acr-images-cleanup.yml index 94c7016c3..f28b49ff1 100644 --- a/.github/workflows/weekly-acr-images-cleanup.yml +++ b/.github/workflows/weekly-acr-images-cleanup.yml @@ -56,19 +56,15 @@ jobs: run: | $images = az acr repository show-tags ` --name ${{ env.ACR_NAME }} --repository ${{ env.IMAGE_NAME }} ` - --top 50 --orderby time_asc --output tsv # Limiting to 250 tags because of the GitHub action matrix limit + --top 250 --orderby time_asc --output tsv # Limiting to 250 tags because of the GitHub action matrix limit # Filter tags that start with "pr-" $filteredTags = $images | Where-Object { $_ -like "pr-*" } - # Filter tags that do not start with start with "pr-" - $tagsWithoutPRPrefix = $images | Where-Object { $_ -notlike "pr-*" -and $_ -notmatch "staging|production|a21f1263dfaa4e4977595912a8cc80c95f737f98|89a9bccde9c2a407b85105e3261d17ed27006160" } - # Remove the "pr-" prefix from filtered tags $filteredTagsWithoutPrefix = $filteredTags -replace "^pr-", "" echo "filteredTags=$filteredTagsWithoutPrefix" >> $env:GITHUB_OUTPUT - echo "tagsWithoutPRPrefix=$tagsWithoutPRPrefix" >> $env:GITHUB_OUTPUT - name: Compare active PRs with existing ACR images id: comparison @@ -98,7 +94,7 @@ jobs: needs: - check-acr-images #Adding second check to avoid running this flow if: needs.check-acr-images.outputs.imageTagList != '[]' - uses: ./.github/workflows/delete-acr-image.yml + uses: ./.github/workflows/template-delete-acr-image.yml with: imageTags: ${{ needs.check-acr-images.outputs.imageTagList }} permissions: