Mike Kasberg

Husband. Father. Software engineer. Ubuntu Linux user.

Image for Automated Jekyll Deployments

Automated Jekyll Deployments

08 Nov 2016

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.

About the Author

Mike Kasberg

👋 Hi, I'm Mike! I'm a husband, I'm a father, and I'm a senior software engineer at Strava. I use Ubuntu Linux daily at work and at home. And I enjoy writing about Linux, open source, programming, 3D printing, tech, and other random topics. I'd love to have you follow me on X or LinkedIn to show your support and see when I write new content!

Share!

If you enjoyed this blog post, I'd love it if you could share it with your network!

I run this blog in my spare time. There's no need to pay to access any of the content on this site, but if you find my content useful and would like to show your support, buying me a coffee is a small gesture to let me know what you like and encourage me to write more great content!

You can also support me by visiting LinuxLaptopPrices.com, a website I run as a side project.