I spent some time last week enabling continous deployment for this site. As a quick bit of background, I use the Zola static site generator to generate the site and Netlify to host it.
I can highly recommend both the tools, as Zola is a very simple and fast generator and Netlify is a pretty feature-complete static hosting platform with an extremely generous free tier. And as we'll later see, the two work quite well together.
The basic idea is that Netlify allows you to connect your sites to Git repositories. At the time of this writing, this includes Github, Gitlab, and Bitbucket. Once a repository has been connected to a site, every time you push to the "main" development branch, Netlify will trigger a deployment pipeline.
This workflow can either be configured from within their web interface or using
a netlify.toml
config file in the root folder of your repository. For static
sites using Zola, this file looks like the following.
[build]
publish = "public"
command = "zola build"
[build.environment]
ZOLA_VERSION = "0.12.0"
The most important line of code in this config is setting ZOLA_VERSION
. This
tells Netlify that we're working with a Zola site so it should please ensure
that the zola
binary exists, corresponds to version 0.12.0
and is available
on $PATH
. The other two lines of config tell Netlify that on every push to
master
(or whatever your main development branch is called), the command zola build
should be run and the contents of the public
folder (which zola build
populates) should be published to the static site.
Once this file is in place and your Git repository is connected to your Netlify site, the process basically just works. That's basically the only switch you would have to flip.
Overall this process was quite straight forward and I'm really happy with the
result. The nicest thing is that the one manual step involved with this site (of
uploading to Netlify) is not there anymore. Prior to having this pipeline in
place, I was using netlify-cli
every time I made a change to deploy the site.
Additionally there was also the dance of local git branches to be able to
differentiate between what's live (the stable
branch) and what's not (the
master
branch).
Now, I can just make some edits and push to Github and the end result is automatically published to https://sgoel.dev within a few seconds. Netlify even sends me a nice little email everytime the site contents change. I don't have to perform any extra steps locally, and there's only one git branch to maintain. And all the stuff that's pushed to Github is "live", and everything else is a draft.
💯/💯 would recommend.