From 5971a424989b745d3e3f17f0030d0a1ca10e4390 Mon Sep 17 00:00:00 2001
From: Martin Weise <martin.weise@tuwien.ac.at>
Date: Thu, 6 Mar 2025 19:51:51 +0100
Subject: [PATCH] WIP

Signed-off-by: Martin Weise <martin.weise@tuwien.ac.at>
---
 .gitlab-ci.yml                       | 22 +++++++++++++++++++++-
 .gitlab/remove-unsupported-images.sh | 24 ++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100755 .gitlab/remove-unsupported-images.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5dd7139b45..cdbf8af44f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -13,6 +13,7 @@ variables:
   DOC_VERSION: "1.7"
   APP_VERSION: "1.7.1"
   CHART_VERSION: "1.7.1"
+  SUPPORTED_VERSIONS: "[\"1.7.0\",\"1.7.1\"]"
   CACHE_FALLBACK_KEY: "${CI_DEFAULT_BRANCH}"
   # This will supress any download for dependencies and plugins or upload messages which would clutter the console log.
   # `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
@@ -43,6 +44,7 @@ stages:
   - build
   - test
   - docs
+  - clean
   - release
   - verify
   - scan
@@ -445,10 +447,28 @@ test-ui:
     - "sleep 30"
     - "ENDPOINT=http://localhost:3000 bash ./dbrepo-ui/tests/test_heap.sh"
 
+clean-images:
+  stage: clean
+  image: docker:${DOCKER_VERSION}-dind
+  only:
+    refs:
+      - dev
+      - /^release-.*/
+  before_script:
+    - "docker logout ${CI_REGISTRY_URL}"
+    - "echo ${CI_REGISTRY_PASSWORD} | docker login --username ${CI_REGISTRY_USER} --password-stdin ${CI_REGISTRY_URL}"
+    - "docker logout ${CI_REGISTRY2_URL}"
+    - "echo ${CI_REGISTRY2_PASSWORD} | docker login --username ${CI_REGISTRY2_USER} --password-stdin ${CI_REGISTRY2_URL}"
+    - "ifconfig eth0 mtu 1450 up"
+    - "apk add --no-cache curl bash jq regclient"
+  script:
+    - bash ./.gitlab/remove-unsupported-images.sh
+
 release-images:
   stage: release
   image: docker:${DOCKER_VERSION}-dind
   dependencies:
+    - clean-images
     - test-analyse-service
     - test-auth-service-init
     - test-data-service
@@ -616,4 +636,4 @@ scan-sonarqube:
     policy: pull
     key: "${CI_COMMIT_SHORT_SHA}"
     paths:
-      - sonar-scanner/
\ No newline at end of file
+      - sonar-scanner/
diff --git a/.gitlab/remove-unsupported-images.sh b/.gitlab/remove-unsupported-images.sh
new file mode 100755
index 0000000000..7c69d95191
--- /dev/null
+++ b/.gitlab/remove-unsupported-images.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+declare -A services
+services[0]=analyse-service
+services[1]=auth-service-init
+services[2]=dashboard-service
+services[3]=data-service
+services[4]=search-db
+services[5]=search-service
+services[6]=search-service-init
+services[7]=ui
+
+echo "Starting registry housekeeping ..."
+
+for key in "${!services[@]}"; do
+  echo "Checking ${CI_REGISTRY2_URL}/${services[$key]} tags ..."
+  TAGS=$(regctl tag ls ${CI_REGISTRY2_URL}/${services[$key]})
+  for tag in $TAGS; do
+      res=$(echo "${SUPPORTED_VERSIONS}" | grep "$tag")
+      if [[ -z $res ]]; then
+        regctl tag rm ${CI_REGISTRY2_URL}/${services[$key]}:$tag
+        echo "Deleted unsupported tag ${CI_REGISTRY2_URL}/${services[$key]}:$tag"
+      fi
+  done
+done
-- 
GitLab