Automated Jekyll Deployments

Automated Jekyll Deployments

Tuesday November 08, 2016
Software Development


My last post was about using Jekyll as a podcasting platform. Now, I want to talk about how I set up automatic deployments with Jekyll. I’m deploying to a Dreamhost server, but the principles I applied should work for most servers that provide ssh access.

Why?

Automatic deployment is important to me. Anything that is not automated is error-prone, and I don’t want to run that risk when deploying my website. With the podcast site I recently developed, there was an additional benefit. I wanted to be able to schedule the podcast to publish an episode at a specific time (preferably overnight), without having to interact with it during the delpoyment. This was important because we publish our podcast at a regular interval. With automated deployment, I don’t need to worry about modifying my schedule to make sure I’m free at the time we need to publish the episode.

How

The idea for this setup is pretty simple. We were already using Git for version control. To setup automated deployments, I began by simply putting a bare Git repo on our Dreamhost server. Developers can push to this repo via ssh just like any other repo.

With the Git repository on the web server itself, it is easy to write a script that builds and deploys the site from that repository. The script itself isn’t too complex. It just checks out a copy of our source, uses Jekyll to build it, and then deploys it to our public html folder. The hardest piece of all of this was getting Jekyll to run on our Dreamhost server - which we accomplished with Ruby RVM and a user install of Jekyll.

Here’s a slightly simplified version of our deployment script:

GIT_REPO=$HOME/myjekyllsite.git
TMP_GIT_CLONE=$HOME/tmp/myjekyllsite
PUBLIC_WWW=$HOME/mypodcast.com

# Check out the Git repository so we have a working copy in a temp dir.
git clone $GIT_REPO $TMP_GIT_CLONE

# Build it.
jekyll build -s $TMP_GIT_CLONE -d $TMP_GIT_CLONE/_site

# Deploy it.
cp -r $TMP_GIT_CLONE/_site/* $PUBLIC_WWW

# Clean up.
rm -rf $TMP_GIT_CLONE

echo "Done."
exit

So?

Using a script like this to deploy our Jekyll site has been great! Since the process is entirely scripted, there’s little room for error. Also, deploying the site on a regular schedule is as simple as running this script from a cron job. By default, Jekyll will not publish anything with a future date, so we can queue up as many posts as we want which will be automatically published in the future. This method of deployment has simplified our process and removed some of the risk normally associated with updates.


View more posts