Coder Social home page Coder Social logo

heroku-buildpack-ruby's Introduction

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 heroku/ruby

$ git push heroku main
...
-----> 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.

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.

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
$ bundle exec rake spec

heroku-buildpack-ruby's People

Contributors

calebhearth avatar catsby avatar danp avatar ddollar avatar dependabot[bot] avatar dmathieu avatar dyegocosta avatar dzuelke avatar edmorley avatar github-actions[bot] avatar halogenandtoast avatar heroku-linguist[bot] avatar hone avatar icco avatar jkutner avatar joshwlewis avatar mattgraham avatar mikehale avatar mikker avatar mmrobins avatar oguzbilgic avatar orlando avatar rafaelfranca avatar rcs avatar rmontgomery429 avatar rohitpaulk avatar rstacruz avatar schneems avatar wuputah avatar znz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heroku-buildpack-ruby's Issues

ungraceful failure on aspen compile

The ruby buildpack seems to fail with a user-facing stacktrace for certain Aspen pushes. For example, try pushing the master branch of this repo to an Aspen app:

$ git push [email protected]:test-aspen-push.git master
Counting objects: 46, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (32/32), done.
Writing objects: 100% (46/46), 4.07 KiB, done.
Total 46 (delta 18), reused 35 (delta 13)

-----> Heroku receiving push
-----> Ruby/Rack app detected
-----> Gemfile detected, running Bundler version 0.9.9
-----> Bundler works best on the Bamboo stack.  Please migrate your app:
       http://devcenter.heroku.com/articles/bamboo
       Unresolved dependencies detected; Installing...
       Using --without development:test
       /usr/local/lib/ruby/1.8/yaml.rb:133:in `load': syntax error on line 2, col 8: `  specs:' (ArgumentError)
        from /usr/local/lib/ruby/1.8/yaml.rb:133:in `load'
        from /usr/local/lib/ruby/1.8/yaml.rb:144:in `load_file'
        from /usr/local/lib/ruby/1.8/yaml.rb:143:in `open'
        from /usr/local/lib/ruby/1.8/yaml.rb:143:in `load_file'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-0.9.9/lib/bundler/definition.rb:16:in `from_lock'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-0.9.9/lib/bundler.rb:84:in `definition'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-0.9.9/lib/bundler/cli.rb:60:in `install'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-0.9.9/lib/bundler/vendor/thor/task.rb:33:in `send'
         ... 6 levels...
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-0.9.9/lib/bundler/vendor/thor.rb:124:in `start'
        from /usr/local/lib/ruby/gems/1.8/gems/bundler-0.9.9/bin/bundle:11
        from /usr/local/bin/bundle:19:in `load'
        from /usr/local/bin/bundle:19
       FAILED: http://devcenter.heroku.com/articles/bundler
 !     Heroku push rejected, failed to install gems via Bundler

To [email protected]:test-aspen-push.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:test-aspen-push.git'

no support for bin/logger processes

i had a script in my app called bin/logger.

here's what happened on build:

-----> Heroku receiving push
-----> Ruby app detected
/tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc.2/lib/bundler/spec_set.rb:90:in block in materialize': Could not find pg-0.14.0 in any of the sources (Bundler::GemNotFound) from /tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc.2/lib/bundler/spec_set.rb:83:inmap!'
from /tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc.2/lib/bundler/spec_set.rb:83:in materializ e' from /tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc.2/lib/bundler/definition.rb:113:inspecs'
from /tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc.2/lib/bundler/definition.rb:162:in specs_f or' from /tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc.2/lib/bundler/definition.rb:151:inrequest
ed_specs'
from /tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc.2/lib/bundler/environment.rb:23:in request ed_specs' from /tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc.2/lib/bundler/runtime.rb:11:insetup'
from /tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc.2/lib/bundler.rb:116:in setup' from /tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/bundler-1.2.0.rc.2/lib/bundler.rb:128:inrequire'
from bin/logger:4:in <main>' -----> Installing dependencies using Bundler version 1.2.0.rc.2 Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment Fetching gem metadata from http://rubygems.org/........ Installing pg (0.14.0) with native extensions Using scrolls (0.2.1) Using sequel (3.38.0) Using bundler (1.2.0.rc.2) Your bundle is complete! It was installed into ./vendor/bundle /tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/database/connecting.rb:69:inconnect': Sequel::
Database.connect takes either a Hash or a String, given: nil (Sequel::Error)
from /tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/core.rb:147:in connect' from bin/logger:6:in

