Automating website build and deploy

Published on

Since I didn’t manage to write blog posts regularly enough in the last few months, I forgot how to deploy the changes to my website. Luckily I documented how to do all of the steps in my previous blog posts! I guess that is the benefit of a system like Wordpress or Drupal, where the authoring is a bit more straightforward out of the box, at the cost of the simplicity of managing patches for a static site of course…

However, since I have a Dockerfile with all the dependencies, it should be straightforward to create a simple job that is triggered when I push updates to my Git repository. It would be nice if they are pushed to a testing URL where I can quickly verify the results before running a Lambda to copy the S3 files and flush the CDN.

A quick web search turned up this solution from KBild, which made me realise that I think that a simple variant on this solution is all that is needed. There is a follow up post that shows how to gather that up as a CloudFormation template. Since the original blog post was made hugo deploy can now handle the CloudFront cache invalidation so the Python script is no longer needed.

You may even want to consider options like AWS Amplify as an even simpler option - but I am happy with S3 static sites and codebuild.

In this post I’m just going to step through the options I set using AWS CodeBuild. Hopefully I’ll follow up with a post on how I templated everything out using Terraform (an alternative) to AWS CloudFormation.

Since I’m building in Ireland the time is behind of my blog post time, which means sometimes posts aren’t built. Just add the --buildFuture flag to the hugo command in the buildspec.yml.

If you’re reading this then everything works as expected, so all that you’ll need is to see the buildspec.yml and some information on the CodeBuild settings…

You’ll also want to add an inline policy to the codebuild role so that it has permissions to publish to your s3 bucket. I started with all S3 permissions, and then removed those that I didn’t need.

Once everything is setup, you might want to consider setting up a build hook, so that a new build and deploy will happen whenever you push new code to your website github repository. That’s detailed here.