Skip to content

fiqryq/media

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

15 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Cloudflare R2 CDN Sync

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).

โœจ Features

  • ๐Ÿ“‚ 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

๐Ÿ“ Repository Structure

.
โ”œโ”€โ”€ cdn/                  # Place all your assets here
โ”‚   โ”œโ”€โ”€ images/
โ”‚   โ”‚   โ””โ”€โ”€ example.png
โ”‚   โ””โ”€โ”€ logos/
โ”‚       โ””โ”€โ”€ logo.svg
โ””โ”€โ”€ .github/
    โ””โ”€โ”€ workflows/
        โ””โ”€โ”€ cloudflare-r2-workflows.yml # CI/CD sync workflow

๐Ÿ”‘ Setup

1. Create R2 Bucket

  • Go to Cloudflare Dashboard โ†’ R2 โ†’ Buckets โ†’ Create bucket
  • Example: assets

2. Attach Custom Domain

  • Go to Bucket โ†’ Settings โ†’ Custom Domains โ†’ Add
  • Example: cdn.fiqry.dev

3. Generate API Keys

  • R2 โ†’ Manage R2 API Tokens โ†’ Create API Token
  • Save:
    • Account ID
    • Access Key ID
    • Secret Access Key

4. Add GitHub Secrets

In your repo โ†’ Settings โ†’ Secrets and variables โ†’ Actions:

  • R2_ACCOUNT_ID
  • R2_ACCESS_KEY_ID
  • R2_SECRET_ACCESS_KEY

โš™๏ธ Workflow

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 \
  --delete

๐ŸŒ Accessing Files

Your assets are accessible via your custom domain:

https://cdn.fiqry.dev/images/example.png

๐Ÿงฐ Development Notes

  • 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

About

A personal CDN for hosting and serving public assets, powered by Cloudflare R2.

Topics

Resources

Stars

Watchers

Forks

Contributors

โšก