'
Cleaning up the bundler cache.
/tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/database/connecting.rb:69:in connect': Sequel:: Database.connect takes either a Hash or a String, given: nil (Sequel::Error) from /tmp/build_lrz990zohxlp/vendor/bundle/ruby/1.9.1/gems/sequel-3.38.0/lib/sequel/core.rb:147:inconnect'
from bin/logger:6:in `'
^CKilled by signal 2.

here's my Gemfile:

source :rubygems

gem 'pg'
gem 'scrolls'
gem 'sequel'

Rubinius in Bundler 1.20 (Gemfile)

Trying to push an app using Rubinius results in the following error:

-----> Heroku receiving push
-----> Ruby/Rails app detected
 !
 !     Invalid RUBY_VERSION specified: ruby-1.8.7-rbx-2.0.0dev
 !     Valid versions: ruby-1.9.3-p0, ruby-1.9.3-p125, rbx-1.2.4, rbx-2.0.0dev-20120115-1.9, rbx-2.0.0dev-20120115-1.8, rbx-2.0.0dev-20120123-1.9, rbx-2.0.0dev-20120123-1.8, ruby-1.9.2-p290, jruby-1.6.5.1, jruby-1.6.7, ruby-1.9.3, ruby-1.9.2, ruby-1.8.7, ruby-1.9.3-jruby-1.7.0.preview1, ruby-1.8.7-jruby-1.7.0.preview1, ruby-1.9.3-rbx-2.0.0dev, ruby-1.8.7-rbx-2.0.0dev
 !
 !     Heroku push rejected, failed to compile Ruby/rails app

Invalid RUBY_VERSION specified:

ruby-1.8.7-rbx-2.0.0dev

Valid versions:

... snip snip ... ruby-1.8.7-rbx-2.0.0dev

Gemfile:

ruby "1.8.7", :engine => "rbx", :engine_version => "2.0.0dev"

Any idea why this is?

Thanks!

More helpful sqlite3 error message

I'm not getting a very helpful error message when pushing an app that has sqlite3 in the Gemfile. I know it's not supported, but I only saw a compilation error:

Warning: Permanently added 'heroku.com,50.19.85.132' (RSA) to the list of known hosts.
Counting objects: 80, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (63/63), done.
Writing objects: 100% (80/80), 28.67 KiB, done.
Total 80 (delta 10), reused 0 (delta 0)

-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.2.0.pre
       Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
       Fetching gem metadata from https://rubygems.org/.......
       Fetching git://github.com/tenderlove/rails.git
       Fetching git://github.com/rails/journey.git
       Fetching git://github.com/rails/active_record_deprecated_finders.git
       Fetching git://github.com/rails/arel.git
       Fetching git://github.com/rails/coffee-rails.git
       Fetching git://github.com/rails/sprockets-rails.git
       Fetching git://github.com/rails/sass-rails.git
       Installing rake (0.9.2.2)
       Installing i18n (0.6.0)
       Installing minitest (3.2.0)
       Installing multi_json (1.3.6)
       Installing tzinfo (0.3.33)
       Using activesupport (4.0.0.beta) from git://github.com/tenderlove/rails.git (at async)
       Installing builder (3.0.0)
       Installing erubis (2.7.0)
       Using journey (1.0.1.20120208102204) from git://github.com/rails/journey.git (at master)
       Installing rack (1.4.1)
       Installing rack-cache (1.2)
       Installing rack-test (0.6.1)
       Using actionpack (4.0.0.beta) from git://github.com/tenderlove/rails.git (at async)
       Installing mime-types (1.19)
       Installing polyglot (0.3.3)
       Installing treetop (1.4.10)
       Installing mail (2.4.4)
       Using actionmailer (4.0.0.beta) from git://github.com/tenderlove/rails.git (at async)
       Using active_record_deprecated_finders (0.0.1) from git://github.com/rails/active_record_deprecated_finders.git (at master)
       Using activemodel (4.0.0.beta) from git://github.com/tenderlove/rails.git (at async)
       Using arel (3.0.2.20120530170952) from git://github.com/rails/arel.git (at master)
       Using activerecord (4.0.0.beta) from git://github.com/tenderlove/rails.git (at async)
       Installing coffee-script-source (1.3.3)
       Installing execjs (1.4.0)
       Installing coffee-script (2.2.0)
       Installing json (1.7.3) with native extensions
       Installing rdoc (3.12)
       Installing thor (0.15.4)
       Using railties (4.0.0.beta) from git://github.com/tenderlove/rails.git (at async)
       Using coffee-rails (4.0.0.beta) from git://github.com/rails/coffee-rails.git (at master)
       Installing hike (1.2.1)
       Installing jquery-rails (2.0.2)
       Installing puma (1.4.0) with native extensions
       Using bundler (1.2.0.pre)
       Installing tilt (1.3.3)
       Installing sprockets (2.4.4)
       Using sprockets-rails (1.0.0) from git://github.com/rails/sprockets-rails.git (at master)
       Using rails (4.0.0.beta) from git://github.com/tenderlove/rails.git (at async)
       Installing sass (3.1.20)
       Using sass-rails (4.0.0.beta) from git://github.com/rails/sass-rails.git (at master)
       Installing sqlite3 (1.3.6) with native extensions
       Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
       /usr/local/bin/ruby extconf.rb
       checking for sqlite3.h... no
       sqlite3.h is missing. Try 'port install sqlite3 +universal'
       or 'yum install sqlite-devel' and check your shared library search path (the
       location where your sqlite3 shared library is located).
       *** extconf.rb failed ***
       Could not create Makefile due to some reason, probably lack of
       necessary libraries and/or headers.  Check the mkmf.log file for more
       details.  You may need configuration options.
       Provided configuration options:
       --with-opt-dir
       --without-opt-dir
       --with-opt-include
       --without-opt-include=${opt-dir}/include
       --with-opt-lib
       --without-opt-lib=${opt-dir}/lib
       --with-make-prog
       --without-make-prog
       --srcdir=.
       --curdir
       --ruby=/usr/local/bin/ruby
       --with-sqlite3-dir
       --without-sqlite3-dir
       --with-sqlite3-include
       --without-sqlite3-include=${sqlite3-dir}/include
       --with-sqlite3-lib
       --without-sqlite3-lib=${sqlite3-dir}/lib
       --enable-local
       --disable-local
       Gem files will remain installed in /tmp/build_3pfs60ipg4429/vendor/bundle/ruby/1.9.1/gems/sqlite3-1.3.6 for inspection.
       Results logged to /tmp/build_3pfs60ipg4429/vendor/bundle/ruby/1.9.1/gems/sqlite3-1.3.6/ext/sqlite3/gem_make.out
       An error occurred while installing sqlite3 (1.3.6), and Bundler cannot continue.
       Make sure that `gem install sqlite3 -v '1.3.6'` succeeds before bundling.
 !
 !     Failed to install gems via Bundler.
 !
 !     Heroku push rejected, failed to compile Ruby/rails app

To [email protected]:quiet-rain-3994.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:quiet-rain-3994.git'

Assets not being properly served from Rails 3.12 App

Problem

Rails 3.2.12 issue: assets are present on the dyno but the body is not present when being served from the dyno.

Solution

config.rack_cache to dalli or or disabling it seems to fix the issue

Next Steps

Need to repro to determine potential root causes.

Ticket: 78446

Fail compile if repo contains vendor/bundle

Thoughts?

Pros: Committing this directory is harmful, breaks native gems, etc.

Cons: People should be able to vendor everything if they really want to. (But there's a "right way" to do that, and this isn't it... (use bundle package))

bson_ext will not install on Ruby 2.0.0 Dynos

~ $ ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
~ $ gem install bson_ext
Fetching: bson_ext-1.8.5.gem (100%)
Building native extensions.  This could take a while...
Successfully installed bson_ext-1.8.5
Parsing documentation for bson_ext-1.8.5
unable to convert "\xE0" from ASCII-8BIT to UTF-8 for ext/bson_ext/bson_ext, skipping
Installing ri documentation for bson_ext-1.8.5
Done installing documentation for bson_ext (0 sec).
1 gem installed

note the:

unable to convert "\xE0" from ASCII-8BIT to UTF-8 for ext/bson_ext/bson_ext, skipping

Looks like there was an issue with rubygems and 2.0.2 fixed it https://jira.mongodb.org/browse/RUBY-561 related to this gem, though might not be the same issue

SR: 82300

limit database.yml usage?

I noticed that the Ruby buildpack was writing database.yml for my app even though it is not using Rails or even ActiveRecord. Have you considered the possibility of writing database.yml only for apps that depend on libraries using that config file, especially given that we'd like to move away from database.yml in general?

binstubs don't actually work

the buildpack runs bundle install --binstubs vendor/bundle/bin. That of course will create binstubs that find the Gemfile at ../../../Gemfile. The thing is, the buildpack then symlinks (or something?) those binstubs that are buried in vendor/bundle/bin into /app/bin instead, so the path to the Gemfile inside those stubs is wrong when you try to run heroku run rake.

(see also Heroku support ticket 74167)

Put checks in for rails binstub

The default rails 4 bin/rails that's created when you initialize a project is different than the rails binstub.

Don't symlink the rails gem into bin if bin/rails is missing(e.g. if bin/ has been added to the .gitignore file)

1.9.3 default?

To what degree of confidence can we make the default ruby for the buildpack 1.9.3? What are the blockers?

Bundler binstubs overwrites existing binstubs

This causes issues with RBX out of the gate. It also manifests itself where on ruby 1.9.3, if you put rake in your Gemfile, it'll overwrite the existing rake causing bin/rake to not work.

~ $ rake -T
/app/vendor/ruby-1.9.3/Gemfile not found

We need to install the bundler binstubs into a different directory than the ones that ruby uses so there aren't conflicts.

Underscore in local folder name for gem Cause error

You can specify a local path for gem in Gemfile (assuming it is in your source control):

gem 'foo', path: 'vendor/my_gems/foo'

Note the dir my_gems has a underscore. When you push you will get an error like this:

-----> Ruby/Rails app detected 
sh: /tmp/build_2sg0z9pa0ogj6/vendor/my_gems/foo: not found 
! 
! Invalid RUBY_VERSION specified: 
The-path-`/tmp/build_2sg0z9pa0ogj6/vendor/my_gems/foo`-does-not-exist. 
! Valid versions: ruby-2.0.0, ruby-1.9.3, ruby-1.9.2, ruby-1.8.7, 
ruby-1.9.3-jruby-1.7.0, ruby-1.8.7-jruby-1.7.0, ruby-1.9.3-jruby-1.7.1, 
ruby-1.8.7-jruby-1.7.1, ruby-1.9.3-rbx-2.0.0dev, ruby-1.8.7-rbx-2.0.0dev 
! 
sh: /tmp/build_2sg0z9pa0ogj6/vendor/my_gems/foo: not found 
! Heroku push rejected, failed to compile Ruby/rails app

Changing the folder name from my_gems to mygems will work.

cc @stolt45 @brettgoulder

Service Request Number: 78948

Print message if asset compilation successful

Because errors can be emitted by the compilation process, it's not always clear that the process finished successfully. Granted, if it failed, a message would be printed, I think it would be wise to also indicate that we think assets were compiled successfully.

Example of current behavior:

...
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       /usr/local/bin/ruby /tmp/build_22f3kpm37ba0o/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
       DEPRECATION WARNING:
       On line 1 of "", after "*"
       Starting in Sass 3.2, "html" may only be used at the beginning of a selector.

       DEPRECATION WARNING:
       On line 937, after "*"
       Starting in Sass 3.2, "html" may only be used at the beginning of a selector.

       DEPRECATION WARNING:
       On line 961, after "*"
       Starting in Sass 3.2, "html" may only be used at the beginning of a selector.

       DEPRECATION WARNING:
       On line 962, after "*"
       Starting in Sass 3.2, "html" may only be used at the beginning of a selector.

       DEPRECATION WARNING:
       On line 1 of "", after "*"
       Starting in Sass 3.2, "html" may only be used at the beginning of a selector.

       DEPRECATION WARNING:
       On line 937, after "*"
       Starting in Sass 3.2, "html" may only be used at the beginning of a selector.

       DEPRECATION WARNING:
       On line 961, after "*"
       Starting in Sass 3.2, "html" may only be used at the beginning of a selector.

       DEPRECATION WARNING:
       On line 962, after "*"
       Starting in Sass 3.2, "html" may only be used at the beginning of a selector.
-----> Rails plugin injection
...

Feature req: Option to run rake db:migrate upon release (before restarting the dynos)

Save downtime and errors by providing the option to run migrations on push/deploy.
git push heroku --with-migrations
OR
detect and run new migrations automatically. (perhaps enable/disable using an ENV-var?)

Minimal downtime is critical and a though nut to solve. It's a bigger problem for the bigger apps (highest paying customers?), I hate the trade-off continuous deployment vs uptime, but it will always be there, I guess.

The total downtime of the app during deployment could be drastically reduced, especially if the environment is already loaded in one of the other rake tasks run. The migration would take a split second. Added benefit is that a failed migration would not only rollback DB but also the deploy.

The two commands are PITA. I could run 'git push heroku && heroku run rake db:migrate', but often the push never return control to my term, so I still have to watch it and most likely wasting valuable seconds of uptime. I know I'm repeating myself now: a failed migration would rollback, but the code depending on the migrations would not be rolled back. I'd have to rollback the release manually. I'd like this automated :)

If I knew how to do this myself, I'd send a pull request... Thanks guys, I appreciate your work! /fan

Rack App Incorrectly identified as Rails app

If you've got a rack app and also make a config/environment.rb file (which is reasonable) your app will be incorrectly detected as a Rails app. The best fix for this is to not rely on arbitrary file existence but rather the Gems bundled in with the app.

Don't provision shared-database if DATABASE_URL is set

If this was the case, this workflow wouldn't have to involve shared-database:

$ heroku create
$ heroku addons:add heroku-postgresql:crane
$ heroku pg:promote BLUE
$ heroku labs:enable user_env_compile
$ git push heroku master

vendor/bundle warning appearing on all apps?

I'm seeing this when I deployed each of my apps today, but I didn't check in vendor/bundle.

...
-----> WARNING:  Removing `vendor/bundle`.
       Checking in `vendor/bundle` is not supported. Please remove this directory
       and add it to your .gitignore. To vendor your gems with Bundler, use
       `bundle pack` instead.
...
% git ls-files | grep bundle
%

[Question] Install bower (hence npm) to manage JS dependencies installation

In all recent projects, I am using bower to organize and install JS dependencies.

The strategy is to put all those dependencies in a git-ignored folders and let Sprockets find those dependencies.

Do you think it would be worth/sensible adding a new step when building Rails 3+ apps that would run bower install (right after bundle install) automatically so that the deps are part of the compiled container? Is there another way to approach this problem that I'm missing?

Thanks in advance and thanks for your awesome work!

Consider stripping ruby binaries and shared libraries

The binaries and shared libraries at least in the ruby-2.0.0 tarball are not stripped. If having debug symbols for buildpack ruby builds would be useful, consider packaging them into a separate tarball.

This shows possible size reduction, which could translate into quicker build (less to download) and run (smaller slugs to fetch) times:

~ $ mkdir t
~ $ curl -o - https://s3.amazonaws.com/heroku-buildpack-ruby/ruby-2.0.0.tgz | tar -C t -zxf -
~ $ du -sh t
83M t
~ $ find t -type f | xargs file | grep 'not stripped' | awk '{ print $1 }' | cut -d: -f1 | xargs strip
~ $ du -sh t
36M t
~ $ tar -C t -czf ruby-2.0.0-smaller.tgz .
~ $ du -sh ruby-2.0.0-smaller.tgz 
11M ruby-2.0.0-smaller.tgz

Changing Ruby Version Breaks Bundler

Changing Ruby Version Breaks Bundler since PATH and GEM_ENV are not set properly. Support is seeing increased tickets, and when more versions of ruby come out i.e. 2.0 these will increase in number. I'll make a devcenter article as a stop gap measure, but we need to gameplan what we'll be doing to fix this in the long term.

Encoding In application.rb can break Detect Phase

The error makes it look like we can't figure out what type of app they have:

$ git push heroku master
Counting objects: 94, done.
Compressing objects: 100% (64/64), done.
Writing objects: 100% (70/70), 22.96 KiB, done.
Total 70 (delta 19), reused 0 (delta 0)
! Heroku push rejected, no Cedar-supported app detected

But it really comes from an encoding error inside of their application.rb file:

$ irb
>  File.exists?("config/application.rb") &&
>         File.read("config/application.rb") =~ /Rails::Application/
ArgumentError: invalid byte sequence in UTF-8
   from (irb):4
   from /bin/irb:16:in `<main>'

