mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 03:49:11 +00:00
add GAR cleanup job
This commit is contained in:
parent
465ca36f28
commit
e89ce7f10c
1 changed files with 46 additions and 0 deletions
46
.github/workflows/gar-cleanup.yml
vendored
Normal file
46
.github/workflows/gar-cleanup.yml
vendored
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
name: GAR Cleanup
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '30 6 * * *'
|
||||||
|
workflow_dispatch: {}
|
||||||
|
workflow_run:
|
||||||
|
workflows: ['Deploy']
|
||||||
|
types:
|
||||||
|
- completed
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker_cleanup:
|
||||||
|
name: Cleanup Deployed Images
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs:
|
||||||
|
- docker_sync
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
region: [us, europe, asia]
|
||||||
|
steps:
|
||||||
|
- name: Set up Cloud SDK
|
||||||
|
uses: google-github-actions/setup-gcloud@master
|
||||||
|
with:
|
||||||
|
project_id: ${{ secrets.GCS_PROJECT_ID }}
|
||||||
|
service_account_key: ${{ secrets.GCS_TF_KEY }}
|
||||||
|
export_default_credentials: true
|
||||||
|
|
||||||
|
- name: Delete stale artifacts
|
||||||
|
run: |
|
||||||
|
flags="--format=json --location=${{matrix.region}} --repository=roleypoly"
|
||||||
|
|
||||||
|
packagesToPrune=$(gcloud artifacts packages list $flags 2>/dev/null | jq -r '.[].name')
|
||||||
|
|
||||||
|
for package in $packagesToPrune; do
|
||||||
|
tagsToKeep=$(gcloud artifacts tags list --package=$package $flags 2>/dev/null | jq -r '.[].version')
|
||||||
|
versionsToCheck=$(gcloud artifacts versions list --package=$package $flags 2>/dev/null | jq -r '.[].name')
|
||||||
|
|
||||||
|
for version in $versionsToCheck; do
|
||||||
|
if [[ "$tagsToKeep" =~ .*"$version".* ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
gcloud artifacts versions delete $version --package=$package $flags 2>/dev/null
|
||||||
|
done
|
||||||
|
done
|
Loading…
Add table
Reference in a new issue