fix(ci): actually purge BunnyCDN cache in purge_cdn_cache.sh (#78)
All checks were successful
ci/crow/cron/process-updates-alpine-323-arm64 Pipeline was successful
ci/crow/cron/process-updates-redhat-9-arm64 Pipeline was successful
ci/crow/cron/process-updates-ubuntu-2204-amd64 Pipeline was successful
ci/crow/cron/process-updates-ubuntu-2204-arm64 Pipeline was successful
ci/crow/cron/process-updates-ubuntu-2404-amd64 Pipeline was successful
ci/crow/cron/process-updates-ubuntu-2404-arm64 Pipeline was successful
ci/crow/cron/process-updates-redhat-10-amd64 Pipeline was successful
ci/crow/cron/process-updates-redhat-10-arm64 Pipeline was successful
ci/crow/cron/process-updates-alpine-322-amd64 Pipeline was successful
ci/crow/cron/process-updates-alpine-322-arm64 Pipeline was successful
ci/crow/cron/process-updates-redhat-9-amd64 Pipeline was successful
ci/crow/cron/process-updates-alpine-323-amd64 Pipeline was successful
ci/crow/cron/process-updates-redhat-8-arm64 Pipeline was successful
ci/crow/cron/process-updates-redhat-8-amd64 Pipeline was successful
All checks were successful
ci/crow/cron/process-updates-alpine-323-arm64 Pipeline was successful
ci/crow/cron/process-updates-redhat-9-arm64 Pipeline was successful
ci/crow/cron/process-updates-ubuntu-2204-amd64 Pipeline was successful
ci/crow/cron/process-updates-ubuntu-2204-arm64 Pipeline was successful
ci/crow/cron/process-updates-ubuntu-2404-amd64 Pipeline was successful
ci/crow/cron/process-updates-ubuntu-2404-arm64 Pipeline was successful
ci/crow/cron/process-updates-redhat-10-amd64 Pipeline was successful
ci/crow/cron/process-updates-redhat-10-arm64 Pipeline was successful
ci/crow/cron/process-updates-alpine-322-amd64 Pipeline was successful
ci/crow/cron/process-updates-alpine-322-arm64 Pipeline was successful
ci/crow/cron/process-updates-redhat-9-amd64 Pipeline was successful
ci/crow/cron/process-updates-alpine-323-amd64 Pipeline was successful
ci/crow/cron/process-updates-redhat-8-arm64 Pipeline was successful
ci/crow/cron/process-updates-redhat-8-amd64 Pipeline was successful
## Summary While cleaning this up I noticed the script **defined** `purge_cdn_cache()` but never **called** it. Every CI run only declared the helper and exited cleanly without issuing a single curl. The PACKAGES freshness on cran.devxy.io / cran.rpkgs.com has been carried entirely by R's `Cache-Control: no-cache` header on the index files. Fixes in one shot: 1. **Actually run the purge.** The shifted args (`api_key`, `arch`, `os_id`, `domain…`) are now consumed inline and a curl POST is issued per (domain × resource). 2. **Drop `set -x`** — leaked the `AccessKey:` header into job logs. 3. **Drop the Python URL-encoder.** `curl -G --data-urlencode "url=…" --data "async=false" https://api.bunny.net/purge` does the same with no Python. The workflow purge steps can later switch from `alpine:3.23 + apk add bash curl` to a slimmer curl-only image. 4. **Add `src/contrib/Meta/archive.rds`** to the purged resource list. It's rewritten on every `process_cran_updates` run (see README) and was being served stale. ## Risks - This is the **first time** the script actually purges anything. If anything else (e.g. a downstream service) relied on the no-op behavior, this PR is the moment it stops being silent. I don't see any such caller. - Edge cache miss right after a purge means an origin S3 fetch — minor latency uptick on the first request per region per resource. Reviewed-on: #78
This commit is contained in:
parent
4425904eeb
commit
228459c0ba
1 changed files with 40 additions and 60 deletions
|
|
@ -1,64 +1,44 @@
|
|||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Purge BunnyCDN edge cache for the index files of one ARCH+OS_ID
|
||||
# combination across one or more domains.
|
||||
#
|
||||
# Usage:
|
||||
# purge_cdn_cache.sh <BUNNYNET_API_KEY> <ARCH> <OS_ID> <domain> [<domain>...]
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
set -o pipefail
|
||||
set -x
|
||||
if (( $# < 4 )); then
|
||||
echo "usage: $0 <api_key> <arch> <os_id> <domain> [<domain>...]" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Function to URL-encode a string using Python
|
||||
urlencode() {
|
||||
python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1], safe=''))" "$1"
|
||||
api_key="$1"
|
||||
arch="$2"
|
||||
os_id="$3"
|
||||
shift 3
|
||||
|
||||
resources=(
|
||||
"src/contrib/PACKAGES"
|
||||
"src/contrib/PACKAGES.gz"
|
||||
"src/contrib/PACKAGES.rds"
|
||||
"src/contrib/PACKAGES.db"
|
||||
"src/contrib/Meta/archive.rds"
|
||||
)
|
||||
|
||||
purge_one() {
|
||||
local target="$1"
|
||||
# --data-urlencode encodes value of `url=` for us; -G forces GET.
|
||||
curl -sS -G -X POST \
|
||||
-H "AccessKey: ${api_key}" \
|
||||
--data-urlencode "url=${target}" \
|
||||
--data "async=false" \
|
||||
"https://api.bunny.net/purge"
|
||||
echo
|
||||
}
|
||||
|
||||
# Function to send the purge request using the provided API key
|
||||
purge() {
|
||||
local api_key="$1"
|
||||
local url="$2"
|
||||
curl -vL -X POST -H "AccessKey: $api_key" "$url"
|
||||
}
|
||||
|
||||
# Function to generate the purge URLs for a given domain, arch, and OS ID
|
||||
generate_urls() {
|
||||
local domain="$1"
|
||||
local arch="$2"
|
||||
local os_id="$3"
|
||||
|
||||
# Array of resource paths (can be modified or extended as needed)
|
||||
local resources=(
|
||||
"src/contrib/PACKAGES"
|
||||
"src/contrib/PACKAGES.gz"
|
||||
"src/contrib/PACKAGES.rds"
|
||||
"src/contrib/PACKAGES.db"
|
||||
)
|
||||
|
||||
local urls=()
|
||||
for domain in "$@"; do
|
||||
for resource in "${resources[@]}"; do
|
||||
local target_url="https://${domain}/${arch}/${os_id}/latest/${resource}"
|
||||
local encoded
|
||||
encoded=$(urlencode "$target_url")
|
||||
urls+=( "https://api.bunny.net/purge?url=${encoded}&async=false" )
|
||||
purge_one "https://${domain}/${arch}/${os_id}/latest/${resource}"
|
||||
done
|
||||
|
||||
echo "${urls[@]}"
|
||||
}
|
||||
|
||||
# Function to process multiple domains.
|
||||
# Usage: process_domains <BUNNYNET_API_KEY> <ARCH> <OS_ID> domain1 [domain2 ... domainN]
|
||||
purge_cdn_cache() {
|
||||
local api_key="$1"
|
||||
local arch="$2"
|
||||
local os_id="$3"
|
||||
shift 3 # Remove the first three arguments, leaving the domains
|
||||
|
||||
for domain in "$@"; do
|
||||
# Generate the list of URLs for the current domain
|
||||
local urls
|
||||
urls=($(generate_urls "$domain" "$arch" "$os_id"))
|
||||
|
||||
# Purge each URL
|
||||
for url in "${urls[@]}"; do
|
||||
purge "$api_key" "$url"
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
# Example usage:
|
||||
# purge_cdn_cache "$BUNNYNET_API_KEY" "$ARCH" "$OS_ID" "domain1.com" "domain2.com"
|
||||
done
|
||||
|
|
|
|||
Loading…
Reference in a new issue