Heroku's Ruby Buildpack
Switch branches/tags
1.15.1 add_binstubs_to_path buildkits_private_space buildkits2 bundle_disable_exec_load bundle_install_full_index bundle_platform_output bundler-1.15.4 bundler-gemfile-parsing cache_assets check-binstubs clean-dot-git-in-vendor-base cli cloudfront custom-jdk-props custom-jdk custom_gemfile database_url_error debug_execjs debug default_postgres_plan default_ruby default_ruby_243 default_193 docker edmorley-use-https-github-s3 edmorly env fail-if-missing-stack-env feature/support-subsequent-process fix-platform-env-arg gems.rb heroku-16 heroku-18 heroku-postgres hone_jdk8 indent-java-tool-opts indirect-patch-1 indirect/patch-1 java_opts jdk-cedar14 jemalloc jkutner/hatchet-update jkutner/java-home jkutner/java-mem jkutner/jruby jkutner/jvm_version jmccartie-patch-1 josephpage-node_8 jruby-compile-path jruby-jvm-preinstall jruby-supported-msg jruby17 keep_original_path legacy-ruby-1.8.7 legacy-ruby-1.9.2 legacy master mattgraham-patch-1 mrg-docker new_output nodebin patch-1 ponies precompile_assets_debug protobuf rack-env-deployment rails-5 rails3_sprockets rails4 rbx refactor_java_home remove-ctrlc remove-extra-quote retry-failed-downloads ruby_previews ruby_version_merge_test_extract ruby_version ruby_versions schneems-patch-1 schneems/DEFAULT_WEB_CONCURRENCY schneems/active-storage schneems/api-rate-limit schneems/better-bundler-error schneems/better-bundler-error2 schneems/better-ruby-error-message schneems/better-ruby-version-failure schneems/better-windows-warning schneems/bundle-wrapper-refactor schneems/bundle-wrapper-refactor2 schneems/bundler-1-17-1 schneems/bundler-1.5.2 schneems/bundler-1.6.3 schneems/bundler-1.13.6 schneems/bundler-1.13.7 schneems/bundler-1.15.0 schneems/bundler-1.16.4 schneems/bundler-1.16.6 schneems/bundler-1.17.2-no-https schneems/bundler-1.17.2-rubygems-upgrade schneems/bundler-1.17.2 schneems/bundler-13 schneems/bundler-17 schneems/bundler-debug-ruby-info-much schneems/bundler-fuzzy-version schneems/bundler-upgrade-warning-deux schneems/bundler-upgrade-warning schneems/bundler1.15.2 schneems/cache_assets schneems/cedar14 schneems/changelog-typo schneems/clean-detect schneems/debug-bad-ruby schneems/debug-bundler schneems/debug-detect schneems/debug-phantom-1-9-3-failure schneems/debug-rails-runner-tests schneems/debug-sept-19 schneems/debug-travis-heroku-cli-failure schneems/debug schneems/debugging-sh-error schneems/debugging schneems/default-223 schneems/detect-rake-tasks schneems/different-gemfile schneems/disable-rubocop schneems/disable-version-check schneems/do-not-fail-when-cannot-detect-config schneems/does-this-fail-on-travis schneems/env-in-check schneems/env-var schneems/explicit-bundler schneems/fail-on-assets-rails schneems/fail-on-rails-cannot-load-rakefile schneems/failing-cd-ruby-test schneems/feature/activerecord_41 schneems/finish-deploy schneems/fix-300 schneems/fix-buildpack-release schneems/fix-bundler-warning-more schneems/fix-changelog-v195 schneems/fix-ci-bad-gemspec schneems/fix-default-cache schneems/fix-default-env-vars schneems/fix-double-space schneems/fix-env-escape schneems/fix-link schneems/fix-lpxc schneems/fix-node-detection schneems/fix-platform-env-arg schneems/fix-procfile-present-on-first-push schneems/fix-rails-runner-timeout-debug schneems/fix-railties-fail schneems/fix-rake-tasks schneems/fix-rubocop-annoyingness schneems/fix-rubocop-ci-error schneems/fix-ruby-version-patch schneems/fix-stack-fail schneems/fix-system-ruby-accident schneems/fix-tests-on-heroku-18 schneems/fix-toml-env schneems/fix-warnings schneems/fuuuuuuuuuuuu-ruby-version-specifiers schneems/hatchet-lockfile schneems/hatchet-runner schneems/heroku-16 schneems/heroku-18-bandaid schneems/heroku-ci schneems/improve-curl schneems/invalid-utf8-encoding-error schneems/investigate-failure schneems/issue-204744 schneems/jruby-troubleshoot schneems/lpxc-fix schneems/malloc-arena-max schneems/mcount schneems/moar-default-cache schneems/moar-warnings schneems/more-database-url-data-in-error schneems/multiple-runner schneems/no-assets-cache-at-runtime schneems/no-bundle-version-check schneems/no-rake-if-manifest schneems/node-multi schneems/orlando schneems/parallel-bundle-wrapper-tests schneems/parallel-tests schneems/patchlevel schneems/performance-m-web_concurrency schneems/plugin-warnings schneems/procfile-warning-redux schneems/rack-env-overwrite schneems/rails-4-1 schneems/rails-4.2 schneems/rails-5 schneems/rails4-no-bin schneems/rake-detect schneems/re-organize-bin schneems/record-jobs-work schneems/release-v167 schneems/remove-add-database schneems/remove-circle schneems/remove-runtime-asset-compilation schneems/remove-warning schneems/retry-hatchet-deploy-failures schneems/rev-app-limit schneems/rev-default-ruby schneems/rev-hatchet schneems/rev-hatchet2 schneems/revert-and-release schneems/revert-commit schneems/rollback-178 schneems/rspec-retry schneems/ruby-2.4.4 schneems/ruby_version_merge schneems/run-tests-against-master schneems/sensible-defaults schneems/sensible-performance-m schneems/shell-detect schneems/spellning schneems/sprockets-error schneems/sprockets-fatal schneems/staging-bucket schneems/support-TAP-ci-output schneems/support-heroku-buildpack-multi-convention schneems/support-subsequent-process schneems/test-handle_new_manifest_filename schneems/timeout-rails-runner schneems/toml schneems/travis schneems/try-activestorage schneems/update-default-ruby schneems/update-hatchet-3 schneems/update-hatchet schneems/upgrade-yarn schneems/use-dot-with-prefix schneems/v154 schneems/v169 schneems/v175 schneems/v176 schneems/v177 schneems/v178 schneems/v179 schneems/v180 schneems/v183 schneems/v184 schneems/v185 schneems/v186 schneems/v188 schneems/v189 schneems/v191 schneems/v194 schneems/v196 schneems/vendor-bundler schneems/version-change-test schneems/wait-on-auto-scale schneems/warn-bundle-config schneems/warn-yellow schneems/webrick-fuuuuuuuuuuuuuuuuuuuu schneems/worker-default-process-type schneems/x-sendfile schneems/1.15.0 schneems/443 skip-plugins-if-gems skip_rake_task_defined staging system testpack travis/speed v77 v166 v170 versions webpacker_install_node
Nothing to show
Clone or download
schneems Merge pull request #832 from heroku/update-yarn
Update included Yarn to latest 1.x version
Latest commit 71c18ff Dec 11, 2018

README.md

Heroku Buildpack for Ruby

ruby

This is a Heroku Buildpack for Ruby, Rack, and Rails apps. It uses Bundler for dependency management.

This buildpack requires 64-bit Linux.

Usage

Ruby

Example Usage:

$ ls
Gemfile Gemfile.lock

$ heroku create --buildpack https://github.com/heroku/heroku-buildpack-ruby.git

$ git push heroku master
...
-----> Heroku receiving push
-----> Fetching custom buildpack
-----> Ruby app detected
-----> Installing dependencies using Bundler version 1.1.rc
       Running: bundle install --without development:test --path vendor/bundle --deployment
       Fetching gem metadata from http://rubygems.org/..
       Installing rack (1.3.5)
       Using bundler (1.1.rc)
       Your bundle is complete! It was installed into ./vendor/bundle
       Cleaning up the bundler cache.
-----> 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.

Bundler

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.

Rails 2

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 --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.

Rails Log STDOUT

A rails_log_stdout is installed by default so Rails' logger will log to STDOUT and picked up by Heroku's logplex.

Auto Injecting Plugins

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.

Rails 3

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 --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.

Assets

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.

Documentation

For more information about using Ruby and buildpacks on Heroku, see these Dev Center articles:

Hacking

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.11.2"

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.

Testing

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:

$ bundle exec hatchet install

then go to hatchet repo and follow the instructions to set it up.

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 do something for a really long time.