They might not see it on their machine if they have their default languages set to another encoding.

stripping /assets from slug after precompilation/asset_sync

I think it's a rather common scenario for a Heroku app's assets (images, css, js) to be served from an external storage/distribution network such as S3 or CDN(cloudfront) and thus not needing to be served by the application server. However to get the correct digested assets, they need to be precompiled and then synced (e.g. using asset_sync) to their eventual resting place after which point the assets are not needed in the slug. My understanding is that the slug on heroku is formed before the build-pack is run. I am wondering if there is a way to strip the assets from the slug after asset_sync that will save significant binary footprint on the slug.

more flexible paths in ruby.sh?

Currently, the .profile.d/ruby.sh script written by the buildpack assumes that the compiled app will be run in $HOME. This is the case by default on Heroku, but I'm not sure that it needs to be coded into the buildpack. It would be nice, for example, to be able to compile and run an app outside of $HOME for doing CI runs on the platform.

To support this, what do you think about replacing e.g.:

export GEM_PATH=${GEM_PATH:-$HOME/vendor/bundle/ruby/1.9.1}
export LANG=${LANG:-en_US.UTF-8}
export PATH="$HOME/bin:$HOME/vendor/bundle/ruby/1.9.1/bin:$PATH"

with e.g.:

f=$(readlink --canonicalize --no-newline $BASH_SOURCE)
APPHOME=$(cd $(dirname $(dirname $f)) && pwd)
export GEM_PATH=${GEM_PATH:-$APPHOME/vendor/bundle/ruby/1.9.1}
export LANG=${LANG:-en_US.UTF-8}
export PATH="$APPHOME/bin:$APPHOME/vendor/bundle/ruby/1.9.1/bin:$PATH"

