Hosting a Hakyll website on AWS S3 with circleci for continuous delivery

Posted on January 2, 2019

This site uses the static site generator Hakyll. Hakyll is a bit of an unusual choice here (note to self: future blog post) which means that static site generator services like Netlify won’t run the generation process for me. They can host the pages, but I’d have to run the script which generates the HTML myself.

This is fine on my own computer, but I’d like to be able to add posts from places or machines where I don’t have Hakyll installed. I use circleci to build the site and then Amazon S3 to host the pages.

circleci will automatically run whenever a commit is made to the repository for this site and then upload the results to Amazon where people like you can see them.

Here is the circleci build script (see github for the latest version)

version: 2
      - image: fpco/stack-build
      - run: apt-get update && apt-get -qq -y install awscli
      - checkout
      - restore_cache:
          keys: stack
      - run: stack setup
      - run: stack install
      - save_cache:
          key: stack
            - .stack-work
            - ~/.stack
      - restore_cache:
          keys: site
      - run: ~/.local/bin/eanalytica-www build
      - save_cache:
          key: site
          paths: _site
      - run: aws s3 sync _site s3://com.eanalytica.www2/

It uses the fpco/stack-build docker image so that the haskell build tools are installed. The stack working directories are cached to decrease build times as is the previous version of the site - if the site was very big this would also improve the build time, but for my little blog it doesn’t make much difference. I still need to figure out how to cache the result of installing awscli on line 7.