DEV Community

Cover image for A Blogging Platform
John Doyle
John Doyle

Posted on • Originally published at

A Blogging Platform

Well, this isn't the first time I've used Hugo, but each time I go to look for a nice blogging platform, I keep returning to its simplicity. While I miss some of the plugins that you get out of the box with WordPress etc, I find Hugo a lot easier to customize.

Super fast summary would be that you write your posts in Markdown and Hugo
transforms this into a static website. Being a static website, you can simply throw it up onto AWS S3 to host it. Maybe do a little magic with AWS CloudFront if you want!

This time around also gave me a chance to play with GitHub Actions. I've tended to keep build internal to AWS to manage everything via permissions, though the heavy lifting of setting up an AWS CodePipeline to execute the AWS CodeBuild buildspec just to generate the HTML and sync it with S3, feels like it could be simpler - to match Hugo!

So took my old buildspec:

version: 0.1

      - curl -Ls -o /tmp/hugo.tar.gz
      - tar xf /tmp/hugo.tar.gz -C /tmp
      - /tmp/hugo
      - aws s3 sync --delete --acl public-read public s3://s3-bucket-name
Enter fullscreen mode Exit fullscreen mode

and used the Hugo deploy feature with GitHub Actions that I found on MonkeyPatch's site:

name: Build and Deploy

on: push

    name: Build and Deploy
    runs-on: ubuntu-latest
      - uses: actions/checkout@v1
      - name: Install Hugo
        run: |
          tar xvzf ${HUGO_DOWNLOAD} hugo
          mv hugo $HOME/hugo
          HUGO_VERSION: 0.59.1
      - name: Hugo Build
        run: cd $GITHUB_WORKSPACE/website && $HOME/hugo -v
      - name: Deploy to S3
        if: github.ref == 'refs/heads/master'
        run: cd $GITHUB_WORKSPACE/website && $HOME/hugo -v deploy --maxDeletes -1
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Enter fullscreen mode Exit fullscreen mode

This now allowed my to embed the configuration of the upload into Hugo's own config file:

order = [".png$", ".jpg$", ".gif$", ".svg$"]

URL = "s3://s3-bucket-name?region=region-name"

# Cache static assets for 20 years.
pattern = "^.+\\.(js|css|png|jpg|gif|svg|ttf)$"
cacheControl = "max-age=630720000, no-transform, public"
gzip = true

pattern = "^.+\\.(html|xml|json)$"
gzip = true
Enter fullscreen mode Exit fullscreen mode

This is obviously the most basic use of GitHub Actions, a one step pipeline with no artifacts etc generated. Looking at the
monthly cost side, I guess AWS would be $1 for the CodePipeline, and with the CodeBuild taking under 1 minute that would be $0.005 per update. GitHub Actions is billed out by the minute, with the first 2000 minutes free. After that its $4 for an extra 1000 updates. So if we max out at 2000 updates... hahaha... it would cost me $11 on the AWS, and still free on GitHub Actions.

I'll be curious how this scales with more complex and longer running pipelines.

Top comments (0)