Bootstrapped

It has been a while since I had my last website.

Intro

My previous website was realized using the famous Wordpress. While there is nothting really wrong with Wordpress, I never really liked the idea of a dynamic website. Not only are there performance disadvantages, but there is always the requirement to stay up to date with patches. Running a full content management system like Wordpress means constant maintenance to avoid getting exposed to potential security threats.

Static website generators are the way to run state of the art websites. I have decided to give Hugo a try. It is straight forward to get started with. It comes with some themes. I decided to test the Icarus theme, originally designed by Ruipeng Zhang, and started to tune it a bit.

Infrastructure

I am a big fan of Digital Ocean and am happy customer for years. Therefore I have my server running with them. It took me 5 minutes to fire up a small instance with Debian Linux and nginx.

Secure HTTP

HTTPS is the way to go these days. There is no good reason these days anymore to not offer encrypted traffic. Let’s encrypt is a disruptive and free certificate service. It took me another 30 minutes to set up HTTPS appropriately, following this tutorial.

Deployment via Git

I wanted to have a convenient way to deploy my new website. I use now git to manage versions of the code. I use $ hugo server for QA and testing and also to develop new content.

Once I am fine with the content, I am pushing changes to the local repository via git to the server. Setting this workflow up took me another 20 minutes by following these steps.

Core magic of this work flow is using one of the hooks (post-receive) that git offers. Git hooks are commands that are automatically executed before or after the check-in process. The script below takes care of the actual deployment, but again for detailed steps how to set this up, it is best to go to the website referenced in the previous link.

# file: $REPO/hooks/post-receive
#!/bin/bash
WORKING_DIRECTORY=$HOME/working
PUBLIC_WWW=$HOME/public_html
BACKUP_WWW=$HOME/backup_html
MY_DOMAIN=domain.name

set -e

rm -rf $WORKING_DIRECTORY
rsync -aqz $PUBLIC_WWW/ $BACKUP_WWW
trap "echo 'A problem occurred.  Reverting to backup.'; rsync -aqz --del $BACKUP_WWW/ $PUBLIC_WWW; rm -rf $WORKING_DIRECTORY" EXIT

git clone $GIT_REPO $WORKING_DIRECTORY
rm -rf $PUBLIC_WWW/*
/usr/bin/hugo -s $WORKING_DIRECTORY -d $PUBLIC_WWW -b "https://${MY_DOMAIN}"
rm -rf $WORKING_DIRECTORY
trap - EXIT

What’s next?

I do not know exactly yet what I am going to write about, but I have so much going on in my life at the moment that I expect to share from time to time interesting stuff. Stay tuned…

comments powered by Disqus