This project is to create a site with Hugo and deploy it to GCP in < 5min.
Accompanying Blog Posts:
- The Making of devopsdirective.com (Hugo, Caddy, + GCP)
- CI/CD for devopsdirective.com (Hugo + Cloud Build)
NOTE: For a static site like this, the built in hugo deploy
approach to host directly within a GCP/AWS/Azure bucket might be easier/more scalable, but I wanted to familiarize myself with various server options (first I used nginx, and then switched to caddy b/c of its automatic https config!) and eventually want to do some benchmarking on the f1-micro instance to see what kind of load it can handle.
- Install hugo (
brew install hugo
) - Install docker (
brew cask install docker
) - Install google cloud sdk (
brew cask install google-cloud-sdk && gcloud init
)
Before starting, update the following:
<SITE_NAME> (within ./Makefile, e.g. my-website)
<DOMAIN(S)> (within ./Caddyfile, e.g. my-website.com www.my-website.com)
<EMAIL_ADDRESS> (within ./Caddyfile, e.g. my.name@gmail.com)
to their appropriate values.
- Run
$make create-site
(uses https://gohugo.io/getting-started/quick-start/)- Creates the hugo site and moves it into this directory
- Run
$make create-project
- Creates a new GCP project
- enable billing using the project link output by previous command
- Run
$make vm-setup
- Enables
compute.googleapis.com
andcontainerregistry.googleapis.com
- Reserves a static IP for the site
- Adds http and https firewall rules
- Creates f1-micro vm,
- Configures your local docker install to use google container registry (gcr)
- Configures VM docker install to be able to use google container registry
- Enables
- Run
$make deploy
- Builds hugo site
- Builds caddy based docker container containing site files
- Tags and pushes to gcr
- Removes currently running containers on VM
- Starts container on VM using new container image
- Run
$make list-vms
--> create A record for domain (not automated)- Go to your DNS provider and point your domain to the VM static IP
- It's also useful to add a www CNAME record (to automatiaclly point requests like www.my-website.com to my-website.com)
- You also need to update the Caddyfile to reflect your domain and enable TLS
Before starting, update the following:
<SITE_NAME> (within ./Makefile, e.g. my-website)
<REPO_NAME> (within ./Makefile, e.g. my-cloud-source-repo-mirroring-a-github-repo)
<USER_NAME> (within ./Makefile, e.g. myusername -- this shoud be the username of the user when you SSH into the VM)
to their appropriate values.
- Mirror GitHub repo in Cloud Source (https://cloud.google.com/source-repositories/docs/mirroring-a-github-repository) -- assuming primary site repo is in GitHub
- Run `make setup-cloud-build
- Enables the Cloud Build API
- Adds the necessary IAM roles to the Cloud Build service account
- Creates the Cloud build Trigger
- Tune caddy config
- Add CDN (eventually)