This repository automatically syncs static assets from the cdn/ folder to a Cloudflare R2 bucket and serves them through a custom domain (e.g. https://cdn.fiqry.dev).
- ๐ Store static assets in the
cdn/directory of this repo - ๐ GitHub Actions automatically sync changes to Cloudflare R2
- ๐ Files are served globally via Cloudflare CDN at your custom domain
- โก Immutable cache headers for long-lived assets
- ๐ Easy to extend with image resizing or versioned paths
.
โโโ cdn/ # Place all your assets here
โ โโโ images/
โ โ โโโ example.png
โ โโโ logos/
โ โโโ logo.svg
โโโ .github/
โโโ workflows/
โโโ cloudflare-r2-workflows.yml # CI/CD sync workflow
- Go to Cloudflare Dashboard โ R2 โ Buckets โ Create bucket
- Example:
assets
- Go to Bucket โ Settings โ Custom Domains โ Add
- Example:
cdn.fiqry.dev
- R2 โ Manage R2 API Tokens โ Create API Token
- Save:
Account IDAccess Key IDSecret Access Key
In your repo โ Settings โ Secrets and variables โ Actions:
R2_ACCOUNT_IDR2_ACCESS_KEY_IDR2_SECRET_ACCESS_KEY
The GitHub Action .github/workflows/cloudflare-r2-workflows.yml:
- Triggers on push to files in
cdn/** - Syncs assets to R2
- Optionally sets immutable cache headers for images
Example:
aws s3 sync cdn s3://$R2_BUCKET \
--endpoint-url https://$R2_ACCOUNT_ID.r2.cloudflarestorage.com \
--deleteYour assets are accessible via your custom domain:
https://cdn.fiqry.dev/images/example.png
- Use hashed filenames (e.g.,
logo.ab12cd.svg) for safe immutable caching - For mutable files, configure shorter
Cache-Control - Optional: Add a Worker in front of R2 for Image Resizing or authentication