kriwil

aldiantoro nugroho. @kriwil. indonesia. part-time programmer. full-time dreamer. swift. elm. linux. ubuntu. python. django. vim. indiana pacers. manchester united. random.

  1. Auto-publish pelican blog to S3 using CircleCI

    While having blog powered by pelican is great (because it's fast), creating new post isn't really fun. There are more than one step to do it:

    1. writing the actual post
    2. upload to the server (in this case, S3)

    If you're on new machine, it's even more painful:

    1. clone the repository
    2. install pelican's requirements
    3. setup S3 credential
    4. write the actual post
    5. upload to the server

    CircleCi has given free tier for a while now. So I figured, since I'm using github for my blog content, I could use it's free continous integration & delivery service to publish my blog easily.

    I found a blog post that gives instruction to do that, but apparently it doesn't work. s3cmd couldn't get the access key ID and secret access key I set. Since CircleCi has awscli preinstalled, it's better to use that one instead. Pelican doesn't support awscli yet, so there's some steps need to be done to use that.

    1. update your Makefile to use awscli instead
    2. insert your AWS S3 access key ID, and secret key ID
    3. create circle.yml in your repository

    Here's how the circle.yml should be:

    dependencies:
      override:
        - pip install -r requirements.txt
        - echo -e "[default] \naccess_key = $S3CFG_ACCESS_KEY \nsecret_key = $S3CFG_SECRET_KEY \n" > /home/ubuntu/.s3cfg
    
    test:
      override:
        - echo "test"
    
    deployment:
      aws:
        branch: master
        commands:
          - make html
          - make s3_upload
    

    Now, everytime you push your commits to master, CircleCI will deploy them to S3. You should be able to see the deployment progress on you CircleCI dashboard.

    You don't need to create special environment to install pelican etc, just git and text-editor. You could even use github's feature to create blog post directly inside your browser (I wrote this using that!).

    new post via github

    — 20161128 – aldi —