Heroku Ruby Jekyll Buildpack is a fork of Heroku's official Ruby buildpack with added support for generating static Jekyll sites during the build/deployment stage.
With this buildpack you no longer need pre-build the site or commit the _site build directory to your repo. This simplifies the deployment process and keeps the repo clean. All of the standard Ruby tools are maintained in this buildpack, so you can take full advantage of Rack middleware and other useful tools from the Ruby ecosystem.
heroku create --buildpack http://github.com/mattmanning/heroku-buildpack-ruby-jekyll.git
or add this buildpack to your current app
heroku config:add BUILDPACK_URL=http://github.com/mattmanning/heroku-buildpack-ruby-jekyll.git
Create a Ruby web app with dependencies managed by Bundler and a Jekyll site. Heroku-Jekyll-Hello-World can be used as a sample starter.
git push heroku master
Watch it "Building jekyll site"
-----> Fetching custom git buildpack... done
-----> Ruby/Rack app detected
-----> Installing dependencies using Bundler version 1.3.0.pre.5
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
Using posix-spawn (0.3.6)
Using albino (1.3.3)
Using fast-stemmer (1.0.0)
Using classifier (1.3.3)
Using daemons (1.1.4)
Using directory_watcher (1.4.1)
Using eventmachine (0.12.10)
Using kramdown (0.13.3)
Using liquid (2.3.0)
Using syntax (1.0.0)
Using maruku (0.6.0)
Using jekyll (0.11.0)
Using rack (1.3.5)
Using rack-contrib (1.1.0)
Using rack-rewrite (1.2.1)
Using thin (1.3.1)
Using bundler (1.3.0.pre.5)
Your bundle is complete! It was installed into ./vendor/bundle
Cleaning up the bundler cache.
Would have removed bundler (1.2.1)
Building jekyll site
Configuration from /tmp/build_2khwpm40t8wev/_config.yml
Building site: . -> ./_site
Successfully generated site: . -> ./_site
-----> Discovering process types
Procfile declares types -> (none)
Default types for Ruby -> console, rake
The buildpack will detect your app as Ruby if it has a Gemfile
and Gemfile.lock
files in the root directory. It will then proceed to run bundle install
after setting up the appropriate environment for ruby and Bundler.
The tests on this buildpack are written in Rspec to allow the use of
focused: true
. Parallelization of testing is provided by
https://github.com/grosser/parallel_tests this lib spins up an arbitrary
number of processes and running a different test file in each process,
it does not parallelize tests within a test file. To run the tests: clone the repo, then bundle install
then clone the test fixtures by running:
$ hatchet install
Now run the tests:
$ bundle exec parallel_rspec -n 6 spec/
If you don't want to run them in parallel you can still:
$ bundle exec rake spec
Now go take a nap or something for a really long time.
For non-windows Gemfile.lock
files, the --deployment
flag will be used. In the case of windows, the Gemfile.lock will be deleted and Bundler will do a full resolve so native gems are handled properly. The vendor/bundle
directory is cached between builds to allow for faster bundle install
times. bundle clean
is used to ensure no stale gems are stored between builds.
Example Usage:
$ ls
app config db doc Gemfile Gemfile.lock lib log public Rakefile README script test tmp vendor
$ ls config/environment.rb
config/environment.rb
$ heroku create --stack cedar --buildpack https://github.com/heroku/heroku-buildpack-ruby.git
$ git push heroku master
...
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.1.rc
...
-----> Writing config/database.yml to read from DATABASE_URL
-----> Rails plugin injection
Injecting rails_log_stdout
-----> Discovering process types
Procfile declares types -> (none)
Default types for Ruby/Rails -> console, rake, web, worker
The buildpack will detect your app as a Rails 2 app if it has a environment.rb
file in the config
directory.
A rails_log_stdout is installed by default so Rails' logger will log to STDOUT and picked up by Heroku's logplex.
Any vendored plugin can be stopped from being installed by creating the directory it's installed to in the slug. For instance, to prevent rails_log_stdout plugin from being injected, add vendor/plugins/rails_log_stdout/.gitkeep
to your git repo.
Example Usage:
$ ls
app config config.ru db doc Gemfile Gemfile.lock lib log Procfile public Rakefile README script tmp vendor
$ ls config/application.rb
config/application.rb
$ heroku create --stack cedar --buildpack https://github.com/heroku/heroku-buildpack-ruby.git
$ git push heroku master
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.1.rc
Running: bundle install --without development:test --path vendor/bundle --deployment
...
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
-----> Rails plugin injection
Injecting rails_log_stdout
Injecting rails3_serve_static_assets
-----> Discovering process types
Procfile declares types -> web
Default types for Ruby/Rails -> console, rake, worker
The buildpack will detect your apps as a Rails 3 app if it has an application.rb
file in the config
directory.
To enable static assets being served on the dyno, rails3_serve_static_assets is installed by default. If the execjs gem is detected then node.js will be vendored. The assets:precompile
rake task will get run if no public/manifest.yml
is detected. See this article on how rails 3.1 works on cedar.
To use this buildpack, fork it on Github. Push up changes to your fork, then create a test app with --buildpack <your-github-url>
and push to it.
To change the vendored binaries for Bundler, Node.js, and rails plugins, use the rake tasks provided by the Rakefile
. You'll need an S3-enabled AWS account and a bucket to store your binaries in as well as the vulcan gem to build the binaries on heroku.
For example, you can change the vendored version of Bundler to 1.1.rc.
First you'll need to build a Heroku-compatible version of Node.js:
$ export AWS_ID=xxx AWS_SECRET=yyy S3_BUCKET=zzz
$ s3 create $S3_BUCKET
$ rake gem:install[bundler,1.1.rc]
Open lib/language_pack/ruby.rb
in your editor, and change the following line:
BUNDLER_VERSION = "1.1.rc"
Open lib/language_pack/base.rb
in your editor, and change the following line:
VENDOR_URL = "https://s3.amazonaws.com/zzz"
Commit and push the changes to your buildpack to your Github fork, then push your sample app to Heroku to test. You should see:
-----> Installing dependencies using Bundler version 1.1.rc
NOTE: You'll need to vendor the plugins, node, Bundler, and libyaml by running the rake tasks for the buildpack to work properly.
Here's the basic flow of how the buildpack works:
Ruby (Gemfile and Gemfile.lock is detected)
- runs Bundler
- installs binaries
- installs node if the gem execjs is detected
- runs
rake assets:precompile
if the rake task is detected
Rack (config.ru is detected)
- everything from Ruby
- sets RACK_ENV=production
Rails 2 (config/environment.rb is detected)
- everything from Rack
- sets RAILS_ENV=production
- install rails 2 plugins
-
-----> Compiled slug size: 6.1MB -----> Launching... done, v99 -----> Deploy hooks scheduled, check output in your logs http://mattmanning.herokuapp.com deployed to Heroku
-
The blog post introducing this buildpack: http://mwmanning.com/2011/11/29/Run-Your-Jekyll-Site-On-Heroku.html.