Gollum on Heroku

1391731200

Gollum is a wiki system built in top of Git. Heroku apps are not stored in a Git directory. If you’ve tried to deploy Gollum to Heroku before, you probably have seen this error: Grit::InvalidGitRepositoryError. So what? We can make our app a valid Git repository by using Heroku’s ephemeral filesystem.

1. Add a Gemfile:

source 'https://rubygems.org'
ruby '1.9.3'
gem 'gollum', '~> 2.6.0'

2. Create your Heroku app and set the following heroku buildpack:

heroku create my-wiki
heroku buildpacks:set frederick/heroku-buildpack-ruby

3. Add your config.ru:

require 'rubygems'
require 'gollum/app'

gollum_path = '.'

# This is the key to make Gollum work on Heroku
unless File.exists? '.git'
  repo = Grit::Repo.init(gollum_path)
  repo.add('.')
  repo.commit_all('Create gollum wiki')
end

Precious::App.set(:default_markup, :markdown)
Precious::App.set(:wiki_options, { universal_toc: false, live_preview: true })
Precious::App.set(:gollum_path, gollum_path)
run Precious::App

Gollum uses Grit to interact with git, so we can use that as well to make it a valid git repository.

Push your repo to Heroku and you’re done!

Creating content for your wiki

This approach will let you see your wiki, and even update it temporarily.

From here onwards you can update your content locally and then push it to Heroku, or if you’re feeling clever, use grit to commit your changes to your Heroku app repository. I’ll experiment some more on that and write about it later.