Git, Gogs, Jekyll and Auto-deployment

By chimo on (updated on )
Note: This setup was superseded by Gitea, Drone CI, Hugo and Auto-deployment.

Since yesterday, this blog deploys automatically when I push changes to its git repository. Before that, my workflow was something like:

  1. ssh into the server
  2. write something
  3. git add, git commit, git push (or forget about this step altogether)
  4. bundle exec jekyll build

Now, I do:

  1. Write something (from any machine where I have a copy of my blog's git repository)
  2. git add, git commit, git push

The best part for me is that I should now have a proper git history of my blog's modifications instead of a few giant commits spaced far apart in time due to skipping step 3 by mistake or laziness.

This isn't unique, has been done before, and a few automated deployment techniques are documented on the Jekyll site, but I wanted to jot down my configuration for a few reasons:

  • As a "note to self" so I can recall how it works if I need to set this up again
  • I'm due for my yearly blog post (yes, I should write more)
  • It might be helpful to other people using a similar list of tools

The Environment

This blog is hosted on a VPS (Linode) that runs a few other products, notably Gogs which I use to "self-host" my git projects.

One of those git projects is the source files for the blog.

Gogs lets you edit git hooks via its web interface under the git repository's "Settings > Git Hooks" section. The one we're interested in is "post-receive", which runs on the server-side after git is done receiving the changes you pushed to it via "git push" from the client-side.

Since both Gogs and the Jekyll blog are on the same server, the only thing I have to do is tell git to run the "jekyll build" command (along with some house-keeping details) after it got the new data:

#!/usr/bin/bash

mkdir -p /tmp/gogs-bundle               # Create directory where bundle will install required tools to build
export BUNDLE_BIN_PATH=/tmp/gogs-bundle # Set env. var used by bundle so it knows where to install stuff

cd /srv/http/chromic.org/public_html    # Change to the directory where the blog's source files are
unset GIT_DIR                           # Have git use $PWD instead of $GIT_DIR
git pull                                # Get latest changes

bundle install                          # Make sure we have all the required gems, etc. installed
bundle exec jekyll build                # Deploy!

And that's pretty much it. Make sure the user running your Gogs instance has access to the blog's files/directories and you should be good to go.

Recent articles from blogs I follow

The Scunthorpe Problem

I was talking with a friend recently about an email of theirs running afoul (🐔) of another aggressive filter system, because they dared to to talk with someone called Dickson. I know right, they’re the absolute worst. For those unfamiliar, this is the The…

via Rubenerd November 21, 2024

In which Neil is surprised by the lack of an HDMI cable

Some modern technology decisions baffle me. Today, I was sitting in a meeting room. In the room was my friend, with her laptop. Her laptop has an HDMI port. Also in the room was a screen, onto which my friend wished to display her laptop’s desktop. The screen …

via Neil's blog November 19, 2024

Helm: JSON schema generation

Helm charts support the inclusion of a values.schema.json file to validate values.yaml. Documentation: https://helm.sh/docs/topics/charts/#schema-files A JSON schema is akin to defining the structure of and type-annotating a JSON file. It helps to “shift lef…

via not just serendipity November 14, 2024