2022-01-21 14:42:23 +01:00
|
|
|
---
|
2024-01-23 19:24:52 +01:00
|
|
|
name: Container registry cleanup
|
2022-01-21 14:42:23 +01:00
|
|
|
|
|
|
|
on:
|
|
|
|
pull_request:
|
|
|
|
types: [closed]
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
build-docker:
|
2024-01-23 19:24:52 +01:00
|
|
|
name: Remove branch-specific Docker images
|
|
|
|
runs-on: ubuntu-22.04
|
2022-01-21 14:42:23 +01:00
|
|
|
steps:
|
2022-01-24 20:12:37 +01:00
|
|
|
########## ACR ##########
|
2024-01-23 19:24:52 +01:00
|
|
|
- name: Log in to Azure - QA Subscription
|
2023-07-03 18:36:42 +02:00
|
|
|
uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7
|
2023-02-16 23:16:32 +01:00
|
|
|
with:
|
|
|
|
creds: ${{ secrets.AZURE_QA_KV_CREDENTIALS }}
|
|
|
|
|
2024-01-23 19:24:52 +01:00
|
|
|
- name: Log in to Azure ACR
|
2023-02-16 23:16:32 +01:00
|
|
|
run: az acr login -n bitwardenqa
|
2023-02-22 20:48:45 +01:00
|
|
|
|
2024-01-23 19:24:52 +01:00
|
|
|
- name: Log in to Azure - production subscription
|
2023-07-03 18:36:42 +02:00
|
|
|
uses: Azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 # v1.4.7
|
2022-01-24 20:12:37 +01:00
|
|
|
with:
|
2023-02-15 11:45:46 +01:00
|
|
|
creds: ${{ secrets.AZURE_PROD_KV_CREDENTIALS }}
|
2022-01-24 20:12:37 +01:00
|
|
|
|
2024-01-23 19:24:52 +01:00
|
|
|
- name: Log in to Azure ACR
|
2023-02-15 11:45:46 +01:00
|
|
|
run: az acr login -n bitwardenprod
|
2022-01-24 20:12:37 +01:00
|
|
|
|
|
|
|
########## Remove Docker images ##########
|
2024-01-23 19:24:52 +01:00
|
|
|
- name: Remove the Docker image from ACR
|
2022-01-24 20:12:37 +01:00
|
|
|
env:
|
2024-02-09 11:32:21 +01:00
|
|
|
REF: ${{ github.event.pull_request.head.ref }}
|
2023-02-16 23:16:32 +01:00
|
|
|
REGISTRIES: |
|
|
|
|
registries:
|
|
|
|
- bitwardenprod
|
|
|
|
- bitwardenqa
|
2022-01-24 20:12:37 +01:00
|
|
|
SERVICES: |
|
|
|
|
services:
|
|
|
|
- Admin
|
|
|
|
- Api
|
|
|
|
- Attachments
|
|
|
|
- Events
|
|
|
|
- EventsProcessor
|
|
|
|
- Icons
|
|
|
|
- Identity
|
|
|
|
- K8S-Proxy
|
|
|
|
- MsSql
|
|
|
|
- Nginx
|
|
|
|
- Notifications
|
|
|
|
- Server
|
|
|
|
- Setup
|
|
|
|
- Sso
|
|
|
|
run: |
|
|
|
|
for SERVICE in $(echo "${{ env.SERVICES }}" | yq e ".services[]" - )
|
|
|
|
do
|
2023-02-16 23:16:32 +01:00
|
|
|
for REGISTRY in $( echo "${{ env.REGISTRIES }}" | yq e ".registries[]" - )
|
|
|
|
do
|
|
|
|
SERVICE_NAME=$(echo $SERVICE | awk '{print tolower($0)}')
|
2024-02-09 11:32:21 +01:00
|
|
|
IMAGE_TAG=$(echo "${REF}" | sed "s#/#-#g") # slash safe branch name
|
2022-01-24 20:12:37 +01:00
|
|
|
|
2023-02-16 23:16:32 +01:00
|
|
|
echo "[*] Checking if remote exists: $REGISTRY.azurecr.io/$SERVICE_NAME:$IMAGE_TAG"
|
|
|
|
TAG_EXISTS=$(
|
|
|
|
az acr repository show-tags --name $REGISTRY --repository $SERVICE_NAME \
|
|
|
|
| jq --arg $TAG "$IMAGE_TAG" -e '. | any(. == "$TAG")'
|
|
|
|
)
|
2022-01-24 20:12:37 +01:00
|
|
|
|
2023-02-16 23:16:32 +01:00
|
|
|
if [[ "$TAG_EXISTS" == "true" ]]; then
|
|
|
|
echo "[*] Tag exists. Removing tag"
|
|
|
|
az acr repository delete --name $REGISTRY --image $SERVICE_NAME:$IMAGE_TAG --yes
|
|
|
|
else
|
|
|
|
echo "[*] Tag does not exist. No action needed"
|
|
|
|
fi
|
|
|
|
done
|
2022-01-24 20:12:37 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
- name: Log out of Docker
|
|
|
|
run: docker logout
|