Wipe cache from cloudflare after updates

This commit is contained in:
Ishan Jain 2023-04-05 21:53:36 +05:30
parent 6ffae6fa25
commit e9c9acd9de
Signed by: ishan
GPG Key ID: 0506DB2A1CC75C27

View File

@ -52,9 +52,18 @@ jobs:
# remove `.github` and any other paths we do not want in the CDN # remove `.github` and any other paths we do not want in the CDN
rm -rf .github .git rm -rf .github .git
# Note all the files that are missing in cdn, missing in repo or they are different
echo "Checking files"
(rclone check s3:$CDN_BUCKET/icons icons --download --combined /tmp/diff || true)
# List all files that are different
echo "Listing all differences"
cat /tmp/diff | grep --quiet --invert-match '^=' || echo "No changes"
# Synchronize the `icons` directory # Synchronize the `icons` directory
# Note: This command should be added for any new directories in this repo # Note: This command should be added for any new directories in this repo
# otherwise, they'll not be synced # otherwise, they'll not be synced
echo "Syncing files"
rclone sync icons s3:$CDN_BUCKET/icons rclone sync icons s3:$CDN_BUCKET/icons
rclone config delete s3 rclone config delete s3
@ -63,3 +72,12 @@ jobs:
# Note: This command should be added for any new directories in this repo # Note: This command should be added for any new directories in this repo
# otherwise, cache for those directories will not be cleared # otherwise, cache for those directories will not be cleared
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: Bearer $DO_TOKEN" -d '{"files": ["icons/*"]}' https://api.digitalocean.com/v2/cdn/endpoints/$CDN_ID/cache curl -X DELETE -H "Content-Type: application/json" -H "Authorization: Bearer $DO_TOKEN" -d '{"files": ["icons/*"]}' https://api.digitalocean.com/v2/cdn/endpoints/$CDN_ID/cache
# Purge each entry in /tmp/diff from cloudflare's cache
cat /tmp/diff | grep --quiet --invert-match '^=' || true | while read line;
do
entry=$(echo $line | awk '{print $2}');
url="https://cdn.instadapp.io/icons/${entry}"
echo "Clearing $url from cache"
curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE_ID }}/purge_cache" -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_KEY }}" -H "Content-Type: application/json" --data "{\"files\": [\"$url\"]}"
done;