开发者

Capistrano and Bundler problem - bundle: not found

开发者 https://www.devze.com 2023-04-02 08:05 出处:网络
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

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.tx开发者_如何学编程t"
    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


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!


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.


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 -)"


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


  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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号