Deploying and Starting this Blog
Why Do a Blog?
To write down a history of my thoughts about computer science, and create reference articles about topics I am knowledgeable enough in (at that moment) to write something meaningful about. My goal is only post about things that I will find useful for future me (and which therefore may be useful to you).
How to Deploy a Blog
Choosing a Source of Truth
A source of truth is the place where all of your CI/CD1 infrastructure stems from. If you use a wordpress site or a CMS2 like Grav3, then your source of truth might be the admin page (and underlying db) of that CMS where you edit and save the files.
I am a big fan of using git as a source of truth (gives you version control and much more). In this case, I have a github repo, which acts as the central repository from which everything is based off of.
Choosing a Deployment Method
There are so many ways to get a website up from cloud to just running a bare metal nginx server. I decided to use my kubernetes cluster.
Now, because I have selected an external git server as my source of truth, I need to figure out a way to get the files from that git repo to my cluster.
How to Sync Git Repo
There are two main ways to do this, webhooks and polling.
Pro | Con |
---|---|
WebHooks | |
Close to instant updating | Have to give git repo access to container |
Lower resource utilization | More difficult to deploy |
Git repo has more visibility | - |
Polling | |
Easy to deploy | Lots of resource utilization |
Easier to switch repos | Can be slower to update |
- | Git repo has no visibility |
I ended up choosing polling because letting the git repo have access to the cluster was a hard no4 (and I did not want to enable inbound access for the container). You can do this with the git-sync container, or a custom container I made to do webhook syncing with luajit.
How to Serve Files
This was pretty easy. You can just create a custom docker container that runs the hugo server off of some directory of files (or just use busybox and pull the hugo binary).
You can use the fast reload server as well, as that seems pretty stable5 (no need to reload the container ever time you change a file).
How to Connect Git Sync Container and Hugo Server
To do this you can take advantage of kubernetes and mount a block of storage between the two. This allows the git sync container to put updated files into the block. Then, because we are using the fast reload server, those changes should be picked up automatically.
This results in a simple yet effective CI/CD infrastructure for using git as a source of truth and hosting your hugo server.
Overall Infrastructure
My deployment files if you want it.
What Now?
The goal is to keep a history of the thoughts and interesting projects I stumble across and put up information about how they work.
Weird Name?
Ya, it’s an emacs thing. Search and replace in emacs can be done with either M-%
or M-x query-replace
. M-%
is a little hard to reach. Some people just deal with it, while others probably rebind it. I have gotten fond of just typing out M-x query-replace
and letting ido-mode handle the rest. It is one of the least optimized and most fond parts of my emacs setup.
Credits
I took some inspiration from this post.
-
Continuous Integration and Continuous Deployment. Basically the infrastructure around how software is developed and deployed. ↩︎
-
Content Managment System ↩︎
-
Using grav for another site made me realize how much I hate CMS as a source of truth. Going into that admin page was painful. ↩︎
-
I would need to have given github access to my tailnet, which seems quite hard to do. ↩︎
-
Apparently “many run it in production” from the hugo site. ↩︎