"bundle exec rake" doesn't honor "without" - ruby-on-rails

On a GitLab installation from source, I'm having problems running binaries such as rake. I've never seen similar problems with my own Ruby or Rails projects:
# bundle config
Set for your local app (/mnt/data/www/gitlab.bitcetera.com/source/gitlab/.bundle/config): "1"
path
Set for your local app (/mnt/data/www/gitlab.bitcetera.com/source/gitlab/.bundle/config): "vendor/bundle"
without
Set for your local app (/mnt/data/www/gitlab.bitcetera.com/source/gitlab/.bundle/config): "development:test:unicorn:mysql:kerberos:metrics"
disable_shared_gems
Set for your local app (/mnt/data/www/gitlab.bitcetera.com/source/gitlab/.bundle/config): "true"
# bundle install --deployment --without development test unicorn mysql kerberos metrics
# bundle config
The Gemfile's dependencies are satisfied
# bundle exec rake --tasks
rake aborted!
LoadError: cannot load such file -- haml_lint/rake_task
Looking at the relevant section of the Gemfile:
group :development, :test do
[...]
gem 'haml_lint', '~> 0.21.0', require: false
[...]
end
Of course the haml_lint gem is missing, after all, it's in the "development" and "test" groups only which I've excluded by "without".
Any idea what's going on here?

Figured it out, kinda daft reason: RAILS_ENV should have been set automatically yet it wasn't so of course things go awry.

Related

Rake aborted! when locally Precompiling Assets

When running bundle exec rake assets:precompile on my dev machine I get a rake aborted error:
cannot load such file -- rack/google_analytics
This is in my gemfile in the production group so isn't installed on my dev machine:
group :production do
gem 'rack-google_analytics', :require => "rack/google_analytics"
end
Any ideas how to fix this? I am running rake 0.9.2.2 and Rails 3.2.1. If required, I can provide more info.
When I changed the following value to true from false (in config/environments/production.rb), I could get rid of the above error
config.assets.compile = true
The only way I could resolve this was to comment out the Production group in my gemfile, and then running:
bundle install
bundle exec rake assets:precompile
Then uncommenting, running bundle install again and pushing to git/deploying with capistrano.
I'm guessing the reason you are experiencing this is that you had previously done a:
bundle install --without production
Some versions of bundler cache this command and run it as default. Try running something like this to clear the cache:
bundle install --without santa
Your next command
bundle exec rake assets:precompile
should work fine again.

Gem is not checked out. Please run `bundle install` in Heroku

I have this configuration in my Gemfile:
group :test do
# ...
gem "shoulda-matchers", :git => "git://github.com/watu/shoulda-matchers.git", :branch => "do_not_load_minitest"
end
which works fine locally, but when I push to Heroku, when I try to run rake db:migrate, I get this error:
git://github.com/watu/shoulda-matchers.git (at do_not_load_minitest) is not checked out. Please run bundle install
Indeed I don't see it in the output of bundle install being run on Heroku, maybe because it's on the test group and Heroku is not installing the test group. But then, why is it complaining when I run rake db:migrate? should it run in staging env?
I tried switching to the http url and all I got is the same error with another URL:
https://github.com/watu/shoulda-matchers.git (at do_not_load_minitest) is not checked out. Please run bundle install
Moving the line outside the :test group workarounded the problem. What's the proper solution?
If you don't really need that gem (since it is in :test group), you can add this configuration to your app:
heroku config:add BUNDLE_WITHOUT="development:test" --app <your_app>

why would I get `no such file to load -- ruby-debug` in production rake task?

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 test in production to tell bundler to not install those groups. Alternatively, you can use something like this in your Gemfile:
unless ENV['RAILS_ENV'] == "production"
gem 'ruby-debug19', :require => 'ruby-debug', :platforms => :ruby
end
That expects that you have the environment variable RAILS_ENV set. during your bundle install run as well as during your bundle exec run (i.e. always).
All you need to do is use the “debugger” gem for ruby 1.9.
gem install debugger

bundle install in Capistrano not installing assets gems in Rails

When I run cap deploy, the gems in the :assets group are not installed.
This is a problem because I'm using precompiled assets, and Capistrano has to run rake assets:precompile on the server. That will fail unless the assets gems are installed.
I can work around this problem by manually running bundle install within the correct release directory. But obviously this isn't the proper workflow.
Here's the full command Capistrano is executing to install the gems on each deploy:
rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'default' -c 'cd
/home/deploy/rails_apps/vlc/releases/20120223192328 && bundle install --gemfile
/home/deploy/rails_apps/vlc/releases/20120223192328/Gemfile --path
/home/deploy/rails_apps/vlc/shared/bundle --deployment --quiet --without development test'
Here's the end, which I think might be part of the problem:
--deployment --quiet --without development test'
Evidently, these flags cause Bundler to install without the :assets group. What is the expected behavior here? Is what I'm seeing out of the ordinary? (I'm guessing so, since it doesn't make sense for Capistrano to deliberately refrain from installing a gem group that it's about to use.)
As a side note, I also note this line in application.rb:
Bundler.require(*Rails.groups(:assets => %w(development test)))
I'm assuming nothing in application.rb would affect a bundle install, since Rails doesn't boot for that. But please correct me if this line is actually relevant to my problem.
--without is remembered option, check in your project dir / on server the file .bundle/config it's possible it already contains something like this:
---
BUNDLE_WITHOUT: assets

