ruby-on-rails - Capistrano v3 找不到 Bundler

标签 ruby-on-rails ruby capistrano bundler

我在使用 Capistrano v3 部署我的应用程序时遇到问题。当我运行“$ cap production deploy”时,我看到一个错误...

 INFO [825ad68d] Running /usr/bin/env bundle --gemfile /home/username/www/myapp/releases/20131026181031/Gemfile --path /home/username/www/myapp/shared/bundle --deployment --quiet --binstubs /home/username/www/myapp/shared/bin --without development test on myhostname.com
DEBUG [825ad68d] Command: cd /home/username/www/myapp/releases/20131026181031 && ( RAILS_ENV=production /usr/bin/env bundle --gemfile /home/username/www/myapp/releases/20131026181031/Gemfile --path /home/username/www/myapp/shared/bundle --deployment --quiet --binstubs /home/username/www/myapp/shared/bin --without development test )
DEBUG [825ad68d]    /usr/bin/env: 
DEBUG [825ad68d]    bundle
DEBUG [825ad68d]    : No such file or directory

但是当我运行最后一个命令时...

cd /home/username/www/myapp/releases/20131026181031 && ( RAILS_ENV=production /usr/bin/env bundle --gemfile /home/username/www/myapp/releases/20131026181031/Gemfile --path /home/username/www/myapp/shared/bundle --deployment --quiet --binstubs /home/username/www/myapp/shared/bin --without development test )

...在我的服务器上通过 ssh 我没有看到任何错误。

这是我的服务器环境:

  • Ubuntu 13.04
  • rvm 1.23.5
  • rubygems 1.8.25
  • bundler 1.3.5
  • ruby 1.9.3p448
  • 卡皮斯特拉诺 (3.0.0)
  • capistrano-bundler (1.0.0)
  • capistrano-rails (1.0.0)

这是我的 Gemfile 的一部分,其中包含 capistrano 的 gems

...
group :development do
  ...
  # Deploy with Capistrano
  gem 'capistrano', '~> 3.0.0'
  gem 'capistrano-rails'
  gem 'capistrano-bundler'
end
...

请看下面capistrano的配置:

Capfile

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'

Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }

config/deploy.rb

set :application, 'myapp'
set :repo_url, "/home/username/repository/#{fetch(:application)}.git"
set :deploy_to, "/home/usename/www/#{fetch(:application)}"
set :scm, :git
set :branch, "master"
set :format, :pretty
set :use_sudo, false

set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

set :keep_releases, 5

SSHKit.config.command_map[:rake]  = "bundle exec rake"
SSHKit.config.command_map[:rails] = "bundle exec rails"

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      # execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end

  after :finishing, 'deploy:cleanup'
end

config/deploy/production.rb

set :stage, :production

set :bundle_gemfile, -> { release_path.join('Gemfile') }
set :bundle_dir, -> { shared_path.join('bundle') }
set :bundle_flags, '--deployment --quiet'
set :bundle_without, %w{development test}.join(' ')
set :bundle_binstubs, -> { shared_path.join('bin') }
set :bundle_roles, :all

role :app, %w{myhostname.com}
role :web, %w{myhostname.com}
role :db,  %w{myhostname.com}

server 'myhostname.com', user: 'username', roles: %w{web app}, my_property: :my_value

fetch(:default_env).merge!(rails_env: :production)

请帮帮我。

已解决

我已经通过以下步骤解决了我的问题:

将 capistrano-rvm 添加到 Gemfile 中并执行

...
group :development do
  ...
  gem 'capistrano', '~> 3.0.0'
  gem 'capistrano-rails'
  gem 'capistrano-bundler'
  gem 'capistrano-rvm'
end
...

将这一行添加到 Capfile

require 'capistrano/rvm'

将这些行添加到 deploy.rb 文件中。

set :rvm_ruby_version, '1.9.3-p448'
set :default_env, { rvm_bin_path: '~/.rvm/bin' }
SSHKit.config.command_map[:rake] = "#{fetch(:default_env)[:rvm_bin_path]}/rvm ruby-#{fetch(:rvm_ruby_version)} do bundle exec rake"

最佳答案

看来您必须添加 capistrano-rvm。它将处理您的 rubybundler 路径。

bundle install doesn't work from capistrano

关于ruby-on-rails - Capistrano v3 找不到 Bundler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19610516/

相关文章:

ruby-on-rails - 配置多个服务器以支持sidekiq

ruby-on-rails - 如何在错误的rspec规范之间清理数据库?

ruby - 为什么不应该使用制表符进行缩进?

ruby - 如何在嵌套的 Rspec 共享示例中传递两个级别的变量?

ruby-on-rails - 如何通过 capistrano 3 运行自定义 rake 任务?

ruby-on-rails - 如何在自定义 capistrano 任务中使用事务?

jquery - 如何将ajax数据提交到.js.erbrails

mysql - 设置 Ruby On Rails 时遇到问题

php - Javascript V8 会杀死所有其他服务器端动态语言吗? ruby 、 python 、PHP?

ruby-on-rails - ActionMailer - 限制收件人数量?