Github Actions to Upload Hugo to BunnyCDN - Wed, Dec 8, 2021
Github Actions to Upload Hugo to BunnyCDN
I finally decided to move off my own hosted VPS server for webhosting, since I did not want to maintain it anymore. Since I had already moved to Hugo last year, this meant that I didn’t have wordpress to maintain, but I didn’t have to maintain a system either.
What I needed
I already had my website on github as a HUGO repo. This lets me use Github Actions and Workflows to create a nice auto deployment system with nothing on the backend that I have to maintain. So I just needed to find a CDN provider (BunnyCDN comes to mind), and write the workflow to do the actions I wanted.
First I got a BunnyCDN account, and setup a storage zone and pull zone. Then I took the FTP username and passwords and stored them as Repo secrets in github. This lets me use variables instead of the values directly in the workflow yaml files.
Once I had the CDN account setup, then I needed a workflow yaml.
name: N3BBQ to BunnyCDN Deployment
on:
push:
branches: [ drafts ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'
- name: Build
run: cd /home/runner/work/n3bbq_website/n3bbq_website; hugo --minify; pwd;
- name: Deploy FTP
uses: sebastianpopp/ftp-action@releases/v2
with:
host: ftp://la.storage.bunnycdn.com
user: ${{ secrets.n3bbq_drafts_BUNNYCDNSTORAGEUSER }}
password: ${{ secrets.n3bbq_drafts_BUNNYCDNSTORAGEPASSW }}
localDir: "/home/runner/work/n3bbq_website/n3bbq_website/public"
I dropped this yaml inside the .github/workflows directory in the repo. It uploads the drafts branch to my drafts website. This way I can look at them before they go to the main website. I then have another file for production locations based off the master branch.
When I am happy, I can do a pull request, and the main site updates for me.