Can't get bundle exec to work in production

I've installed my gems in production with:
cd /app/releases/current && bundle install --gemfile /app/releases/current/Gemfile --path /app/shared/bundle --deployment --quiet --without development test
I can't bundle exec any of my gems (except rake and gem):
$ bundle exec whenever
bundler: command not found: whenever
Install missing gem executables with `bundle install`
The gems are correctly installed in /app/shared/bundle:
$ cd /app/shared
$ find . -name whenever
./bundle/ruby/1.9.1/gems/whenever-0.6.8/bin/whenever
./bundle/ruby/1.9.1/gems/whenever-0.6.8/lib/whenever
My (generated) bundle config (in /app/current/.bundle/config) is:
---
BUNDLE_FROZEN: "1"
BUNDLE_PATH: /app/shared/bundle
BUNDLE_DISABLE_SHARED_GEMS: "1"
BUNDLE_WITHOUT: development:test
I'm running ruby 1.9.2p290, manually installed to /usr/local/bin.
Do I have to bundle install my gems with the --binstubs option? Why wouldn't bundle exec be searching the stored BUNDLE_PATH?
Using Capistrano and Rails and using deploy.rb as deployer file.
I realized that changing the order where appears require "whenever/capistrano" really matters. I put that at almost the last line:
In deploy.rb:
#first lines:
set :rvm_ruby_string, "1.9.3"
set :rvm_type, :user
set :whenever_command, "bundle exec whenever"
# others...
# last lines
require 'rvm/capistrano'
require 'bundler/capistrano'
require "whenever/capistrano"
after "deploy:update_code", "customs:config"
after "deploy:create_symlink","deploy:create_symlink"
after "deploy", "deploy:cleanup"
load 'deploy/assets'
# end
I had this problem and had the requires in the correct order, i.e.
require 'rvm/capistrano'
require 'bundler/capistrano'
require 'whenever/capistrano'
It still wanted to run the crontab update before bundle:install. The solution was to update my local bundler with
gem update bundler
After that it started working again. Not sure exactly what changed between versions that broke all of this.
Check where your bundle:install is being set, and try moving it above require 'whenever/capistrano' in your deploy.rb file.
It seems like this was triggered when I did a bundle update that increased the whenever gem version in my Gemfile.lock.
It looks like whenever tries to run it's chrontab update before my deploy file runs bundle:install
from https://github.com/javan/whenever/blob/master/lib/whenever/capistrano.rb
before "deploy:finalize_update", "whenever:update_crontab"
And my deploy.rb had
after 'deploy:finalize_update', 'bundle:install'
Like everyone else in this thread, I tried a few things and I'm not sure this is what fixed it for me, but changing bundle install to before deploy:finalize_update, and also setting it as "before" above requiring 'whenever/capistrano' seems like it's the likely fix in my scenario.
I think when whenever gem is not in your Gemfile, or it's in the test or development section of your Gemfile
I changed the --path from /app/shared/bundle to vendor/bundle, which made it work.
This seemed wrong to me, so I removed /app/shared/bundle and vendor/bundle, and ran bundle install again to /app/shared/bundle.
This clean bundle install fixed the problem. I have no idea why!
If anyone has an explanation for this, I'd love to mark you as the accepted answer. But this fixed the problem for me.
Probably different issues cause the same error message. For me, I had to update capistrano gem after having updated whenever gem to get roles support. bundle exec whenever had worked prior to my upgrade of whenever.
Using the brightbox deployment gem, which handles bundler etc for me (by magic, in some other recipes) I found this works:
Replace
require "whenever/capistrano"
with the contents of https://github.com/javan/whenever/blob/master/lib/whenever/capistrano/v2/hooks.rb
then modify it to load after bundler:install finishes (you may or may not have that task, I don't know if it's standard)
# require "whenever/capistrano"
# hacked whenever/lib/whenever/capistrano/v2/hooks.rb below to work with brightbox bundler installation
require "whenever/capistrano/v2/recipes"
# Write the new cron jobs near the end.
after "bundler:install", "whenever:update_crontab"
# If anything goes wrong, undo.
after "deploy:rollback", "whenever:update_crontab"

Resources