feat: use function for cache purging

This commit is contained in:
Patrick Schratz 2025-03-26 13:22:00 +01:00
commit d440585078
Signed by: pat-s
GPG key ID: 3C6318841EF78925

View file

@ -62,12 +62,55 @@ steps:
BUNNY_API_KEY:
from_secret: BUNNY_API_KEY
commands: |
curl -sL -X POST -H "AccessKey: $BUNNY_API_KEY" https://api.bunny.net/purge?url=https%3A%2F%2Fcran.devxy.io%2Famd64%2Frhel9%2Flatest%2Fsrc%2Fcontrib%2FPACKAGES&async=false
curl -sL -X POST -H "AccessKey: $BUNNY_API_KEY" https://api.bunny.net/purge?url=https%3A%2F%2Fcran.devxy.io%2Famd64%2Frhel9%2Flatest%2Fsrc%2Fcontrib%2FPACKAGES.gz&async=false
curl -sL -X POST -H "AccessKey: $BUNNY_API_KEY" https://api.bunny.net/purge?url=https%3A%2F%2Fcran.devxy.io%2Famd64%2Frhel9%2Flatest%2Fsrc%2Fcontrib%2FPACKAGES.rds&async=false
curl -sL -X POST -H "AccessKey: $BUNNY_API_KEY" https://api.bunny.net/purge?url=https%3A%2F%2Fcran.devxy.io%2Famd64%2Frhel9%2Flatest%2Fsrc%2Fcontrib%2FPACKAGES.db&async=false
curl -sL -X POST -H "AccessKey: $BUNNY_API_KEY" https://api.bunny.net/purge?url=https%3A%2F%2Fcran.devxy.io%2Famd64%2Frhel9%2Flatest%2Fsrc%2Fcontrib%2FPMeta%2FParchive.rds&async=false
sleep 20 # need to wait a bit to successfully deliver API calls
#!/bin/bash
# Variables for subdomains, OS identifier and architecture
SUBDOMAIN1="cran.devxy.io"
SUBDOMAIN2="cran.allianceswisspass.devxy.io"
OS_ID="rhel9"
ARCH="amd64"
# Array of resource paths
resources=(
"src/contrib/PACKAGES"
"src/contrib/PACKAGES.gz"
"src/contrib/PACKAGES.rds"
"src/contrib/PACKAGES.db"
)
# Function to URL-encode a string using Python
urlencode() {
python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1], safe=''))" "$$1"
}
# Function to send the purge request
purge() {
curl -sL -X POST -H "AccessKey: $BUNNY_API_KEY" "$$1"
}
# Function to generate the purge URLs for a given subdomain
generate_urls() {
local subdomain=$$1
local urls=()
for resource in "${resources[@]}"; do
# Build the unencoded URL based on variables
local target_url="https://$${subdomain}/$${ARCH}/$${OS_ID}/latest/$${resource}"
# URL-encode the target URL
local encoded=$(urlencode "$$target_url")
# Construct the full API call URL
urls+=( "https://api.bunny.net/purge?url=$${encoded}&async=false" )
done
echo "$${urls[@]}"
}
# Generate URLs for both subdomains
urls_combined=( $$(generate_urls "$$SUBDOMAIN1") )
allianceswisspass_urls=( $$(generate_urls "$$SUBDOMAIN2") )
# Purge for first subdomain and then wait
for url in "$${urls_combined[@]}"; do
purge "$$url"
done
- name: 'ntfy'
image: binwiederhier/ntfy:v2.11.0