Capistrano和Bundler问题- bundle:未找到



当尝试使用bundle/install选项部署我的应用程序时,我一直得到以下错误:

    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移动到vendor路径:

bundle install --path vendor/bundle

我不认为这是一个权限问题,因为我可以手动登录与部署和bundle安装直接在服务器上没有问题。这是整个部署。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

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

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

在你的配置/部署。添加以下代码片段

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

然后我必须添加gemfile。锁定和gemfile到存储库和BAM!

过时

下面的解决方案适用于capistrano 2。对于版本3及以上,请使用capistrano-rbenv插件。


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

为此,您可能需要指示capistrano使用这样的shell:

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

把它放进你的deploy.rb。与fatfrog的解决方案相比,它还具有保持DRY的优点,无需引入另一个位置来管理rbenv $PATH添加。

这是因为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 -)"

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

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

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

更多细节,请看我的回答:https://stackoverflow.com/a/15779928/445908

我正面临这个问题,在我的例子中是来自部署/生产的代码片段。Rb值如下:

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

必须按如下方式安装捆绑器:

sudo apt-get install bundle>

相关内容

最新更新