Giter Site home page Giter Site logo

hugo-gcp-deploy's Introduction

Hugo Static Site Running on GCP Free Tier VM

This project is to create a site with Hugo and deploy it to GCP in < 5min.

Accompanying Blog Posts:

  1. The Making of devopsdirective.com (Hugo, Caddy, + GCP)
  2. 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.

Prerequisites

  • Install hugo (brew install hugo)
  • Install docker (brew cask install docker)
  • Install google cloud sdk (brew cask install google-cloud-sdk && gcloud init)

Site Setup Instructions

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. [email protected])

to their appropriate values.

  1. Run $make create-site (uses https://gohugo.io/getting-started/quick-start/)
    • Creates the hugo site and moves it into this directory
  2. Run $make create-project
    • Creates a new GCP project
  3. enable billing using the project link output by previous command
  4. Run $make vm-setup
    • Enables compute.googleapis.com and containerregistry.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
  5. 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
  6. 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

CI/CD Setup Instructions

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.

  1. Mirror GitHub repo in Cloud Source (https://cloud.google.com/source-repositories/docs/mirroring-a-github-repository) -- assuming primary site repo is in GitHub
  2. 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

TODO:

  • Tune caddy config
  • Add CDN (eventually)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.