Hosting a Jekyll Site on Heroku

Avoid pulling your hair out like I did.

This post is part of a series on hosting Jekyll with Heroku.


I love using Jekyll. I use it for this blog, my personal site, and it’s the first thing I suggest when people want something with content that needs to be updated. However, deploying gets complicated when you’re using a variety of plugins and you don’t want to host with GitHub Pages.

I had setup Deploy to do this automatically when new commits were pushed to the master branch. But I wanted something better; something that didn’t feel like so much of a hack. I was having to compile the whole site locally, and sometimes I’d forget to use the right config file, so things would break and I’d have to scramble to fix quickly.

One day, the lightbulb when off, and I started to wonder if I could use Heroku to host my Jekyll sites. After doing some calculations, I felt like I could improve the deploy workflow, and save a little money.

So how the heck do you do it?

Well, it was a bigger pain in the butt to figure out than I thought, but once you understand the pieces, it actually is pretty simple. Unfortunately, most of the articles that walk you through this process were published a while ago, so they were using out-of-date gems, and deprecated commands.1 But by combining the process of this article and this article, you find yourself with a great solution. Hopefully you’ll find this useful.

Ignore the Site Folder

First things first, you’ll want to ignore your _site folder. You’ll be building the site on the server now, so there’s no need for these files to be cluttering up your repo. In your .gitignore add the following line:

# .gitignore
_site

Exclude Vendor in _config.yml

You’ll also want to exclude vendor in your _config.yml file. This folder is generated by Heroku I believe. I didn’t actually test why this needs to be done, but I did it.

# _config.yml
excluded: ['vendor']

Add Gemfile

If you don’t have one already, you’ll want to create a Gemfile.2 I recommend you visit RubyGems.org for the latest versions of these gems.

# Gemfile
source "https://rubygems.org"
gem 'foreman'
gem 'jekyll'
gem 'rack-contrib'
gem 'rake'
gem 'thin'

Once you’ve got these gems in your Gemfile, run bundle install and make sure your Gemfile.lock is checked into your repo. The build process will fail without the Gemfile.lock.

Add Procfile

Next, add a Procfile. We’ll be using thin to serve up our site. You do that with the following lines:

# Procfile
web: bundle exec thin start -p $PORT -V
console: echo console
rake: echo rake

Add Rakefile

We need to tell Heroku to build our site, and we’ll do that by attaching a command to the rake assets:precompile task that Heroku runs. Create a Rakefile, and add these lines:

# Rakefile
namespace :assets do
  task :precompile do
    puts `bundle exec jekyll build`
  end
end

Add config.ru

Now, we need to tell Rack how to serve up our files. We want it to do this statically so we’ll add a config.ru file and add the following lines:

# config.ru
require 'rack/contrib/try_static'

use Rack::TryStatic,
  :root => "_site",
  :urls => %w[/],
  :try => ['.html', 'index.html', '/index.html']

run lambda { |env|
  return [404, {'Content-Type' => 'text/html'}, ['Not Found']]
}

Lastly, make sure you’re using relative URLs for assets. I ran into a javascript error for calling jQuery over an insecure connection. Which meant changing the line.3

<!-- You'll change a line like this -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<!-- To this -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

That’s it! Now just push your repo to Heroku, and it’ll build the site and serve it. If you’d like to dig through the repo for this site, it’s on GitHub.

  1. Not to mention, it was difficult to find a pattern of how people do this. You’ll usually do research on something like this and all the blog posts will point you to the same steps. Not here. There were like four different ways, some that seemed simple, and others that were quite complex and required knowledge of routes in Sinatra. Craziness. 

  2. You can do this by going into your terminal, cd into the directory of your Jekyll site, and type bundle init. You’ll need to have the bundler gem to do this, so if you don’t have that, type gem install bundler into your terminal to install. 

  3. I add this information because my JS wasn’t working and I spent like 20 minutes just scratching my head as to why. Opened the console, and found the issue immediately. Should’ve done that in the first place. 

Instacast Discontinued as Vemedio Runs out of Money

Benjamin Mayo reporting for 9to5Mac:

Popular podcasting app Instacast for iOS and Mac is shutting down as the founders can no longer fund it or any of Vemedio’s other projects.

Hering seems to imply that profitability issues are the cause as the email plainly states “I ran out of funds to keep the project going”. The company’s Twitter account is now private and vemedio.com now redirects to a simple ‘Discontinued’ page.

I’ve been using Instacast for as long as I can remember.1 It’s sad to see it go, but “running out of money” is a real thing, and I can identify with that. Instacast was my favorite due to their sync to a Mac App which—contrary to what is popular—is essential to me. I love listening to shows on the Mac, and I don’t feel that listening to podcasts while I work distracts me.

