Capistrano和Bundler问题 - 捆绑:未找到

时间:2011-09-03 00:53:34

标签: ruby-on-rails capistrano bundler

尝试使用捆绑/安装选项部署我的应用时,我一直收到以下错误:

    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

**更新 - 看起来我错过了一个错误:

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

我在deploy.rb中试过这个:

require "bundler/capistrano"

我试过这个:

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'

我还将我的捆绑包移到了供应商路径:

bundle install --path vendor/bundle

我不认为这是一个权限问题,因为我可以直接在服务器上使用deploy和bundle install手动登录没问题。这是整个deploy.rb文件:

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

6 个答案:

答案 0 :(得分:12)

我在这里找到了解决方案:

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

  

在config / deploy.rb中添加以下代码段

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

然后我不得不将gemfile.lock和gemfile添加到存储库和BAM!

答案 1 :(得分:7)

<强>过时

以下解决方案适用于capistrano 2.对于版本3及以上使用capistrano-rbenv plugin


假设您正在使用bash shell并在bashrcprofile文件的行中配置rbenv(全局位于/etc或逐个用户)基础)问题是capistrano不使用所谓的登录shell,这需要加载这些文件(最后,加载rbenv)。

出于此目的,您可能需要instruct capistrano to use such a shell

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

将其放入deploy.rb。与fatfrog的解决方案相比,还可以通过不引入另一个位置来管理你的rbenv $PATH来保持干爽。

答案 2 :(得分:5)

这是因为bashrc rbenv init没有被执行。将其移至部署用户bashrc文件的顶部,它将解决问题:

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

答案 3 :(得分:1)

如果您的问题是服务器上的RVM,请查看rvm.io提供的帮助: https://rvm.io/integration/capistrano/#gem

答案 4 :(得分:1)

  1. 确保您的服务器中确实安装了rbenv(听起来很荒谬,但在我的情况下确实发生了这种情况)

  2. 使用此gem:https://github.com/yyuu/capistrano-rbenv

  3. 有关详情,请参阅我的回答:https://stackoverflow.com/a/15779928/445908

答案 5 :(得分:-1)

我遇到了这个问题,在我看来,deploy / production.rb的片段如下:

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

必须按如下方式安装bundler:

  

sudo apt-get install bundler