Capistrano:Bundler不使用rvm gemset

23t*_*tux 4 capistrano ruby-on-rails bundler rvm ruby-on-rails-3

我有一个Ruby on Rails 3.2应用程序,使用bundler和capistrano进行部署.我的服务器是带有rvm和ruby 1.9.2的Debian Squeeze.我为capistrano(http://beginrescueend.com/integration/capistrano/)阅读了rvm的东西,你可以在其中设置gemset set :rvm_ruby_string, '1.9.2@my_gemset'.

但在部署期间,bundler会将每个gem写入/var/www/my_app/shared/bundle.我想如果我用@符号定义rvm_ruby_string,bundler会使用gemset.

部署的输出说

  * executing "cd /var/www/my_app/releases/20120216145728 && bundle install --gemfile /var/www/my_app/releases/20120216145728/Gemfile --path /var/www/my_app/shared/bundle --deployment --quiet --without development test"
Run Code Online (Sandbox Code Playgroud)

我可以在哪里更改--path /var/www/...使用1.9.2@my_gemsetrvm中的gemset?

也许吧,因为我正在使用几个环境进行部署(登台,制作......).所以这是我的deploy.rb

# RVM bootstrap
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'capistrano/ext/multistage'
require 'bundler/capistrano'
require 'rvm/capistrano'

set :rvm_bin_path, "/usr/local/rvm/bin"
set :rvm_type, :system

set :stages, %w(production staging)
set :default_stage, "staging"

set :application, "my_app"
set :repository,  "gitosis@mydomain.org:my_app.git"

set :scm, :git

set :user, "my_deploy_user"

set :use_sudo, false

set :ssh_options, { :forward_agent => true }

default_run_options[:pty] = true

namespace :deploy do
  task :start do
  end
  task :stop do
  end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
end
Run Code Online (Sandbox Code Playgroud)

在config/deploy/staging.rb中

set :rails_env, "staging"
set :rvm_ruby_string, '1.9.2@my_gemset'
set :deploy_to, "/var/www/my_app"

role :web, "stage.mydomain.de"                          # Your HTTP server, Apache/etc
role :app, "stage.mydomain.de"                          # This may be the same as your `Web` server
role :db,  "stage.mydomain.de", :primary => true # This is where Rails migrations will run
Run Code Online (Sandbox Code Playgroud)

也许有人可以帮助我.

Dwa*_*rde 7

capistrano-bundler 1.1.2允许您从bundler参数中删除--path标志,并将gem安装到指定的gemset.

我的配置到底是什么样的:

set :rvm_type, :system
set :rvm_ruby_version, "2.0.0-p353@#{fetch(:application)}"

set :bundle_path, nil
set :bundle_binstubs, nil
set :bundle_flags, '--system'
Run Code Online (Sandbox Code Playgroud)


Hec*_*lot 5

你们都在使用bundler和rvm集成.Rvm将确保它使用正确的ruby(便于管理rubies),bundler会将所有gem分成shared/bundle目录.这是生产的捆绑包默认设置.我相信这是一个很好的方式来设置它,也因为它适用于开箱即用的乘客,从每个应用程序中分离宝石,并有rvm处理红宝石.

如果您真的想使用RVM进行宝石分离,最好从达西开始这篇博文(这适用于乘客).正如您所看到的,在完成这项工作时需要付出一些努力,但这是可能的.