With Instacast out, I’ll be using Pocket Casts. They have exceptional sync, and their design is great. They’re coming out with Apple Watch support soon, which I’m really looking forward to since I recently ordered one.2

  1. I tried looking up when the app came out, but all the Vemedio pages point to a discontinued page. I want to say I’ve been using Instacast since 2010. 

  2. I’m so excited! I ordered a Apple Watch Sport 42mm Space Gray with Black Sport Band. I’m also interested in getting one of these

New Beginnings

For the past two years, I’ve run my own business, Anythin’ Goes. I’ve been so incredibly happy to work on some awesome projects with great people. On Monday, I begin a new chapter.

As some of you know, I’m getting married to my best friend in May. Since December, I’d been looking for a great company to join. Looking for a job is a difficult process. You end up reading a lot of job descriptions; some are written well, others are really not.

Two weeks ago, I interviewed with Matt Crest. The first interview went really well. On the second interview, I was convinced. I really wanted this job. I was excited about the work, and I felt I fit with the team.

Monday, March 30th, is my first day at Artletic. I’m so excited about this opportunity. I’ll be able to use my skills to help the team, but I know there will be much for me to learn from this great group of people.

I’ve interviewed with a lot of companies in the past four months, and I thank them all for chatting with me. I also want to thank all of you who made intros for me, hired me in the last two years, and who sent me job listings you thought I’d be great for. That type of generosity can never be fully repaid, but I promise to try my best.

I want to give a special shoutout to Matthew Kammerer, Jory Raphael, Nicole Dominguez, Chris Kennedy, Jonathan Cutrell, John Locke, Myke Hurley, and Bermon Painter. If it weren’t for you, there would’ve been months that I wouldn’t have been able to pay my rent. You didn’t know it, but your help was monumental, and I thank you.

Now, on to new beginnings.

Andrew Wilkinson on Building a Lifestyle Business

Andrew Wilkinson talks about being In-N-Out Burger instead of becoming McDonalds. It’s quite encouraging to read something like this from someone who’s had so much success in our industry. Here’s my favorite part of the article:

Meanwhile, there are thousands of internet businesses out there, quietly making tens, and even hundreds of millions of dollars, who have taken the same path as In-N-Out. They don’t need to be first, second, or even tenth, in their space, and have instead chosen to focus on a small percent of a massive market. They answer to customers, not investors, and focus on making their employees, customers, and themselves happy.

‘On Productivity’

Brian Krogsgard:

I should admit something: I have almost no such hacks and I do not focus heavily on my processes and how to streamline them.

Now, I do think I’m a fairly productive person. I get a lot done during the day. Since I started my own business, I tend to balance the day with research, writing (which is what pays bills, if you will), customer support, site maintenance, and development.

I love this post by Brian. We can get caught up in all of these things that you “should be doing to be productive” instead of doing what works for you.

The Verge Reviews Big Sean’s Latest Album

It’s the little things, the avoidable mistakes, that stand out on Dark Sky Paradise. It’s a great album, but it could have been a classic. It has all the ingredients; a capable artist, excellent production, a clear theme and direction, and the potential for multiple hits. This is the album that is supposed to propel Big Sean into the upper echelon of rap. He’s closer, but Dark Sky Paradise won’t get Big Sean a seat at the table. (Kanye, Drake, Jay Z, and Kendrick Lamar are sitting at the table. Sorry, but this is not up for debate. Your argument will not be accepted.) Big Sean is definitely on his way. He just still has some work to do.

A surprisingly great review of Dark Sky Paradise.

‘Deploy a Password Protected Jekyll Site on Heroku with Dropbox’

Dave Rupert:

At Paravel, we frequently run into issues where we need to share password protected sites with clients. We could setup some complicated post-commit hook/Capistrano system, or pin ourselves to a certain SaaS provider, but none of those have sat well with us and seem overly complicated.

We need a workflow that is flexible, almost disposable, and could even show a different “experimental” branch at a whim. We’ve come across something relatively simple that uses Dropbox to sync a Jekyll site to Heroku.

Such a good idea! Thanks Uncle Dave!

Post Status Reviews Layers by Obox

Brian Krogsgard:

I am definitely not on the bandwagon for page builders, though it seems the WordPress product world is. Where traditional options heavy theme sales have died away, page builders have risen from their ashes.[…]

I’m afraid, however, that end user “demand” may make it so whether I like it or not; but it won’t be for their own good. I think there is a better way. I think “page building”, as it seems we’ve standardized the term, is broken when too many granular design elements are allowed. Instead, I’d like to see content building, where structured content can be created with a tool, but theming and styles are still left to, well, themes.

Lots of things I wanted to quote here, but just go read this. Brian, as per usual, gives excellent insights.