The objective of this project is to build a technology blog website, satisfying the following requirements:
x.wordpress.com
sites. This blog needs to work with any domain
name.This project includes, or will include, the following posts. If any aren't finished, check back later!
Date | Article |
---|---|
2019-08-01 | Building a Pelican Docker image |
2019-08-03 | Writing blog content for Pelican |
2019-08-04 | A simple Pelican development environment |
2019-08-05 | Saving Docker images in Google's Container Registry |
2019-08-06 | Google Cloud Build with GitHub Trigger |
2019-08-09 | Hosting a website using Google Cloud Storage |
2019-12-02 | Using Cloudflare to provide HTTPS |
At a high level, with this setup you just write your content and push it to git. The rest takes care of itself.
Here's how it works:
Before Pelican can render the markdown files into a site worth looking at, it needs a theme to work with.
The easiest way to go is to select a pre-made theme.
Personally, I forked a theme then heavily modified it. Forking the theme prevents it from changing, and lets you change things as needed. I'd suggest creating a fork of the theme even if you won't change it.
Next, the pelican software needs to be containerized for Cloud Build to use it. You can either grab an existing image, such as the one I've shared on Docker Hub, or build your own.
How to build a Docker image for Pelican
The Pelican image needs to be in the Google Container Registry for Cloud Build to use it. GCR is like Docker Hub, but private and not free. It's pretty affordable.
Google Storage's website hosting feature is great, but it has a cache that I haven't yet figured out how to bypass. This means that if you push a mistake to the storage, then push a fix, the fix may not display for like an hour.
To get past this, using a local service for development is a nice solution. Also, this way you're not testing your code in production.
You can see the utility script I made here,
but basically you just run a local Pelican image, then run pelican
against
your content files with --listen
and --autoreload
.
Pelican Website: Local Development Environment
Google Cloud Build is the automation framework used to watch for changes committed to github, then transform the content files into a website and save them to Google Cloud Storage.
Configure Cloud Build to watch for commits to the master branch of the blog content repository, then run the pelican and rsync jobs against it.
Google Cloud Build: Automatically Deploy Changes from GitHub
At this point, you've written your content, converted it into web files, and synchronized those files with Google Cloud Storage. To make the website accessible, you need to configure Google Cloud Storage to host the content as a website. This step is also where you point your custom domain name at the new site.
Google Cloud Storage: Static Website Hosting
These days there's really no good excuse to not have HTTPS on your site. On a self-hosted site I usually use LetsEncrypt, but for this static site instead I've used the built-in HTTPS feature of CloudFlare's free CDN solution.