Revamping this site

Shortly after creating this site I quickly pivoted to working with other tech outside of work and mostly forgot about it. I definitely missed a few good opportunities for blog posts about the topics I was pursuing. Nevertheless I figured it was time to get this site up again.

Surprisingly not much has changed with Hugo, the static site generator I used. A few config updates and a theme update and I was back underway.

On the other hand a lot has changed regarding the deployment side from 2021 to 2026. I originally had access to a k8s cluster that I deployed this to, unfortunately that project isn’t in service anymore. While it’d be fun setting up another cluster I don’t think I can justify it just to host a tiny ~25MB static website.

A simply approach using s3 and cloudfront while suffice. Apparently AWS Amplify is a “recommended” tool for this use case but comes with a higher price tag and more features that are un-needed.

Terraform made a questionable decision regarding licensing and subsequently handled the response to that quite poorly. So we’ll be using OpenTofu, an open-source fork of terraform for our infra needs.

In short, the important bits are:

resource "aws_s3_bucket" "site" {
  bucket = var.bucket_name

  tags = {
    Name = var.bucket_name
  }

...

extra resources to control the s3 bucket
...

resource "aws_cloudfront_distribution" "site" {
  enabled             = true
  ...
  default_root_object = "index.html"
  ...

  origin {
    domain_name              = aws_s3_bucket.site.bucket_regional_domain_name
    origin_id                = "s3-${aws_s3_bucket.site.id}"
    origin_access_control_id = aws_cloudfront_origin_access_control.site.id
  }

...

various resources related to CDN controls
...

}

This deploys all the required resources on the AWS side.

Now lets setup some automation to build and deploy my site when I make changes.

One thing that’s changed in the last 5 years is the unfortunate fall of github. Which was almost inevitable given Microsoft’s purchase of it in 2018. Anyways Gitlab has been a reliable alternative for years and their CI/CD offering is pretty good.

stages:
  - build
  - deploy

# only run when changes are made to site/
workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH'
      changes:
        - site/**/*
    - when: never
...
...

build:
  stage: build
  ...
  script:
    - hugo --source site --destination "${CI_PROJECT_DIR}/public" --gc --minify
  artifacts:
    expire_in: 1 week
    paths:
      - public/

deploy:
  stage: deploy
  ...
  script:
    - SITE_DIR=public ./deploy.sh
  environment:
    name: production
    url: https://cbull.dev
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'

This builds my hugo site and exports it as an artifact, which the deploy job will upload to s3 then create an invalidation on the CDN.

Additionally I created a scheduled job in the Gitlab UI to run this once a week. While for this context it’s likely overkill, but it’s somewhat good practice to not let things get too stale if you’re working with external packages.

I also had to transfer my domain from squarespace to Route 53. Which was the unfortunate result of google getting rid of google domains and transferring all domains to squarespace.