Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 559
nfm Avatar asked Nov 23 '11 05:11

nfm


3 Answers

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
like image 158
Ccastillop Avatar answered Nov 10 '22 07:11

Ccastillop


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.

like image 31
wickning1 Avatar answered Nov 10 '22 07:11

wickning1


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.

like image 1
aproctor Avatar answered Nov 10 '22 07:11

aproctor