From be20b6702a036627e9ff1caa95644f31c85b728d Mon Sep 17 00:00:00 2001
From: Dominik Hebeler <dominik@suma-ev.de>
Date: Wed, 11 May 2022 12:07:32 +0200
Subject: [PATCH] pruning fpm and nginx tags

---
 .gitlab/ci/cleanup_tags.yml | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/.gitlab/ci/cleanup_tags.yml b/.gitlab/ci/cleanup_tags.yml
index c02e632cf..b18baaf3f 100644
--- a/.gitlab/ci/cleanup_tags.yml
+++ b/.gitlab/ci/cleanup_tags.yml
@@ -6,14 +6,25 @@
     NGINX_IMAGE_REPOSITORY_ID: 416
   script: |
     # Delete all composer image tags for this branch as we don't need them anymore
-    echo "PRIVATE-TOKEN: $CI_JOB_TOKEN"
     curl -X DELETE -k -H 'Content-Type: application/json' --fail \
         -H "JOB-TOKEN: ${CI_JOB_TOKEN}" \
         -i "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/registry/repositories/${FPM_IMAGE_REPOSITORY_ID}/tags" \
         --data "{\"name_regex_delete\": \"$CI_COMMIT_REF_SLUG-composer-.*\"}"
+    # Delete all fpm tags but keeping the latest n ones (1 for review apps and 10 for development/master)
+    curl -X DELETE -k -H 'Content-Type: application/json' --fail \
+        -H "JOB-TOKEN: ${CI_JOB_TOKEN}" \
+        -i "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/registry/repositories/${FPM_IMAGE_REPOSITORY_ID}/tags" \
+        --data "{\"name_regex_delete\": \"$CI_COMMIT_REF_SLUG-.*\", \"keep_n\": $KEEP_TAGS}"
+    # Delete all nginx tags but keeping the latest n ones (1 for review apps and 10 for development/master)
+    curl -X DELETE -k -H 'Content-Type: application/json' --fail \
+        -H "JOB-TOKEN: ${CI_JOB_TOKEN}" \
+        -i "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/registry/repositories/${NGINX_IMAGE_REPOSITORY_ID}/tags" \
+        --data "{\"name_regex_delete\": \"$CI_COMMIT_REF_SLUG-.*\", \"keep_n\": $KEEP_TAGS}"
 
 cleanup_tags_review:
   extends: .cleanup_tags
+  variables:
+    KEEP_TAGS: 1
   rules:
     - if: '$CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "development"'
       when: never
-- 
GitLab