Minimal Jekyll with Docker and rsync

Background image for my website. Not quite sure why I put that here. I like aircraft I guess. Thanks DeathToTheStockPhoto!

For some reason I have a phobia of installing almost anything on my systems, given macOS’ nasty tendency to leave files lying around in Library or Application Support etc. Instead, I’ve resorted to using Docker to contain pretty much everything, and just mounting parts of my filesystem when needed.

The same held when I wanted to set up a static site for my personal webpage. I didn’t feel like installing the whole Ruby environment and packages (which takes ages, or at least seems to), neither on my laptop nor on my VPS. Instead, I relied on the great Docker to provide a fully built environment, compressed into a single command.


The setup

Courtesy of the fine folks at Jekyll, they actually provide Jekyll containers with a fully-built environment. The container is provided with an exectuable entry-point, which made my life pretty easy.

First, I grabbed a theme I liked from GitHub (thanks @volny!) and tweaked it to my needs. Then, for some Docker ‘magic’:

docker run -v $PWD:/srv/jekyll jekyll/jekyll:latest jekyll build

And sure enough, once it got done I found my site under ./_site!

Note: It’s worth mentioning that you could try jekyll serve to try and work while Jekyll is serving the website, but I’ve found that the deamon that watches for regeneration/incremental changes doesn’t play nice with Docker’s file-system adapter. In other words, it doesn’t notice changes you make to files. To me that doesn’t matter so much, it’s a simple website, but I suppose this could complicate matters for more complicated website setups.

Deployment

Searching the web, you’d get the mistaken impression that these days, the only way to deploy anything really is using Git and its hooks. I found that to be quite… absurd. I don’t understand why my VPS needs a Git setup and a Ruby environment, just to serve a bunch of static files? I’ve found more than one page describing how to get your VPS ready by installing Git, Ruby, then setting up post-update hooks to build the git repo and finally serve it. In my usual phobia for installing things (ok, and I’m just not patient to set up such a complicated flow for something that’s so damn simple), I decided to approach things differently. The solution is everyone’s favorite tool: rsync.

I could actually do this with scp as well, but that wasn’t very efficient because it copied every file, everytime, instead of an incremental copy, hence, rsync.

Literally all it takes is this:

rsync -rh ./_site/* vps:/var/www/html/

I’ll admit I’m cheating a little, because I have a vps host defined in my SSH config, but really, that’s it. No Git shenanigans, no webhooks, dark lord incantations or whatever other obscure deployment rites you could come up with.

I admit this solution won’t work for everyone and in every context, for any site. However, I do feel that we’re generally defaulting to complex, instead of briefly mentioning “or, you know, if it’s simple, you could just rsync it”.