Rails 3 - Bundler / Capistrano Errors

I have a basic Rails 3 application that runs locally in my development box, but you want to check the deployment at an early stage to make sure everything works. I am using Capistrano for deployment.

When I run cap deploy (after all the necessary configuration), it breaks off this command with this error:

 [...] * executing 'bundle:install' * executing "bundle install --gemfile /var/www/trex/releases/20100917172521/Gemfile --path /var/www/trex/shared/bundle --deployment --quiet --without development test" servers: ["www.[my domain].com"] [www.[my domain].com] executing command ** [out :: www.[my domain].com] sh: bundle: command not found command finished [...] 

So it looks like it cannot find the bundle command on the server.

However, when I log in to the server ...

 $ ruby -v ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux] $ rails -v Rails 3.0.0 $ bundle -v Bundler version 1.0.0 

... the bundle command is working fine.

What could be wrong?

-

(Also, for completeness :)

 $ which ruby ~/.rvm/rubies/ruby-1.9.2-p0/bin/ruby $ which rails ~/.rvm/gems/ruby-1.9.2-p0/bin/rails $ which bundle ~/.rvm/gems/ruby-1.9.2-p0/bin/bundle 
+52
ruby-on-rails ruby-on-rails-3 bundler capistrano
Sep 17 '10 at 17:50
source share
8 answers

UPDATE:

For RVM> = 1.11.3 you should just use the rvm-capistrano gem . For older RVM> = 1.0.1, the answer below still applies.




ORIGINAL RESPONSE:

Well, although I still haven't gotten a full cap deploy to work, I fixed this problem. The problem was that Capistrano was trying to use a different path for the Bundler (and other gems) than the RVM paths.

Test your Capistrano path by running cap shell , then echo $PATH . You will probably see your standard /usr/local/bin and /usr/bin , but not where the RVM has a Bundler, etc. Saved.

Modify the Capistrano config/deploy.rb and add the following lines to the following instructions :

 # Add RVM lib directory to the load path. $:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Load RVM capistrano plugin. require "rvm/capistrano" set :rvm_ruby_string, '1.9.2' set :rvm_type, :user # Don't use system-wide RVM 

Finally he got Capistrano to see the Bundler and start loading the gems accordingly.

+89
Sep 20 '10 at 15:16
source share

The bundler was not found because .bash_profile is not loading and therefore your PATH is erroneous. This is probably due to the fact that you have an RVM script in .bash_profile.

The simple answer is to move the RVM script from .bash_profile to .bashrc, and Capistrano should find it (also check that .bash_profile source.bashrc).

Capistrano uses SSH to execute commands on the server using a non-interactive shell . This shell session will be source.bashrc, but not .bash_profile . I added an ECHO instruction for both and ran LS through SSH. You can see in the results below that only .bashrc is sent:

 $ ssh user@123.amazonaws.com ls .bashrc loaded git file1 file2 
+26
Aug 12 '11 at 11:20
source share

I had an identical problem using rbenv. The solution was to take specific rbenv lines from the bottom of my .bashrc file and place them at the top. The first line of my .bashrc file was returned by an interrupt if the shell did not work interactively.

+11
Feb 15 2018-12-15T00:
source share

The last line should be

 set :rvm_type, :user 

that is, the user must be a symbol, not a variable, otherwise you will get

 undefined local variable or method `user' 
+7
Nov 24 '10 at 15:46
source share

No rvm/capistrano worked for me. The best solution I found added the following line to the deploy.rb file (this is for a non-system-wide RVM):

set :bundle_cmd, 'source $HOME/.bash_profile && bundle'

+7
Nov 27 '11 at 3:45
source share

As I understand it, the bundle command was not found because the PATH variable defined in the ~ / .bash_profile user file is not loaded by Capistrano.

To get around this, I created a task: bundle_gems.

 task :bundle_gems do run "cd #{deploy_to}/current && export PATH=/usr/local/pgsql/bin:/opt/ruby-enterprise-XXX/bin:$PATH && bundle install vendor/gems" end 

Please note that I also indicate the path to the PostgreSQL binaries - the installation of pg gem failed because they could not be found even if the package was found.

This seems like a messy approach. Presumably, there is a more โ€œglobalโ€ place to define binary paths that I don't know about.

Update 23/12

To add a directory to $ PATH for all users: https://serverfault.com/questions/102932/adding-a-directory-to-path-in-centos

However, this will not be loaded yet, because it is a non-interactive shell without login.

It was suggested to add the paths to / etc / bashrc: How to set $ PATH so that `ssh user @host command` works?

However, this did not work for me either. I believe because SSH does not load / etc / bashrc.

Another suggestion was to edit ~ / .ssh / environment: http://www.ruby-forum.com/topic/79248 . However, this seems almost as dirty as specifying the paths in deploy.rb.

+2
Dec 19 '10 at 16:23
source share

This worked for me:

set: bundle_cmd, 'source $ HOME / .bash_profile && & &&& & && bundle

+1
Feb 14 '14 at 13:53
source share

I tried a few suggestions. There were problems setting paths in the deploy.rb file for the RVM environment. My final decision was to include the following:

In the config / deploy.rb file add:

 require "bundler/capistrano" 

Also in config / deploy.rb or in my case config / production.rb since I used the multi-stage option for Capistrano

 after "deploy", "rvm:trust_rvmrc" 

This step simply ensures that we stop receiving โ€œyou want to trust the .rvmrc fileโ€ and it invokes the task in the deploy.rb file, for example:

 namespace :rvm do task :trust_rvmrc do run "rvm rvmrc trust #{release_path}" end end 

After making these minor changes, I was able to run cap production deploy , which checked the code; Deployed the asset pipeline, linked the release folder to the current one, completed bundle install and cleaned it.

0
Feb 20 '13 at 23:33
source share



All Articles