14 Aug 2011

Deploying a Jekyll Site to Amazon S3

Before moving my blog to Amazon S3 I wanted to make sure that I could deploy updates easily. I came across several ways to do it. The easiest method I found was in a blog post by Hendrik Volkmer. It uses a command line tool called s3cmd run through a rake task. s3cmd can be installed using Homebrew on Mac OS X.

 brew install s3cmd

I updated the rake task to use S3's reduced redundancy storage and set an Expires header for my images by using s3cmd's --reduced-redundancy, --exclude, and --add-header options. You can find out about other s3smd options on the s3tools website.

  # based on http://blog.hendrikvolkmer.de/2011/02/25/moving-from-wordpress-on-a-vps-to-jekyll-and-amazon-s3/
  task :default => :deploy

  desc "Deploy to S3"
  task :deploy do
    sh "jekyll"
    sh "s3cmd sync --reduced-redundancy --exclude 'images/*' _site/* s3://www.heathanderson.net"
    sh "s3cmd sync --reduced-redundancy --add-header 'Expires: Thu, 6 Feb 2020 00:00:00 GMT' _site/images/* s3://www.heathanderson.net/images/"

After placing the above in a rakefile all I have to do is run the following to publish a new post or deploy any other changes:

 rake deploy