2022-01-27 22:28:12 +01:00
|
|
|
---
|
2024-01-23 19:24:52 +01:00
|
|
|
name: Container registry purge
|
2022-01-27 22:28:12 +01:00
|
|
|
|
|
|
|
on:
|
2022-02-01 20:41:34 +01:00
|
|
|
schedule:
|
2024-01-23 19:24:52 +01:00
|
|
|
- cron: "0 0 * * SUN"
|
2022-01-27 22:28:12 +01:00
|
|
|
workflow_dispatch:
|
|
|
|
inputs: {}
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
purge:
|
|
|
|
name: Purge old images
|
2024-01-23 19:24:52 +01:00
|
|
|
runs-on: ubuntu-22.04
|
2022-01-27 22:28:12 +01:00
|
|
|
steps:
|
2024-01-23 19:24:52 +01:00
|
|
|
- name: Log in to Azure
|
2024-07-10 21:47:20 +02:00
|
|
|
uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0
|
2022-01-27 22:28:12 +01:00
|
|
|
with:
|
|
|
|
creds: ${{ secrets.AZURE_PROD_KV_CREDENTIALS }}
|
|
|
|
|
|
|
|
- name: Purge images
|
|
|
|
env:
|
2023-02-15 11:45:46 +01:00
|
|
|
REGISTRY: bitwardenprod
|
2022-02-01 20:41:34 +01:00
|
|
|
AGO_DUR_VER: "180d"
|
2022-01-27 22:28:12 +01:00
|
|
|
AGO_DUR: "30d"
|
|
|
|
run: |
|
|
|
|
REPO_LIST=$(az acr repository list -n $REGISTRY -o tsv)
|
|
|
|
for REPO in $REPO_LIST
|
|
|
|
do
|
2022-12-21 17:47:23 +01:00
|
|
|
|
|
|
|
PURGE_LATEST=""
|
|
|
|
PURGE_VERSION=""
|
|
|
|
PURGE_ELSE=""
|
|
|
|
|
2022-02-01 20:41:34 +01:00
|
|
|
TAG_LIST=$(az acr repository show-tags -n $REGISTRY --repository $REPO -o tsv)
|
|
|
|
for TAG in $TAG_LIST
|
|
|
|
do
|
2022-03-30 21:08:28 +02:00
|
|
|
if [ $TAG = "latest" ] || [ $TAG = "dev" ]; then
|
2022-12-21 17:47:23 +01:00
|
|
|
PURGE_LATEST+="--filter '$REPO:$TAG' "
|
2022-02-01 20:41:34 +01:00
|
|
|
elif [[ $TAG =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
|
2022-12-21 17:47:23 +01:00
|
|
|
PURGE_VERSION+="--filter '$REPO:$TAG' "
|
2022-02-01 20:41:34 +01:00
|
|
|
else
|
2022-12-21 17:47:23 +01:00
|
|
|
PURGE_ELSE+="--filter '$REPO:$TAG' "
|
2022-02-01 20:41:34 +01:00
|
|
|
fi
|
|
|
|
done
|
2022-12-21 17:47:23 +01:00
|
|
|
|
|
|
|
if [ ! -z "$PURGE_LATEST" ]
|
|
|
|
then
|
|
|
|
PURGE_LATEST_CMD="acr purge $PURGE_LATEST --ago $AGO_DUR_VER --untagged --keep 1"
|
|
|
|
az acr run --cmd "$PURGE_LATEST_CMD" --registry $REGISTRY /dev/null &
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z "$PURGE_VERSION" ]
|
|
|
|
then
|
|
|
|
PURGE_VERSION_CMD="acr purge $PURGE_VERSION --ago $AGO_DUR_VER --untagged"
|
|
|
|
az acr run --cmd "$PURGE_VERSION_CMD" --registry $REGISTRY /dev/null &
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z "$PURGE_ELSE" ]
|
|
|
|
then
|
|
|
|
PURGE_ELSE_CMD="acr purge $PURGE_ELSE --ago $AGO_DUR --untagged"
|
|
|
|
az acr run --cmd "$PURGE_ELSE_CMD" --registry $REGISTRY /dev/null &
|
|
|
|
fi
|
|
|
|
|
|
|
|
wait
|
|
|
|
|
2022-01-27 22:28:12 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
check-failures:
|
|
|
|
name: Check for failures
|
|
|
|
if: always()
|
2024-01-23 19:24:52 +01:00
|
|
|
runs-on: ubuntu-22.04
|
2024-03-05 21:14:50 +01:00
|
|
|
needs: [purge]
|
2022-01-27 22:28:12 +01:00
|
|
|
steps:
|
|
|
|
- name: Check if any job failed
|
|
|
|
if: |
|
2024-03-05 21:14:50 +01:00
|
|
|
(github.ref == 'refs/heads/main'
|
2022-01-27 22:28:12 +01:00
|
|
|
|| github.ref == 'refs/heads/rc'
|
2024-03-05 21:14:50 +01:00
|
|
|
|| github.ref == 'refs/heads/hotfix-rc')
|
|
|
|
&& contains(needs.*.result, 'failure')
|
|
|
|
run: exit 1
|
2022-01-27 22:28:12 +01:00
|
|
|
|
2024-01-23 19:24:52 +01:00
|
|
|
- name: Log in to Azure - CI subscription
|
2024-07-10 21:47:20 +02:00
|
|
|
uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0
|
2022-01-27 22:28:12 +01:00
|
|
|
if: failure()
|
|
|
|
with:
|
2023-04-17 19:03:32 +02:00
|
|
|
creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }}
|
2022-01-27 22:28:12 +01:00
|
|
|
|
|
|
|
- name: Retrieve secrets
|
|
|
|
id: retrieve-secrets
|
2023-11-08 19:08:15 +01:00
|
|
|
uses: bitwarden/gh-actions/get-keyvault-secrets@main
|
2022-01-27 22:28:12 +01:00
|
|
|
if: failure()
|
2022-10-04 20:23:08 +02:00
|
|
|
with:
|
2023-04-17 15:06:57 +02:00
|
|
|
keyvault: "bitwarden-ci"
|
2022-10-04 20:23:08 +02:00
|
|
|
secrets: "devops-alerts-slack-webhook-url"
|
2022-01-27 22:28:12 +01:00
|
|
|
|
|
|
|
- name: Notify Slack on failure
|
2024-07-10 21:47:20 +02:00
|
|
|
uses: act10ns/slack@44541246747a30eb3102d87f7a4cc5471b0ffb7d # v2.1.0
|
2022-01-27 22:28:12 +01:00
|
|
|
if: failure()
|
|
|
|
env:
|
|
|
|
SLACK_WEBHOOK_URL: ${{ steps.retrieve-secrets.outputs.devops-alerts-slack-webhook-url }}
|
|
|
|
with:
|
|
|
|
status: ${{ job.status }}
|