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