feat: use function for cache purging
This commit is contained in:
parent
c7459b9712
commit
d440585078
1 changed files with 49 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue