From 914b2e8af58b03caa882f2760b3e51626bf70c29 Mon Sep 17 00:00:00 2001 From: pat-s Date: Thu, 28 May 2026 15:48:03 +0200 Subject: [PATCH] fix(ci): actually purge BunnyCDN cache in purge_cdn_cache.sh The script defined a purge_cdn_cache() function but never invoked it, so every CI run only declared the helper and exited cleanly without issuing a single curl. The CDN had been relying entirely on the Cache-Control: no-cache headers R writes onto PACKAGES* objects. Rewrite to call the purge inline; while here: - drop `set -x` (leaked the AccessKey header into logs) - drop the python3 urlencoder; `curl --data-urlencode` does the same with no Python dep, so the workflow purge step no longer needs `apk add bash curl` over `curl --data-urlencode`-capable curl alone - add `src/contrib/Meta/archive.rds` to the resource list - it changes during process-updates and was being served stale --- scripts/purge_cdn_cache.sh | 96 +++++++++++++++----------------------- 1 file changed, 38 insertions(+), 58 deletions(-) diff --git a/scripts/purge_cdn_cache.sh b/scripts/purge_cdn_cache.sh index a4e34c3..b525a44 100644 --- a/scripts/purge_cdn_cache.sh +++ b/scripts/purge_cdn_cache.sh @@ -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 [...] +# +set -euo pipefail -set -o pipefail -set -x +if (( $# < 4 )); then + echo "usage: $0 [...]" >&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 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 -- 2.54.0