Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capistrano and Bundler problem - bundle: not found

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,  "[email protected]:***/**.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
like image 585
fatfrog Avatar asked Sep 03 '11 00:09

fatfrog


5 Answers

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!

like image 112
fatfrog Avatar answered Nov 12 '22 14:11

fatfrog


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.

like image 24
glasz Avatar answered Nov 12 '22 12:11

glasz


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 -)"
like image 37
tzumby Avatar answered Nov 12 '22 14:11

tzumby


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

like image 20
Yo Ludke Avatar answered Nov 12 '22 13:11

Yo Ludke


  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

like image 1
Siwei Avatar answered Nov 12 '22 13:11

Siwei