File 0002-we-can-no-longer-just-copy-the-docker-script.-provid.patch of Package gitlab-runner

From 86708809459cd9723d75fd6fe55a8824f2346a9e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marcus=20R=C3=BCckert?= <darix@nordisch.org>
Date: Fri, 19 Dec 2025 08:18:40 +0100
Subject: [PATCH 2/2] we can no longer just copy the docker script. provide
 proper copy

---
 .../share/gitlab-runner/clear-podman-cache    | 93 +++++++++++++++++++
 1 file changed, 93 insertions(+)
 create mode 100755 packaging/root/usr/share/gitlab-runner/clear-podman-cache

diff --git a/packaging/root/usr/share/gitlab-runner/clear-podman-cache b/packaging/root/usr/share/gitlab-runner/clear-podman-cache
new file mode 100755
index 000000000..e99fa94c6
--- /dev/null
+++ b/packaging/root/usr/share/gitlab-runner/clear-podman-cache
@@ -0,0 +1,93 @@
+#!/usr/bin/env bash
+# http://redsymbol.net/articles/unofficial-bash-strict-mode/
+
+#########################################################################################
+#  SCRIPT: clear-podman-cache.sh
+#  Description: Used to cleanup unused podman containers and volumes
+######################################################################################
+IFS=$'\n\t'
+set -euo pipefail
+
+if ! [ -x "$(command -v podman)" ]; then
+  echo -e "INFO: podman installation not found, skipping clear-podman-cache"
+  exit 0
+fi
+
+podman_API_VERSION=$(podman version --format '{{.Client.APIVersion}}')
+podman_CLIENT_VERSION=$(podman version --format '{{.Client.Version}}')
+podman_CLIENT_VERSION="${podman_CLIENT_VERSION%%-*}" # strip -whatever, so 23.0.0-rd becomes 23.0.0
+REQUIRED_podman_API_VERSION=1.25
+FILTER_FLAG="${FILTER_FLAG:-label=com.gitlab.gitlab-runner.managed=true}"
+
+usage() {
+  echo -e "\nUsage: $0 prune-volumes|prune|space|help\n"
+  echo -e "\tprune-volumes    Remove all unused containers (both dangling and unreferenced) and volumes"
+  echo -e "\tprune            Remove all unused containers (both dangling and unreferenced)"
+  echo -e "\tspace            Show podman disk usage"
+  echo -e "\thelp             Show usage"
+  exit 1
+}
+
+if awk "BEGIN {exit !(\"$podman_API_VERSION\" < \"$REQUIRED_podman_API_VERSION\")}"; then
+  echo -e "ERROR: Your current API version is lower than ${REQUIRED_podman_API_VERSION}. The client and daemon API must both be at least ${REQUIRED_podman_API_VERSION}+ to run these commands. Kindly upgrade your podman version."
+  exit 1
+fi
+
+COMMAND="${1:-prune-volumes}"
+
+case "$COMMAND" in
+
+  prune)
+
+    echo -e "\nCheck and remove all unused containers (both dangling and unreferenced)"
+    echo -e "-----------------------------------------------------------------------"
+
+    if awk "BEGIN {exit !(\"$podman_CLIENT_VERSION\" < \"17.06.1\")}"; then
+      # The podman system prune command without pruning volumes does not exist before 17.06.1, so we need to use podman rm
+      CONTAINERS=$(podman ps -a -q \
+                  --filter=status=exited \
+                  --filter=status=dead \
+                  --filter="$FILTER_FLAG")
+
+      if [ -n "${CONTAINERS}" ]; then
+        podman rm "${CONTAINERS}"
+      fi
+    else
+      podman system prune -af --filter "$FILTER_FLAG"
+    fi
+
+    exit 0
+    ;;
+
+  space)
+
+    echo -e "\nShow podman disk usage"
+    echo -e "----------------------"
+    podman system df
+
+    exit 0
+    ;;
+
+  help)
+
+    usage
+    ;;
+
+  prune-volumes)
+
+    echo -e "\nCheck and remove all unused containers (both dangling and unreferenced) including volumes."
+    echo -e "------------------------------------------------------------------------------------------"
+
+    if awk "BEGIN {exit !(\"$podman_CLIENT_VERSION\" > \"5.6.1\")}"; then
+      # Prior to 23.0, `podman volume prune` didn't support --all
+      podman system prune -af --filter "$FILTER_FLAG"
+      podman volume prune -f --filter "$FILTER_FLAG"
+    else
+      podman system prune -af --filter "$FILTER_FLAG"
+      podman volume prune -af --filter "$FILTER_FLAG"
+    fi
+
+    exit 0
+    ;;
+
+esac
-- 
2.52.0

openSUSE Build Service is sponsored by