Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purge Cloudflare cache for all files after uploading R2 artifacts #3568

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

sairon
Copy link
Member

@sairon sairon commented Aug 29, 2024

If an attempt to access R2 artifacts is made before the files exist, the 404 reply gets cached and it's not possible to access the file after it's been created without purging the cache, essentially doing a cache poisoning for future build artifacts. To avoid it, list all files that have been created by the build and call the purge cache API.

As there's a limit for number of files that can be purged in a single API call [1], the GNU split utility is used to split intermediary list of files to chunks of 30 URLs, which is then converted to a JSON array and passed to the curl command.

[1] https://developers.cloudflare.com/api/operations/zone-purge#purge-cached-content-by-url

If an attempt to access R2 artifacts is made before the files exist, the 404
reply gets cached and it's not possible to access the file after it's been
created without purging the cache, essentially doing a cache poisoning for
future build artifacts. To avoid it, list all files that have been created by
the build and call the purge cache API.

As there's a limit for number of files that can be purged in a single API call
[1], the GNU split utility is used to split intermediary list of files to
chunks of 30 URLs, which is then converted to a JSON array and passed to the
curl command.

[1] https://developers.cloudflare.com/api/operations/zone-purge#purge-cached-content-by-url
@sairon sairon added the build Build and CI related issues label Aug 29, 2024
@sairon sairon requested review from agners and ludeeus August 29, 2024 11:45
Copy link
Member

@agners agners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sairon sairon merged commit d9e46d6 into dev Sep 2, 2024
2 checks passed
@sairon sairon deleted the purge-cf-cache branch September 2, 2024 08:38
@sairon sairon mentioned this pull request Sep 26, 2024
@sairon sairon mentioned this pull request Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Build and CI related issues cla-signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants