Hello there ![]()
I’d like to introduce you to…
Kibry S3 Sync — 1.0.0(kinda stable)
TL;DR:
A plugin that enables you to upload files to Cloudflare r2 or any s3-compatible bucket, while replacing the original with a 1x1 pixel placeholder. It comes with some nice safeguards and (dry-run) cli support.
Disclaimer:
This plugin is considered ‘kinda stable’, meaning that I’ve run it multiple times with success. However, since it’s not yet ‘Battle Tested’ I recommend using it very carefully at first. Making backups is always a good practice. You could also try it out on the Kirby Starterkit.
Use case:
I’m increasingly relying on Ploi.io / DigitalOcean (droplets) for hosting Kirby as a headless CMS, while deploying the frontend —in my case: Nuxt/Svletkit— to Cloudflare Pages. While this setup works really great I realized that deploying multiple Kirby instances like this to a single droplet/server can come with a cost… Namely that those droplets/servers are not cost-efficient for storing large amounts of —mostly— static files.
That’s when I became interested in using an s3 compatible bucket for storing these files. Since my frontend already ‘lives’ on Cloudflare I was mostly interested in using r2 (s3-compatible). The nice benefit for me is how good it’s cache-layers works.
s3 or r2?
If you’ve read ‘Use Case’ you’ll understand why it’s r2-first. But since r2 is s3-compatible it’s well suited to work with other s3 buckets. That’s the reason why I chose to name it as ‘s3 sync’.
Safeguards:
Since storing files and/or bulk-syncing them is kind of a scary practice I tried to include as many safeguards as possible to make sure none of your data get’s lost in the process. That being said, please make sure to create backups/snapshots before ‘trying out’ the script
.
I included the --dry-run script flag to see what will happen. When a script has skipped files or something went wrong in the execution you can the script again and it will find those skipped files.
Files are only removed from the content-folder when we are sure that the upload succeeded and all necesary data is set. When deleting files, those get archived in the _archive folder. Tip: deleting the _archive folder can be be automated with a Cronjob (I haven’t tried it yet).
Give it a try?:
As this is the first time I’ve published a plugin for the Kirby ecosystem I’m looking forward to hearing your feedback
I’m developing this on my own, so please bare with me when addressing potential bugs or improvements. Thanks in advance
.