Hugo, Gitea, and Drone CI
One of the many nice things about the tildeverse is that we have can have repos in tildegit. Another nice thing is it uses Gitea and Drone CI. Yay open source, and stuff.
Bashblog might be nice if all you want to do is write and post, but it’s not very nice when it comes to customization. Also I’ve been spoiled rotten by Gitlab/hub Pages and really wanted to set up something like that for the tildes.
And so, after much putting it off and asking people for help, I finally undertook the seemingly daunting (but actually easy although a bit tedious) task of setting all of this up.
I’ll be the first to admit I know jack shit about Docker, (and I should probably learn how to use it at some point since I have a spare box at home that I plan to use as a personal server of sorts), so my current solution may not be the best or most elegant but for the intents and purposes of setting this up I figured it wouldn’t be 100% necessary to create containers and such. And I would have never gotten this off the ground either, so there’s that.
After creating and testing my Hugo site locally, I pushed it all to a repo,
activated it under Drone and got to work on the .drone.yml
file.
A couple searches later, I was all set up with something I pulled from the Drone docs1. Easy peasy… Or so I thought. I went with a combination of the Hugo plugin2 and the rsync plugin3, which didn’t work at all. PEBCAK? I’m not so sure. For some reason, rsync wouldn’t pick up on the secrets I set up on the repo config. Oh well… I fell back to the solution the documentation proposes and used the scp plugin4, which does work. Or would have worked if there was something for it to copy… This is how I discovered the Hugo plugin didn’t work. Or didn’t work for me? I found a number of posts of people using it successfully. Mind you, these are all a couple of years old now.
At this point I scrapped all the remote stuff, went back to the docs5 for a fresh start, and decided to try a manual approach without using containers.
First, I recreated the repo setup in Drone and added the connection details as
secrets.
Second, I logged into my ~club account and cloned the repo.
Then I recreated .drone.yml
as follows:
---
kind: pipeline
type: ssh
name: deploy
server:
host:
from_secret: host
user:
from_secret: username
ssh_key:
from_secret: ssh_key
trigger:
branch:
- blog
steps:
- name: deploy
commands:
- cd /home/me/myBlog
- git pull origin blog
- hugo --cacheDir ~/temp/
- rm -r resources
- cp -ruf public/* /home/me/public_html
- rm -r public
This establishes an ssh connection, pulls the git repo, generates the static pages using hugo, and moves them to their designated location.
The trigger
option makes sure the pipeline only works on the specified branch,
this makes working on themes or whatever on a different branch easier, and it
won’t eat up CI time.
Hugo’s default cacheDir
is /tmp
, which can’t be accessed by non admin users
on tilde, so I set it to a directory I created.
Last but not least, I created a .gitignore
with the following lines in it:
public/
resources/
public
contains the generated blog and resources
houses files used in the
generation, they’re not needed in the repo.