I have a rake task that looks like so (crontab):
cd /data/TheApp/current && bundle exec rake nightly_tasks[3]
--trace --silent 2>> /data/TheApp/shared/log/tasks_prod_errors.log
It all runs fine in test and dev, but on prod I get this error:
rake aborted!
no such file to load -- ruby-debug
/usr/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in
`require'
/usr/lib/ruby/gems/1.9.1/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in
`block (2 levels) in require'
OK so I check my gemfile and I have this:
group :development, :test do
gem 'ruby-debug19', :require => 'ruby-debug', :platforms => :ruby
...
Production env should be ignoring that ruby-debug requirement. So I check my RAILS_ENV and it’s correct:
$ echo $RAILS_ENV
production
On top of that the line that used to require ruby debug in this rake task is commented out. So to me it looks like there’s no way bundle exec should be trying to load ruby-debug in prod. Is this maybe something to do with the gemfile.lock? There is an entry for ruby-debug19 in there. But why would my rake task be loading it in that case?
Also, running the command from the command line works fine. Confusing.
The rails environment and bundler groups are two completely different things. One doesn’t know about the other although they use similar terms in your case
As a workaround, you can use
bundle install --without development testin production to tell bundler to not install those groups. Alternatively, you can use something like this in your Gemfile:That expects that you have the environment variable RAILS_ENV set. during your
bundle installrun as well as during yourbundle execrun (i.e. always).