No indicator that Rake failed

When recently deploying an app to production a developer added:

require 'ci/reporter/rake/rspec'

The gem is ci_reporter

to our Rakefile. On the next push to Heroku the app was crashing because the assets were non compiling. Once we discovered what the change was the fix was quick:

unless Rails.env == 'production'
  require 'ci/reporter/rake/rspec'
end

But there was no indicator from the push command that anything was wrong other than noticing that the assets compile message was missing https://gist.github.com/1942061

So the suggestion would be to output the result of the rake command, even if it barfs.

Blocking plugin injection causes deprecation warnings

$ rails new rails-example
      ...
      create  vendor/plugins/.gitkeep
         run  bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Installing rake (10.0.4)
...
Using rails (3.2.13)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
$ mkdir -p vendor/plugins/rails_log_stdout
mikehale@Michaels-iMac  ~/dev/heroku/rails-example
$ touch vendor/plugins/rails_log_stdout/.gitkeep
$ rake tmp:clear
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app 
as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /U
sers/mikehale/dev/heroku/rails-example/Rakefile:7)
$ rm -rf vendor/plugins/rails_log_stdout/.gitkeep
$ rake tmp:clear
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app 
as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /U
sers/mikehale/dev/heroku/rails-example/Rakefile:7)
$ rm -rf vendor/plugins/rails_log_stdout/
$ rake tmp:clear
$

