Behind the Curtain

The inner workings of this website, a look at how it is written, generated, deployed, hosted, and served.

How it was

Regular visitors to this website (hi mum) will notice that it has had a little bit of a revamp. Previously my site was a custom theme for Jekyll hosted on GitHub pages. I got fed up about something to do with GitHub and so decided to move away. I took a rip of the static site and threw it up on an OpenBSD box I had lying around (as you do). This worked fine but any time I wanted to make a minor edit, I had to ssh into the box and make my changes there. Not ideal.

How it is

Now I have my website built using ssg, a static site generator from Roman Zolotarev written in shell. It is still hosted on the same OpenBSD server with a nice automated rollout process.

The source

The source for this website is available here in case you would like to mail a patch for whatever reason. The repository includes the src files for the static site, the scripts to create the site, and the .build.yaml which looks after the deployment of the website.

The deploy

Every time I push to master, an automated build on builds.sr.ht is kicked off, as you can see from the output here:

ols $ gpsup
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 1.29 KiB | 1.29 MiB/s, done.
Total 5 (delta 3), reused 0 (delta 0)
remote: Build started: https://builds.sr.ht/~ols/job/77835

The contents of the .build.yaml which handles this are as follows:

image: alpine/latest
packages:
    - rsync
    - perl
sources:
    - https://git.sr.ht/~ols/ols.wtf
environment:
    deploy: deploy@beast.ols.wtf
    dir: /home/deploy/ols.wtf
secrets:
    -  ce249f9a-ef77-48d5-9f3b-3005bf9b8db9
tasks:
    - build: |
            cd ols.wtf
            export PATH="$PWD/bin:$PATH"
            mkdir dst
            ssg5 src dst 'Oliver Leaver-Smith' 'https://ols.wtf'
    - deploy: |
            cd ols.wtf
            sshopts="ssh -o StrictHostKeyChecking=no"
            $sshopts $deploy "rm -rf $dir/previous/* && cp -R $dir/current/* $dir/previous/ && rm -rf $dir/current/*"
            rsync --rsh="$sshopts" -rP dst/* $deploy:$dir/current/
    - clean: |
            cd ols.wtf
            rm -rf dst

This deploy will generate the static site, copy the contents of $dir/current (where $dir is the htdocs directory for the site on the web server) to $dir/previous, then rsync the contents of dst/ within the build instance to $dir/current.

The platform

As I mentioned earlier, the web server this website is hosted on is running OpenBSD 6.5, the web server software is OpenBSD's httpd. Like most things OpenBSD, the config required to achieve what you want is simple and self-explanatory. It follows below:

server "ols.wtf" {
    listen on * tls port 443
    hsts {
        subdomains
    }
    tls {
        certificate "/etc/ssl/ols.wtf.pem"
        key "/etc/ssl/private/ols.wtf.key"
        ciphers "secure"
    }
    root "/htdocs/ols.wtf/current"
    location "/.well-known/acme-challenge/*" {
        root "/acme"
        request strip 2
    }
}

server "ols.wtf" {
    listen on * port 80
    block return 301 "https://ols.wtf$REQUEST_URI"
}

You can see I also have acme-client managing the LetsEncrypt certificate for TLS goodness too, but configuration of that is for another blog post.