Building Smarter

Article Information
Tagged as git, website, tech, bot, lisp
Written on

The git logo

I've been meaning to improve the way I deploy this website for a little while now. Since I stopped using Netlify in favour of a more bare-bones approach, there has been a lot of manual/ugly work involved with the process of updating this website and posting from its RSS feed to my Mastodon feed.

Initially, I simply cloned the git repository for this site to my FreeBSD box and then SSHd in to the box to pull the lates files. This, of course, is not very automatic, and it also required me hosting a lot more files in the git repository than strictly necessary since I was performing the coleslaw build on my local machine and pushing this up to replace the directory. This was always highly inefficient, but as usual I kind of just though "eh, I'll get round to doing something better later".

Then we have my bot. I was so pleased with this little thing because it was my first endeavour at writing something in common lisp. However, it too was pretty dumb. In both cases I eventually just ended up setting up cron jobs: one to perform a git pull every 15 minutes and another to run the scbl --load for the bot 5 minutes later. Yuck. Not exactly a dynamic way to do things.

Since I had a bit of time on my hands today and have also been playing around with sourcehut, I figured this was a good a time as any to improve some things. I had two objectives:

I knew the former of these was going to be best achieved with a git hook, but since I'd never actually used one of these before I really had no idea what I was doing. Luckily, smarter people than myself have already done this and have been kind enough to write it down.

tl;dr:

Next, we have my bot. This thing is a pretty simple common lisp web scraper that functions pretty much identically to my folklore thursday bot. As I said earlier, this bot was basically just powered by a cron job that tried to sbcl --load the file every 15 minutes or so. This, of course is pretty wasteful for a couple of reasons. Firstly, it's just bad practice to run the thing at intervals when I may not be posting for... months. Secondly, running the REPL rather than just using a binary is pretty expensive. Roswell to the rescue!

Roswell is a Lisp implementation manager and one of my favourite things ever. In addition to making managing your lisp implementations a breeze, it also allows you to package your lisp scripts pretty trivially. With a few minor changes, I could simply install the bot as a binary and add it to the path of the git_daemon user. Bingo. Now, the post receive hook runs the bot after receiving a new post.

This has been a fun little exercise. I should probably have got round to this sooner seeing as I've been in lockdown for a few weeks but unfortunately I'm too lazy to be lazy.