aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnstein Ressem <aressem@yahooinc.com>2023-11-06 14:13:03 +0100
committerArnstein Ressem <aressem@yahooinc.com>2023-11-06 14:13:03 +0100
commit7f37e3ba54410446c56953c9ce7f88c48ba60ca5 (patch)
tree39bc7aa1d2bf74c79d8b6a3ee34813562e397bc1
parent90f6a433b4e11d7de99a152d84ea4b0c880d7778 (diff)
Add automatic cleanup of archive.
-rw-r--r--screwdriver.yaml12
-rwxr-xr-xscrewdriver/delete-old-cloudsmith-artifacts.sh34
2 files changed, 46 insertions, 0 deletions
diff --git a/screwdriver.yaml b/screwdriver.yaml
index d4e50f5d581..dd9fa5cba8b 100644
--- a/screwdriver.yaml
+++ b/screwdriver.yaml
@@ -546,6 +546,18 @@ jobs:
- mirror-aarch64: |
screwdriver/publish-unpublished-rpms-to-archive.sh aarch64
+ delete-old-versions-in-archive:
+ annotations:
+ screwdriver.cd/cpu: LOW
+ screwdriver.cd/ram: LOW
+ screwdriver.cd/timeout: 10
+ screwdriver.cd/buildPeriodically: H 6 * * 1
+ secrets:
+ - CLOUDSMITH_API_CREDS
+ steps:
+ - cleanup: |
+ screwdriver/delete-old-cloudsmith-artifacts.sh
+
mirror-copr-rpms-to-artifactory:
image: quay.io/centos/centos:stream8
annotations:
diff --git a/screwdriver/delete-old-cloudsmith-artifacts.sh b/screwdriver/delete-old-cloudsmith-artifacts.sh
new file mode 100755
index 00000000000..1dada7a4499
--- /dev/null
+++ b/screwdriver/delete-old-cloudsmith-artifacts.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+set -euo pipefail
+MAX_NUMBER_OF_RELEASES=50
+
+# Cloudsmith repo
+rpm --import 'https://dl.cloudsmith.io/public/vespa/vespa/gpg.0F3DA3C70D35DA7B.key'
+curl -1sLf 'https://dl.cloudsmith.io/public/vespa/vespa/config.rpm.txt?distro=el&codename=8' > /tmp/vespa-vespa.repo
+dnf config-manager --add-repo '/tmp/vespa-vespa.repo'
+rm -f /tmp/vespa-vespa.repo
+
+VERSIONS_TO_DELETE=$(dnf list -y --quiet --showduplicates --disablerepo='*' --enablerepo=vespa-vespa vespa | awk '/[0-9].*\.[0-9].*\.[0-9].*/{print $2}' | sort -V | head -n -$MAX_NUMBER_OF_RELEASES | grep -v "7.594.36")
+
+RPMS_TO_DELETE=$(mktemp)
+trap "rm -f $RPMS_TO_DELETE" EXIT
+
+for VERSION in $VERSIONS_TO_DELETE; do
+ curl -sLf --header 'accept: application/json' \
+ "https://api.cloudsmith.io/v1/packages/vespa/vespa/?query=version:${VERSION}" | jq -re '.[] | .slug' >> $RPMS_TO_DELETE
+done
+
+echo "Deleting the following RPMs:"
+cat $RPMS_TO_DELETE
+
+if [[ -n $SCREWDRIVER ]] && [[ -z $SD_PULL_REQUEST ]]; then
+ for RPMID in $(cat $RPMS_TO_DELETE); do
+ curl -sLf -u "$CLOUDSMITH_API_CREDS" -X DELETE \
+ --header 'accept: application/json' \
+ "https://api.cloudsmith.io/v1/packages/vespa/vespa/$RPMID/"
+ done
+fi
+
+