Gitlab Runner + Hugo + S3

September 27, 2020

Recently, I found that the previous Docker image to build this site no longer worked with Hugo version 74(ish). I am not exactly sure when this broke since I took a hiatus from blogging. Here is the updated pipeline in Gitlab.

variables:
  S3_BUCKET_NAME_PROD: 'blog.loganwedwards.com'
  CLOUDFRONT_DISTRIBUTION_PROD: 'XXXXXXXXXXXX'
stages:
  - build
  - deploy

build-site:
  # Considered the defacto
  # https://gohugo.io/getting-started/installing/#docker
  image:
    name: klakegg/hugo:ext-alpine
    entrypoint: [''] # Fixes the gitlab pipeline error
  stage: build
  script:
    - hugo
  artifacts:
    paths:
      - public/

deploy-site-production:
  image: python:latest
  stage: deploy
  environment: production
  script:
    - pip install awscli
    - aws s3 cp ./public s3://$S3_BUCKET_NAME_PROD/ --recursive  --include "*"
    - aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_PROD --paths "/*" # Ensures latest changes are immediately live
  only:
    - master