Jekyll Deployments with Fabric

An Introduction to Deploying Jekyll Sites with Fabric

I put together a quick fabric script yesterday to deploy this site after growing tired of manually building it and SFTP'ing it over.

An alternative method which I've used in the past would be to setup a Git repo on the server and have a post-recieve hook which builds the site and copies it over, allowing me to deploy via Git push. However, I didn't want to install Ruby on the server if it would only be used for building Jekyll sites.

 1 from fabric.api import *
 3 env.user = 'user'
 4 env.hosts = ['host']
 6 domain = ''
 7 subdom = 'www'
 9 def push():
10     local('jekyll build')
11     local('zip -r _site _site')
12     run('rm -f /srv/%s/' % (domain))
13     run('rm -rf /srv/%s/_site' % (domain))
14     put('', '/srv/%s/' % (domain))
15     run('unzip /srv/%s/ -d /srv/%s' % (domain, domain))
16     run('rm -rf /srv/%s/%s' % (domain, subdom))
17     run('mv /srv/%s/_site /srv/%s/%s' % (domain, domain, subdom))

When you run $ fab push the script

  1. Builds the site
  2. Zips it as
  3. Removes from the server if it exists
  4. Removes _site/ from the server if it exists
  5. Copies to the server
  6. Unzips to _site/
  7. Removes the previous site www/ and replaces it with _site/

As far as I'm concerned, this is just a temporary measure - I plan to replace this with Ansible or Salt Stack when I get some time, but deploying via fabric till then is pretty nice. I also plan to slowly move my other static sites to Jekyll, allowing me to use my deployment script(s) with as many of my static sites as possible.

Published on 06 February 2014.