Not sure what the best fix for this is. Perhaps just rely on gems: #11. Perhaps look for a path like vendor/plugins/.rails_log_stdout/.gitkeep, which does not seem to trigger the deprecation warning.

Error around ruby_versions.yml

I gather S3 fetching silently failed.

$ git push heroku master
Counting objects: 9, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 442 bytes, done.
Total 5 (delta 4), reused 0 (delta 0)

-----> Heroku receiving push
-----> Ruby/Rails app detected
/usr/local/lib/ruby/1.9.1/syck.rb:145:in `initialize': No such file or directory - ruby_versions.yml (Errno::ENOENT)
    from /usr/local/lib/ruby/1.9.1/syck.rb:145:in `open'
    from /usr/local/lib/ruby/1.9.1/syck.rb:145:in `load_file'
    from /app/slug-compiler/buildpacks/ruby/lib/language_pack/ruby.rb:151:in `block (2 levels) in ruby_versions'
    from /app/slug-compiler/buildpacks/ruby/lib/language_pack/ruby.rb:149:in `chdir'
    from /app/slug-compiler/buildpacks/ruby/lib/language_pack/ruby.rb:149:in `block in ruby_versions'
    from /usr/local/lib/ruby/1.9.1/tmpdir.rb:83:in `mktmpdir'
    from /app/slug-compiler/buildpacks/ruby/lib/language_pack/ruby.rb:148:in `ruby_versions'
    from /app/slug-compiler/buildpacks/ruby/lib/language_pack/ruby.rb:183:in `install_ruby'
    from /app/slug-compiler/buildpacks/ruby/lib/language_pack/ruby.rb:49:in `compile'
    from /app/slug-compiler/buildpacks/ruby/lib/language_pack/rails2.rb:38:in `compile'
    from /app/slug-compiler/lib/../buildpacks/ruby/bin/compile:8:in `block in <main>'
    from /app/slug-compiler/buildpacks/ruby/lib/language_pack/base.rb:81:in `log'
    from /app/slug-compiler/lib/../buildpacks/ruby/bin/compile:7:in `<main>'
 !     Heroku push rejected, failed to compile Ruby/rails app

