Migrating from WordPress to Hugo
Migrating from WordPress to Hugo
So after a little tinkering around and looking at options for something different I decided to swap to Hugo. Why Hugo? Because I wanted to not just swap CMS but also try out more with Github’s Actions (CD/CI), essentially I have combined both those at the same time.
The How
So Hugo is basically a static site generator that can pull data from any number of different sources, compile them via templates into a static site. With that in mind, I looked into GitHub’s Actions a little more to see if I could automate the deployment.
CD/CI Actions
The actions are pretty simple to deploy with Hugo. For myself I am using SCP to copy files from the generated action environment to place them on a remote server (this one), below is a copy of the workflow file.
name: Hugo Deploy
on:
push:
branches: [ master ]
jobs:
# This workflow contains a single job called "build"
build:
name: Build
# Runner type
runs-on: ubuntu-latest
# Sequence of tasks
steps:
# Checks-out the repo
- uses: actions/checkout@v2
# Setup Hugo
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.72.0'
# Build Hugo
- name: Build Hugo
run: hugo -D --minify
# Copy files to remote
- name: Copy Repo files to remote dest
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
port: ${{ secrets.PORT }}
key: ${{ secrets.KEY }}
source: "./public"
target: "~/blog"
It’s a pretty simple and straight forward set of actions. To break it down:
- It makes an environment that is ubuntu based
- It copies the repo into that environment
- Sets up Hugo based on version, using peaceiris’ script
- Runs the Hugo build command (with drafts in this case)
- Copies the newly generated public folder, makes a tar file
- Copies the file over to the server, untars, and then removes the tar
All in all this is a pretty good way to deploy to a VPS or baremetal. Is it a little over the top? Maybe, but I’m a little lazy and that leads to figuring how to automate. So here we are.