A New Home

I finally took the time to move this site to s3 instead of my previous setup with a digitalocean droplet.

Before I used my own git server, capistrano and nginx to serve and deploy the site. That approach was a bit brittle and ultimately was not as automatic as I’d like.

Here’s a quick rundown of the new deployment and hosting.

The site is now open source and hosted at Github, feel free to have a look at the code if you like. TravisCI and the gem s3_website is used for deployment to S3. Due to limitations in DNS, namely that the root @ record cannot be a CNAME I’ve used my droplet and nginx to redirect traffic to hugotunius.se to www.hugotunius.se which is a CNAME for the s3 bucket.

Code

Here are the relevant parts of the deployment code if you are interested in setting up something similar

.travis.yml

language: ruby
branches:
  only: master
script: "./_scripts/deploy.sh"
env:
  global:
    - secure: "Y8oSq4b3m6bCJOLGQf5PZCS8x078mZA3VNoHyPOMcVCi0m+Qalp+nildzv4eiKIx8zIhz3Ushf+jHAytAn3TU8hK+zdg7KYX6DoisxAehHxw0n6t0SniELixla70ckrV87FqiNFG3TCrERoOWsk2s6had0oV07IXxPFuBQQe3w0="
    - secure: "NHIh4KBJ3TK2o8K5iP5f6cfnHDu9MyHWKnEAHC3WecDbTutnWnjZSN46I3gCro9uRuMz8oLOqTU3EJxvFG/tLUlw/fk9C/88ZboKvib8SpIVX5CmEut6s9/U/sllT+Msx80bWTeRX3Q8U3bYtLeS7x+v56gGuu0YS3HC+Qkar6k="
cache: bundler

The secure fields contain the environment variables for the S3 credentials used for uploads

s3_website.yml

s3_id: <%= ENV['S3_ACCESS_ID'] %>
s3_secret: <%= ENV['S3_ACCESS_SECRET'] %>
s3_bucket: hugotunius.se
gzip:
  - .html
  - .css
  - .png
s3_reduced_redundancy: true

Rakefile

task :default => :watch


desc 'Cleanup generated files'
task :clean do
  sh 'rm -rf _site'
  compass 'clean'
end

desc 'Build the site'
task build: [:clean] do
  jekyll "build"
end

desc 'Deploy the site to s3'
task deploy: [:build] do
  s3 "push"
end

desc 'Serve the site locally and watch for changes'
task watch: [:clean] do
  jekyll "serve --watch --drafts"
end

def jekyll(command)
  with_bundler "jekyll #{command}"
end

def s3(command)
  with_bundler "s3_website #{command}"
end

def compass(command)
  with_bundler "compass #{command}"
end

def with_bundler(command)
  sh "bundle exec #{command}"
end

Finally the small script scripts/deploy.sh

#!/bin/bash
if [[ $TRAVIS_BRANCH == 'master' ]] ; then
    rake deploy
fi

glues it all together on Travis