Hosting a static blog using Google Cloud

Until recently, my first experiments with generating static blog site using Hugo were hosted on Servage. Since I grew incrementally disenchanted with them, and I wanted to experiment with Google Cloud anyway, I decided to see what it takes to host the site.

The basic outline I started with is described in a Cloud Storage tutorial by Google:

It was all pretty straightforward. I ended up with four forwarding rules, two for HTTP and HTTPS for IPv4 and IPv6 each.

A small shell.nix fragment and .envrc:

% cat shell.nix
{ nixpkgs ? import <nixpkgs> {} }:
with nixpkgs;
mkShell {
  buildInputs = [ hugo google-cloud-sdk ];
  shellHook = ''
    # usually link in a nix-built vendor directory or other housekeeping
  '';
}
% cat .envrc
use nix

followed by direnv allow provide the necessary components. To prepare for uploading the site, I have to log in.

 % gcloud auth login

followed by

 % gcloud config set project ${PROJECT_ID}
Updated property [core/project].

to set the project. Next, I made sure the rendered version of the site was up-to-date and pushed the result:

 % hugo
 % gsutil rsync -R public/. gs://gerd-flaig-blog.

Here’s an overview of the serving configuration I ended up using:

 % gcloud compute forwarding-rules list
NAME                       REGION  IP_ADDRESS          IP_PROTOCOL  TARGET
blog-lb-forwarding-rule            34.98.111.55        TCP          blog-lb-target-proxy
blog-lb-forwarding-rule-2          34.98.111.55        TCP          blog-lb-target-proxy-2
blog-lb-forwarding-rule-3          2600:1901:0:d322::  TCP          blog-lb-target-proxy-3
blog-lb-forwarding-rule-4          2600:1901:0:d322::  TCP          blog-lb-target-proxy-4
 % gcloud compute target-https-proxies list
NAME                    SSL_CERTIFICATES  URL_MAP
blog-lb-target-proxy    blog-ssl          blog-lb
blog-lb-target-proxy-3  blog-ssl          blog-lb
 % gcloud compute target-http-proxies list
NAME                    URL_MAP
blog-lb-target-proxy-2  blog-lb
blog-lb-target-proxy-4  blog-lb
 % gcloud compute url-maps list
NAME     DEFAULT_SERVICE
blog-lb  backendBuckets/gcs-blog
 % gcloud compute backend-buckets list
NAME      GCS_BUCKET_NAME  ENABLE_CDN
gcs-blog  gerd-flaig-blog  True
 % gsutil ls
gs://gerd-flaig-blog/

Of course, this makes me wonder if there’s a declarative approach to GCE resources. I know there’s NixOps for VMs, but what about configuring load balancers, proxies and storage buckets?