diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e26a00..70e4ceb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -98,3 +98,17 @@ jobs: --max-instances ${{ env.MAX_INSTANCES }} \ --platform managed \ --allow-unauthenticated + + - name: Cleanup old images + run: | + # Get all images except the most recent 2 + IMAGES_TO_DELETE=$(gcloud artifacts docker images list ${{ env.CONTAINER_IMAGE }} \ + --format="get(DIGEST)" \ + --sort-by="~CREATE_TIME" | tail -n +3) + + # Delete the older images + for DIGEST in $IMAGES_TO_DELETE; do + gcloud artifacts docker images delete ${{ env.CONTAINER_IMAGE }}@$DIGEST \ + --delete-tags \ + --quiet + done