aboutsummaryrefslogtreecommitdiffstats
path: root/screwdriver/delete-old-artifactory-artifacts.sh
diff options
context:
space:
mode:
authorArnstein Ressem <aressem@verizonmedia.com>2021-09-13 16:24:38 +0200
committerArnstein Ressem <aressem@verizonmedia.com>2021-09-13 16:24:38 +0200
commit19a87b04077ece0b406efeda9a34f2102d91ee5a (patch)
tree0c0f2939501d6d22620c77d9e34db25921f62d11 /screwdriver/delete-old-artifactory-artifacts.sh
parent9420cc0c5873d92fd20c9ab99bc54a23001d606a (diff)
Add jobs to mirror RPMs and do repo cleanup.
Diffstat (limited to 'screwdriver/delete-old-artifactory-artifacts.sh')
-rwxr-xr-xscrewdriver/delete-old-artifactory-artifacts.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/screwdriver/delete-old-artifactory-artifacts.sh b/screwdriver/delete-old-artifactory-artifacts.sh
new file mode 100755
index 00000000000..062e37fdaa1
--- /dev/null
+++ b/screwdriver/delete-old-artifactory-artifacts.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+set -euo pipefail
+
+MAX_NUMBER_OF_RELEASES=200
+ARTIFACTORY_URL="https://artifactory.verizonmedia.com/artifactory"
+
+# JFrog Cloud repo file
+if [[ ! -f /etc/yum.repos.d/vespa.repo ]]; then
+ cat << EOF > /etc/yum.repos.d/vespa.repo
+[vespa-release]
+name=Vespa releases
+baseurl=$ARTIFACTORY_URL/vespa/centos/7/release/\$basearch
+gpgcheck=0
+enabled=1
+EOF
+fi
+
+VERSIONS_TO_DELETE=$(yum list --quiet --showduplicates --disablerepo='*' --enablerepo=vespa-release vespa | awk '/[0-9].*\.[0-9].*\.[0-9].*/{print $2}' | sort -V | head -n -200)
+
+RPMS_TO_DELETE=$(mktemp)
+trap "rm -f $RPMS_TO_DELETE" EXIT
+
+for VERSION in $VERSIONS_TO_DELETE; do
+ curl -sSL -H "content-type:text/plain" -H "Authorization: Bearer $JFROG_API_TOKEN" \
+ --data "items.find({ \"repo\": { \"\$eq\": \"vespa\" }, \"name\": {\"\$match\": \"vespa*$VERSION*\"} }).include(\"repo\", \"path\", \"name\")" \
+ "$ARTIFACTORY_URL/api/search/aql" \
+ | jq -re ".results[]|\"$ARTIFACTORY_URL/artifactory/\(.repo)/\(.path)/\(.name)\"" >> $RPMS_TO_DELETE
+done
+
+echo "Deleting the following RPMs:"
+cat $RPMS_TO_DELETE
+
+if [[ -n $SCREWDRIVER ]] && [[ -z $SD_PULL_REQUEST ]]; then
+ for RPM in $(cat $RPMS_TO_DELETE); do
+ curl -sSL -H "Authorization: Bearer $JFROG_API_TOKEN" -X DELETE $RPM
+ done
+fi
+
+