How I Made This Blog (And Not So Much Why)
Background
I have made blogs in the past, mostly using Wordpress. I thought about using Wordpress again, as GCP has an out-of-the-box deployment in the Marketplace, but that requires a few things:
- GCP compute instance running to host the blog
- SSL certificate to make your site look very professional
The problem is these things costs money, and I don’t plan on making any money from this blog, so any cost comes out of my Steam gaming fund. On top of that, Wordpress takes some effort to manage and maintain. You need to make sure your configuration is secure to prevent unwanted users from accessing your blog, and you have to regularly update the software with the latest security patches. I just wanted to make a simple, clean blog where I could share information.
The blog software
After some digging, I found a few options for generating static websites. I decided to go with Hugo since it seemed fairly popular and had a lot of resources to refer to when building a site. I won’t go into the detail on how to use Hugo, as I’m a novice myself, and there are lots of resources already.
The hosting platform
So if I wasn’t going to use a GCP compute instance to host my site, how else could I do it? There are lots of cheap hosting platforms out there, but I wanted to have (mostly) complete control over the platform. That’s when I found out you can host websites directly on Google Cloud Storage.
I wanted to have an SSL certificate, but I did not want to pay for a GCP load balancer and an SSL certificate. What to do?
The SSL dilemma
Enter Cloudflare. Cloudflare is a popular CDN (content delivery network). GCP also has a CDN, but I chose Cloudflare as it has a free tier that includes an SSL certificate! The catch is the cert is only valid between Cloudflare and the end user, and not your site and the end user, but I didn’t really care, I just wanted that sweet, sweet SSL certificate. Cloud Storage uses an SSL certificate when accessing anything in the buckets anyway.
Behind the curtain
Since this is a static website, there is a manual process to publish content. (I will likely try to automate this in the future, just for fun) Keeping in line with the “cheap or free” mindset, I use the free GCP Cloud Shell to do the work of updating the site. Cloud Shell is a free virtual Linux instance that lets you interace with your GCP resources with built-in tools like gsutil
. It also has a bit of storage to use, and best of all, it’s free.
Without going into the intricacies, here are the basic steps for using Hugo to generate a static site:
- Use Hugo to create the initial site directory
- Pick a theme and copy it to this directory in the themes folder
- Create content with markdown files (such as this post)
- Run Hugo to generate an HTML site from the Hugo configuration and markdown content
- Copy this site to your webhost
Pretty manual, eh? While thinking of ways to simplify this process, I decided to just keep using Cloud Storage. The problem with this is Hugo cannot operate against Google Storage buckets, so I wondered if I could mount a Cloud Storage bucket to a Linux machine. The answer is yes, you can, with gcsfuse
. And to make it even easier, Cloud Shell already has access to your buckets and has gcsfuse
already installed. It’s as simple as:
gcsfuse someUniqueBucketName /linux/mount/point/someUniqueBucketName
Because I was logged into my Cloud Shell, I already had the required permissions to access the bucket. You do not need to specifiy gs:// for gcsfuse
to work, it assumes the first parameter is the bucket.
I created my site with Hugo thusly:
hugo new site /linux/mount/point/someUniqueBucketName
Once, after several hours, you have your site configured the way you want it, you just run the hugo
command inside the directory and it will generate a folder called public
where it creates the HTML based website. Now you need to copy the files to your webhost. Since my webhost is Cloud Storage, this was very easy, I just used gsutil
:
gsutil -m rsync -r public/ gs://hypervsior.buzz
The -m
option here attempts to parallelize the file copy, and -r
tells rysnc to recurse into the the directory. The beauty of rysnc
is it only copies new files and files that have changed, so you don’t have to copy your entire site every time.
FIN
That’s it. That’s the post. Hit me up on Twitter if anything looks funny.