Publishing a static site to Bunny.net using Gitea Actions
Publish a Hugo-powered static site to Bunny.net using Gitea Actions.
Bunny.net (formerly BunnyCDN) can host a static site by serving files from a storage zone through a pull zone. The workflow below uses Gitea Actions to build a Hugo site, upload it over FTP, and purge the CDN cache after each deployment.
Creating a storage zone
Create a storage zone in the Bunny.net dashboard and give it a name that you can associate with the site. Select the regions where Bunny.net should replicate the content. More regions can make the site faster in those locations. They also cost more.
Open the storage zone's FTP credentials page and keep the host, username, and password for the workflow.
Creating a pull zone
Create a pull zone in the Bunny.net dashboard, give it a recognizable name, and set the storage zone as its "origin". Select the regions from which the CDN should serve the site. For a custom domain, add it to the pull zone and create a CNAME record at your DNS provider that points to the Bunny.net pull zone.
Uploading the site
This Gitea Actions workflow builds the Hugo site, mirrors the generated public/ directory to the storage zone with its FTP credentials, and purges the pull zone cache. It can be adapted to another CI system.
# .gitea/workflows/hugo-build.yml
name: Build and Deploy to BunnyCDN
on:
push:
branches:
- main
jobs:
bunnycdn:
name: bunnycdn-publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.126.1'
extended: true
- name: Build
run: hugo --minify
- name: Deploy to BunnyCDN
run: |
apt update -y
apt install -y lftp
lftp -e "
set ftp:ssl-allow true;
set ftp:ssl-protect-data true;
set ssl:verify-certificate no;
open ${{ secrets.BUNNYCDN_FTP_HOST }};
user ${{ secrets.BUNNYCDN_FTP_USER }} ${{ secrets.BUNNYCDN_FTP_PASSWORD }};
mirror -R --delete -v public/ .;
bye;
"
- name: purge bunny cache
run: |
curl --request POST \
--url https://api.bunny.net/pullzone/${{ secrets.BUNNYCDN_ZONE_ID }}/purgeCache \
--header 'AccessKey: ${{ secrets.BUNNYCDN_API_KEY }}' \
--header 'content-type: application/json'
Set the BUNNYCDN_FTP_HOST, BUNNYCDN_FTP_USER, and BUNNYCDN_FTP_PASSWORD secrets from the storage zone's FTP credentials page. Hugo builds the site into public/, which lftp recursively mirrors to the root of the storage zone. The --delete option removes remote files that are no longer in public/, and -v prints verbose transfer output.
Set BUNNYCDN_ZONE_ID and BUNNYCDN_API_KEY secrets in your Action's settings found on the Bunny.net dashboard. The final workflow step uses them to purge the pull zone cache after the upload.
The pull zone URL serves the uploaded site. If you configured a custom domain, it serves the same content. Caching, compression, and auto-HTTPS can be configured on the pull zone.
Note: Bunny.net is rebuilding its dashboard, so these steps may not match the current dashboard. The underlying process should remain largely the same.