Serving a static blog from a Snap
Out of curiosity, I decided to try and package this blog as a snap package, and it turns out to be an extremely easy and convenient way to deploy a static blog!
There are several advantages that the snappy packaging format bring to the table as far as applications developers are concerned (which I am, my application in this case being my blog).
Snapcraft makes it very easy to package things, there's per-application jails preventing/sandboxing your applications/services that basically comes for free, and it also comes with a distribution mechanism that takes care of auto-upgrading your snap on any platform.
Since this blog is generated using the excellent "pelican" static blog generator from a bunch of markdown articles and a theme, there's not a lot of things to package in the first place :)
A webserver for the container age
A static blog obviously needs to be served by a webserver.
Packaging a "full" traditional webserver like apache2 (what I used before) or nginx is a little outside the scope of what I would have liked to do with my spare time, so I looked around for another way to serve it.
- A static files webserver.
- Able to set headers for cache control and HSTS.
- Ideally self-contained / statically linked (because snapping the whole would be much faster/easier this way)
- SSL ready. I've had an A+ rating on SSLlabs for years and intend to keep it that way.
- Easy to configure.
A little bit of snapcraft magic
Of course, a little bit of code was needed in the snapcraft recipe to make it all happen.
Simply copying the Caddyfile and the snap/ subfolder to your existing pelican project should be all you need to get going, then run the following to get a snap package:
# On an Ubuntu system. snap install snapcraft snapcraft
With your site's FQDN added to the Caddyfile and pushed to production, you can marvel at all the code and configuration you did not have to write to get an A+ rating with SSLlabs :)
As usual, feel free to reach out with any question or comment you may have!