9

I keep getting the following error when trying to deploy my app with the bundle/install option:

    failed: "sh -c 'cd /home/deploy/swamp/releases/20110903003336 
    && bundle install --gemfile /home/deploy/swamp/releases/20110903003336/Gemfile 
    --path /home/deploy/swamp/shared/bundle --deployment --quiet 
    --without development test'" on 12.345.678.98

**Update - looks like I missed an error:

[err :: 12.345.678.98] sh: bundle: not found

I've tried this in my deploy.rb:

require "bundler/capistrano"

and I've tried this:

namespace :bundler do
  task :create_symlink, :roles => :app do
    shared_dir = File.join(shared_path, 'bundle')
    release_dir = File.join(current_release, '.bundle')
    run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
  end
  task :bundle_new_release, :roles => :app do
    bundler.create_symlink
    run "cd #{release_path} && bundle install --without test"
  end
end
after 'deploy:update_code', 'bundler:bundle_new_release'

I've also moved my bundle to the vendor path with this:

bundle install --path vendor/bundle

I don't think it's a permissions problem, because I can log in manually with deploy and bundle install directly on the server no problem. Here is the entire deploy.rb file:

require "bundler/capistrano"


 set :application, "swamp"
 set :domain, "12.345.678.98"
 set :repository,  "git@github.com:***/**.git"
 set :deploy_to, "/home/deploy/#{application}"
 set :rails_env, 'production'
 set :branch, "master"

 role :app, domain
 role :web, domain
 role :db,  domain, :primary => true

 set :deploy_via, :remote_cache

 set :scm, :git
 set :user, "deploy"
 set :runner, "deploy"
 ssh_options[:port] = ****
 set :use_sudo, false

 after "deploy", "deploy:cleanup"

namespace :deploy do

    desc "Restarting mod_rails with restart.txt"
    task :restart, :roles => :app, :except => { :no_release => true } do
        run "touch #{current_path}/tmp/restart.txt"
    end

    [:start, :stop].each do |t|
        desc "#{t} task is a no-op with mod_rails"
        task t, :roles => :domain do ; end
    end
end

task :after_update_code do  
 run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
end
fatfrog
  • 2,118
  • 1
  • 23
  • 46
  • Are you using RVM or anything that could make your session different when you login vs when capistrano connects? – danivovich Sep 03 '11 at 02:18
  • No, I'm not using RVM - it turned out that the solution was to show where bundle was in the deploy.rb file. I'm not very knowledgable with this $PATH stuff. I thought the solution was odd, because of the past few weeks, I've never seen this option set in a deploy file. – fatfrog Sep 03 '11 at 02:30

6 Answers6

11

I found the solution here:

http://www.pastbedti.me/2011/06/change-path-environment-with-rails-and-capistrano/

In you config/deploy.rb add the following snippet

    set :default_environment, {
      'PATH' => "/opt/ruby-enterprise/bin/:$PATH"
    }

Then I had to add gemfile.lock and gemfile to the repository and the BAM!

fatfrog
  • 2,118
  • 1
  • 23
  • 46
  • 2
    note that in cap 3, they changed (for no reason I can understand) this to "default_env" – Bret Weinraub Dec 20 '13 at 12:19
  • @BretWeinraub Thank you so much. I just wasted 3 hours on that one. For those using Capistrano 3, please make note of the variable name change. – Venice Mar 16 '14 at 16:38
7

outdated

the below solution works for capistrano 2. for version 3 and up use the capistrano-rbenv plugin.


assuming you're using the bash shell and have rbenv configured in something along the lines of a bashrc or profile file (globally in /etc or on a user-by-user basis) the problem is that capistrano does not use a so-called login shell which is required to have these files loaded (which, in the end, load rbenv).

for that purpose you might want to instruct capistrano to use such a shell:

default_run_options[:shell] = '/bin/bash --login'

put that into your deploy.rb. also has the benefit of keeping you DRY by not introducing another location to manage your rbenv $PATH additions -- in contrast to fatfrog's solution.

glasz
  • 2,526
  • 25
  • 24
6

This happens because the bashrc rbenv init doesn't get executed. Move this to the top of your deployer user bashrc file and it will fix the problem:

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
David Tuite
  • 22,258
  • 25
  • 106
  • 176
tzumby
  • 61
  • 1
  • 3
1

If your Issue is RVM on the server, then look at the help provided by rvm.io: https://rvm.io/integration/capistrano/#gem

Yo Ludke
  • 2,149
  • 2
  • 23
  • 38
1
  1. make sure you indeed have the rbenv installed in your server(sounds ridiculous, but it did happen in my case)

  2. use this gem: https://github.com/yyuu/capistrano-rbenv

for more details, see my answer here: https://stackoverflow.com/a/15779928/445908

Community
  • 1
  • 1
Siwei
  • 19,858
  • 7
  • 75
  • 95
-1

I was facing this problem and in my case the snippet from deploy/production.rb was as follows:

run "cd #{release_path} && bundle --without development test"

Had to install bundler as follows:

sudo apt-get install bundler

Rahul Singh
  • 2,032
  • 2
  • 16
  • 17