When Pelican met CircleCi

Posted by Henry Cook on Wed 09 March 2016

As with most of my projects, the more and more I play with them, the harder I find to put them down.

In this case, having successfully set up a Static site (this blog) via Pelican and gotten to grips with the deployment to S3 via a Makefile. I then decided...how can I automate this. CI/CD (in all of it's various forms) isn't particularly new however, I didn't have anything in place and like hell was I going to host anything myself in this age of 'cloud computing'. After looking around and speaking to my various talented friends and colleagues, I decided to go with CircleCi.


CircleCi will meet all your CI and CD needs via the use of containers and the best part, I'm not hosting any of it! For my level of use it's completely free and this abstracted the maintenance of the CI/CD system away, so I can concentrate on other things.

Via CircleCi I was able to link it with my GitHub and in turn setup a webhook for the the repo my pelican setup was in. Each time I commit and push my changes to GitHub, CircleCi sees this and kicks off a build.

So far so good, only problem is that my build was failing. Bummer. The reason was because I hadn't included a circle.yml which specifies all the various bits of magic that's done during the build process. As of writing, here's my circle.yaml:

    - pip install pelican markdown s3cmd
    - git clone https://github.com/gilsondev/pelican-clean-blog.git && pelican-themes --install pelican-clean-blog
    - echo -e "[default] \naccess_key = $S3CFG_ACCESS_KEY \nsecret_key = $S3CFG_SECRET_KEY \n" > /home/ubuntu/.s3cfg

    branch: master
      - make html
      - make s3_upload

While it's a little sparse, let me run through what each bit does.


dependencies: sets up your project's language-specific dependencies, so for example, pip installs pelican for the actual site generation, markdown for the language it's all written in and s3cmd to deploy to the S3 bucket.

pip install pelican markdown s3cmd

Next we will need the custom theme I have set in my pelicanconf.py by cloning it and then installing it via pelican-themes.

git clone https://github.com/gilsondev/pelican-clean-blog.git && pelican-themes --install pelican-clean-blog

Then create the .s3cfg file to store the credentials for s3cmd and utilise enviroment variables for storing the key and secret.

echo -e "[default] \naccess_key = $S3CFG_ACCESS_KEY \nsecret_key = $S3CFG_SECRET_KEY \n" > /home/ubuntu/.s3cfg

CircleCi gives you the ability to upload your AWS keys for any application/library that utilises .aws/credentials, as well as setting environment variables via the project settings.

One thing worth noting is that the user associated with the key and secret will need access to the bucket you are uploading data to. I know that sounds obvious, but double check your access policy reflects that.


deployment: Is used to actually deploy the code. branch gives you the ability to specify what happens to each branch in terms of deployment.

Here is where the html pages are generated.

make html

Lastly the site can then be deployed to S3 via the Makefile.

make s3_upload


My next step is to write some tests for CircleCi, so I know when the deploys go completely arse over tit.

Having never done this before I'm actually really looking forward to it.


Now I have my deployment workflow all streamlined in a very tidy fashion which has made it dead simple to make changes wherever I am. No need for a funky dev environment. Just Git and some form of text editor.

  1. Clone/Pull Git Repo
  2. Make Changes
  3. Commit and push

That's literally all I have to do as CircleCi does the rest!