Skip to content

Commit 5dfd467

Browse files
authored
feat: Purge bunny.net cache after production build (#891)
1 parent 3aa7294 commit 5dfd467

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

Makefile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ netlify-fetch:
7474
git reset --hard -q $(CURRENT_COMMIT)
7575
git clean -fdq
7676

77-
netlify-build: netlify-fetch build-prod build-search-index
77+
netlify-build: netlify-fetch build-prod build-search-index purge-cache
7878

79-
.PHONY: build-only-dev build-local build-prod build-ui clean netlify-build netlify-fetch
79+
# Purge the bunny.net pull zone cache after a production build so freshly
80+
# deployed content is served instead of stale cached responses. Skipped when
81+
# the bunny.net credentials are not set (e.g. local builds).
82+
purge-cache:
83+
@if [ -n "$$BUNNY_API_KEY" ] && [ -n "$$BUNNY_PULL_ZONE_ID" ]; then \
84+
echo "Purging bunny.net pull zone $$BUNNY_PULL_ZONE_ID"; \
85+
curl --fail --show-error --silent \
86+
-X POST "https://api.bunny.net/pullzone/$$BUNNY_PULL_ZONE_ID/purgeCache" \
87+
-H "AccessKey: $$BUNNY_API_KEY" \
88+
-H "content-type: application/json"; \
89+
else \
90+
echo "Skipping bunny.net purge (BUNNY_API_KEY / BUNNY_PULL_ZONE_ID not set)"; \
91+
fi
92+
93+
.PHONY: build-only-dev build-local build-prod build-ui clean netlify-build netlify-fetch purge-cache

0 commit comments

Comments
 (0)