Заметки Ruby программиста Всякие полезные наработки


Bundler on heroku and without feature

Since bundler 1.0 release it recommends include Gemfile.lock into repository to force exactly the same gem environment for all users. Good idea, but here is one problem occurs - we can't use Gemfile hacks like this anymore:

if RUBY_PLATFORM =~ /darwin/
  gem "autotest-fsevent"

This case on other platform bundler will detect what gem "autotest-fsevent" is not present in Gemfile but presents in Gemfile.lock and fails.

Researching this problem i have found solution: same things still can be done using power of bundler :group and --without features! We can put gems which is needed only for specific platform to separate group and skip them on another platform using bundler's --without parameter! Let's look at example:

group :development do
  gem 'ruby-debug', :platforms => :mri_18
  gem 'looksee'
  gem 'awesome_print'
  gem 'wirble'

group :test do
  gem 'rspec-rails', '~> 2.0.0.beta.20'
  gem "factory_girl_rails"
  gem "autotest"
  gem "autotest-fsevent"

Usually we also don't need any test or development gems in our production environment. So then deploying to production we can run:

$ bundle install --without development test

And production and test groups will be skipped and don't used in production server.

This works fine then you deploy using capistrano or you can run bundle install manually and specify any command line parameters. Unfortunately we can't do this on Heroku. But solution exists! We still can use ENV vars to configure bundler install default behavior! Set BUNDLE_WITHOUT config var to the name of groups (separated by colon) and it will just skip unneeded gems during bundle install.

$ heroku config:add BUNDLE_WITHOUT=test:development

Unfortunately this feature is not working right now because of a bundler bug. But i have already fixed this bug and now it's already in bundler repo! So this feature will work with next bundler release. I hope Heroku team will upgrade their bundler as soon as this release will out. Because this feature is very needed on that platform.

Here is one more problem exists. When you put gem in two (or more) groups and trying skip it using one of this groups only - it will be ignored. It will work only if you specify both group names. We are discussing this behavior now and if you support me i hope this behavior would be changed. So please put your thoughts here:


Комментарии (0) Пинги (0)

Пока нет комментариев.

Leave a comment

Нет обратных ссылок на эту запись.