Removing the Rails 3 runtime asset compilation fallback

cc @samg @hone

When the Rails 3 asset pipeline compilation fails we fallback to runtime compilation by injecting the rails31_enable_runtime_asset_compilation plugin.

As far as I can see this is a pretty terrible default, as most applications aren't able to compile assets at runtime in production as the default Rails Gemfile doesn't even include the required asset dependencies in the production group:

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails', '~> 3.2.0'
  gem 'coffee-rails', '~> 3.2.0'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platform => :ruby
  gem 'uglifier', '>= 1.0.3'
end

The end result is that most apps end up in a 500 state after deployment, throwing an error on any page render. And that it's very easy for the asset compilation to break due to misbehaving plugins (like newrelic for example) only makes the situation worse.

If the asset compilation fails it's probably better to simply error rather than injecting the runtime runtime asset compilation plugin. At least then you've a chance to debug the problem, look at the referenced dev article in the deploy hook output, and fix the compilation.

Example failure (after installing the New Relic gem in a standard Rails 3 app - via the gem, not the addon):

-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile

       Starting the New Relic Agent.
       Installed New Relic Browser Monitoring middleware
       rake aborted!
       could not connect to server: Connection refused
       Is the server running on host "127.0.0.1" and accepting
       TCP/IP connections on port 5432?

       Tasks: TOP => environment
       (See full trace by running task with --trace)
       Precompiling assets failed, enabling runtime asset compilation
       Injecting rails31_enable_runtime_asset_compilation
       Please see this article for troubleshooting help:
       http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting

