1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-06 13:38:13 -05:00

Fix Container Registry Purge workflow (#1835)

This commit is contained in:
Vince Grassia 2022-02-01 14:41:34 -05:00 committed by GitHub
parent 1e68958b20
commit 5b401b3895
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,8 +2,8 @@
name: Container Registry Purge name: Container Registry Purge
on: on:
#schedule: schedule:
# - cron: '0 0 * * SUN' - cron: '0 0 * * SUN'
workflow_dispatch: workflow_dispatch:
inputs: {} inputs: {}
@ -12,27 +12,46 @@ jobs:
name: Purge old images name: Purge old images
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
strategy: strategy:
fail-fast: false
matrix: matrix:
include: include:
- name: bitwardenqa - name: bitwardenqa
- name: bitwardenprod - name: bitwardenprod
steps: steps:
- name: Login to Azure - name: Login to Azure
if: matrix.name == 'bitwardenprod'
uses: Azure/login@1f63701bf3e6892515f1b7ce2d2bf1708b46beaf uses: Azure/login@1f63701bf3e6892515f1b7ce2d2bf1708b46beaf
with: with:
creds: ${{ secrets.AZURE_PROD_KV_CREDENTIALS }} creds: ${{ secrets.AZURE_PROD_KV_CREDENTIALS }}
- name: Login to Azure
if: matrix.name == 'bitwardenqa'
uses: Azure/login@1f63701bf3e6892515f1b7ce2d2bf1708b46beaf
with:
creds: ${{ secrets.AZURE_QA_KV_CREDENTIALS }}
- name: Purge images - name: Purge images
env: env:
REGISTRY: ${{ matrix.name }} REGISTRY: ${{ matrix.name }}
AGO_DUR_VER: "180d"
AGO_DUR: "30d" AGO_DUR: "30d"
run: | run: |
REPO_LIST=$(az acr repository list -n $REGISTRY -o tsv) REPO_LIST=$(az acr repository list -n $REGISTRY -o tsv)
for REPO in $REPO_LIST for REPO in $REPO_LIST
do do
PURGE_CMD="acr purge --filter '$REPO:.*' --ago $AGO_DUR --untagged --dry-run" TAG_LIST=$(az acr repository show-tags -n $REGISTRY --repository $REPO -o tsv)
for TAG in $TAG_LIST
do
if [ $TAG = "latest" ]; then
PURGE_CMD="acr purge --filter '$REPO:$TAG' --ago $AGO_DUR_VER --untagged --keep 1"
elif [[ $TAG =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
PURGE_CMD="acr purge --filter '$REPO:$TAG' --ago $AGO_DUR_VER --untagged"
else
PURGE_CMD="acr purge --filter '$REPO:$TAG' --ago $AGO_DUR --untagged"
fi
az acr run --cmd "$PURGE_CMD" --registry $REGISTRY /dev/null az acr run --cmd "$PURGE_CMD" --registry $REGISTRY /dev/null
done done
done
check-failures: check-failures: