dsshap / heroku-buildpack-ruby-multiapp

Heroku's Ruby Buildpack for Cedar

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Heroku buildpack: Multiple apps in one repo

This buildpack allows you to have two applications in one repo, but only having one application compiled and run on the heroku server at a time.

This is a Heroku buildpack for Ruby Rails3 apps. It uses Bundler for dependency management.

Usage

Config Vars

Example Usage:

=== multiapp-app1 Config Vars
  BUILDPACK_URL:  https://github.com/dsshap/heroku-buildpack-ruby-multiapp.git
  BUILD_DIR:      app1
  BUNDLE_GEMFILE: /app/app1/Gemfile               *Dont set this until after the slug has been compiled*
  GEM_PATH:       app1/vendor/bundle/ruby/1.9.1
  LANG:           en_US.UTF-8
  PATH:           bin:app1/vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin
  RACK_ENV:       production
  RAILS_ENV:      production

Procfile

web: bundle exec thin start -R $BUILD_DIR/config.ru -p $PORT -e $RACK_ENV

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 --stack cedar --buildpack https://github.com/dsshap/heroku-buildpack-ruby-multiapp.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.

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

Flow

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

Rails 3 (config/application.rb is detected)

About

Heroku's Ruby Buildpack for Cedar

License:MIT License


Languages

Language:Ruby 83.7%Language:Shell 12.2%Language:Perl 4.0%