Avoid deprecation warning from injected plugins for Rails::VERSION::MAJOR >= 3

To avoid ugly deprecation warnings like:

DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)

For Rails::VERSION::MAJOR >= 3

Extract your vendor/plugins to their own gems and bundle them in your Gemfile. If they're tiny, not worthy of the own gem, fold it into your app as lib/myplugin/* and config/initializers/myplugin.rb

[1] http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released/

bundle exec ./script/console

bundle exec script/console doesn't always work; particularly for core. "bundle exec ./script/console" is needed instead. No idea if this is just a core problem that needs to be fixed, or a more generic problem.

Rails 4.0.0.rc1 puts out ugly output

Apparently not grabbing all of the logs:

       Running: rake assets:precompile
       I, [2013-04-30T23:03:44.600420 #826]  INFO -- : Writing /tmp/build_3h426x2r89sub/public/assets/bg-body-5f5fcb2eca2ce4f9d2aa546ffbb087ff.png
       I, [2013-04-30T23:03:44.605139 #826]  INFO -- : Writing /tmp/build_3h426x2r89sub/public/assets/favicon-36f22e1081bda94ef5e5cc3100f56107.png
       I, [2013-04-30T23:03:44.607399 #826]  INFO -- : Writing /tmp/build_3h426x2r89sub/public/assets/logo-bw-251247929739ae68359d7ee4b4ee90d7.png
       I, [2013-04-30T23:03:44.609745 #826]  INFO -- : Writing /tmp/build_3h426x2r89sub/public/assets/logo-mark-9c2e1f494b9c3c1f12ebf38f83029951.png
       I, [2013-04-30T23:03:44.612039 #826]  INFO -- : Writing /tmp/build_3h426x2r89sub/public/assets/logo-bdc05941cec8e7791d61eabf7a0f208c.png
       I, [2013-04-30T23:03:48.934108 #826]  INFO -- : Writing /tmp/build_3h426x2r89sub/public/assets/application-fe9122b4f346603b5686e310cdc580cd.js
       I, [2013-04-30T23:03:49.369551 #826]  INFO -- : Writing /tmp/build_3h426x2r89sub/public/assets/application-a51886dc6f18f124a0af6e5d9492d504.css
       Asset precompilation completed (6.96s)

I'd imagine those INFO lines shouldn't be there.

fatal: Not a git repository (or any of the parent directories): .git

See "fatal: Not a git repository (or any of the parent directories): .git" when pushing sometimes from @daneharrigan

-----> Heroku receiving push
-----> Ruby/Rack app detected
-----> Installing dependencies using Bundler version 1.1.rc
      Running: bundle install --without development:test --path vendor/bundle --deployment
      fatal: Not a git repository (or any of the parent directories): .git
      fatal: Not a git repository (or any of the parent directories): .git
      fatal: Not a git repository (or any of the parent directories): .git
      fatal: Not a git repository (or any of the parent directories): .git
      fatal: Not a git repository (or any of the parent directories): .git
      fatal: Not a git repository (or any of the parent directories): .git
      fatal: Not a git repository (or any of the parent directories): .git
      fatal: Not a git repository (or any of the parent directories): .git
      fatal: Not a git repository (or any of the parent directories): .git
      Fetching gem metadata from http://rubygems.org/........
      fatal: Not a git repository (or any of the parent directories): .git
      fatal: Not a git repository (or any of the parent directories): .git
      fatal: Not a git repository (or any of the parent directories): .git
      Installing daemons (1.1.4)
      Installing eventmachine (0.12.10) with native extensions
      Using oauth (0.4.5)
      Using rack (1.3.5)
      Using rack-protection (1.1.4)
      Using tilt (1.3.3)
      Using sinatra (1.3.1)
      Using micro (0.0.1) from source at .
      Installing thin (1.2.11) with native extensions
      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     -> web
      Default types for Ruby/Rack -> console, rake
-----> Compiled slug size is 6.6MB
-----> Launching... done, v3
      http://micro-engine.heroku.com deployed to Heroku

Remove .git directories from "gems" installed from git sources

ref #16

If I have:

gem "rails", :git => "git://github.com/rails/rails.git", :ref => "3-0-stable"

In my Gemfile I end up with a directory like:

vendor/bundle/ruby/1.9.1/bundler/gems/rails-77403a9b0407

in my slug. This directory contains a .git directory. In a slug created from an app with the above line in its Gemfile that .git directory is 64M. I believe this directory can be removed from the slug and things will still work.

Make it easier to debug the asset pipeline

Debugging pipeline issues can be hard and devious. If the --dry-run fails, it looks like the pipeline support is not working at all, since there's no output. Here's what's currently required to track down issues:

$ heroku run bash
$ unset DATABASE_URL REDISTOGO_URL REDIS_URL MONGOLAB_URI SENDGRID_USERNAME SENDGRID_PASSWORD
$ time env RAILS_ENV=production DATABASE_URL=postgres://user:[email protected]/dbname rake assets:precompile --trace

That said I am not sure what the best solution is, but here's some ideas.

  • What if we had a branch of the buildpack with --trace enabled on the --dry-run and the task itself?
  • What if we built this into the build pack and then it could be enabled... somehow? It can't be a config var, so... File.exists?(".debug-asset-pipeline")?
  • Is there a way we can detect the presence of the pipeline without booting their app, so at least we can say that the --dry-run failed and that's why the pipeline stuff isn't working? Maybe just blindly do this if sprockets is present?
-----> assets:precompile rake task not detected; asset pipeline support disabled

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.