2011-11-25 84 views
0

我刚刚开始使用git-deploy代替capistrano,问题是虽然我在服务器上使用rvm,但两者混合不好。git-push和rvm问题

这里是git的部署链接我使用的: https://github.com/mislav/git-deploy

我使用红宝石通过RVM用户安装在我的服务器上1.9.2-P180。当我运行git push和git deploy在部署中运行我的脚本时,它会在vendor/.bundle而不是我的gems目录中安装gem:/home/vps/.rvm/gems

这是我的deploy/after_push脚本

#!/usr/bin/env bash 
set -e 
oldrev=$1 
newrev=$2 

run() { 
    [ -x $1 ] && $1 $oldrev $newrev 
} 

echo files changed: $(git diff $oldrev $newrev --diff-filter=ACDMR --name-only | wc -l) 

umask 002 

git submodule init && git submodule sync && git submodule update 

export GEM_HOME=/home/vps/.rvm/gems/ruby-1.9.2-p180 
export MY_RUBY_HOME=/home/vps/.rvm/rubies/ruby-1.9.2-p180 
export GEM_PATH=/home/vps/.rvm/gems/ruby-1.9.2-p180:/home/vps/.rvm/gems/[email protected] 
export RUBY_VERSION=ruby-1.9.2-p180 
export PATH=/home/vps/.rvm/gems/ruby-1.9.2-p180/bin:/home/vps/.rvm/gems/[email protected]/bin:/home/vps/.rvm/rubies/ruby-1.9.2-p180/bin:/home/vps/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games 

export rvm_config_path=/home/vps/.rvm/config 
export rvm_path=/home/vps/.rvm 
export rvm_examples_path=/home/vps/.rvm/examples 
export rvm_rubies_path=/home/vps/.rvm/rubies 
export rvm_usr_path=/home/vps/.rvm/usr 
export rvm_src_path=/home/vps/.rvm/src 
export rvm_version=1.6.3 
export rvm_gems_path=/home/vps/.rvm/gems 
export rvm_ruby_string=ruby-1.9.2-p180 
export rvm_tmp_path=/home/vps/.rvm/tmp 
export rvm_lib_path=/home/vps/.rvm/lib 
export rvm_repos_path=/home/vps/.rvm/repos 
export rvm_log_path=/home/vps/.rvm/log 
export rvm_help_path=/home/vps/.rvm/help 
export rvm_environments_path=/home/vps/.rvm/environments 
export rvm_archives_path=/home/vps/.rvm/archives 

rvm use 1.9.2 

run deploy/before_restart 
run deploy/restart && run deploy/after_restart 

这里是我的部署/ before_restart

#!/home/vps/.rvm/rubies/ruby-1.9.2-p180/bin/ruby 
oldrev, newrev = ARGV 

def run(cmd) 
    exit($?.exitstatus) unless system "umask 002 && #{cmd}" 
end 

RAILS_ENV = ENV['RAILS_ENV'] || 'production' 
use_bundler = File.file? 'Gemfile' 
rake_cmd = use_bundler ? 'bundle exec rake' : 'rake' 

if use_bundler 
    bundler_args = ['--deployment'] 
    BUNDLE_WITHOUT = ENV['BUNDLE_WITHOUT'] || 'development:test' 
    bundler_args << '--without' << BUNDLE_WITHOUT unless BUNDLE_WITHOUT.empty? 

    # update gem bundle 
    run "bundle install #{bundler_args.join(' ')}" 
end 

if File.file? 'Rakefile' 
    num_migrations = `git diff #{oldrev} #{newrev} --diff-filter=A --name-only`.split("\n").size 
    # run migrations if new ones have been added 
    run "#{rake_cmd} db:migrate RAILS_ENV=#{RAILS_ENV}" if num_migrations > 0 
end 

# clear cached assets (unversioned/ignored files) 
run "git clean -x -f -- public/stylesheets public/javascripts" 

# clean unversioned files from vendor/plugins (e.g. old submodules) 
run "git clean -d -f -- vendor/plugins" 

它不仅安装在供应商/ .bundle但安装它红宝石的系统版本是1.9.1,所以我不能用它与我的rvm版本是apache2正在运行的版本。我目前的所有工作都是手动ssh并在该目录中运行bundle install。

有没有更干净的方式做到这一点?

我是否必须在脚本文件中包含所有这些导出?

更新:

即使我手动进入目录并运行安装包,它把宝石为供应商/捆出于某种原因。

更新:

后进入我的before_restart以下

run "ruby -v" 
run "type ruby" 

我得到这样的结果:

ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux] 
ruby is /home/vps/.rvm/rubies/ruby-1.9.2-p180/bin/ruby 

我已经采取了bundler_args,但它仍然坚持在安装我的宝石在供应商/捆绑的红宝石1.9.1

回答

0

运行bundle install --deloyment故意places gems in the vendor目录。

你实际上已经安装了Ruby 1.9.1的可能性不大。如果你使用的是Debian派生的发行版,那么这是因为它实际上安装了1.9.2时,这个包被错误地命名为1.9.1。

否则我不确定为什么你的rvm use 1.9.2行不会生效。可能在before_restart脚本中执行run "ruby -v"并检查版本或run "type ruby"以检查其路径。