git-push和rvm问题

时间:2011-11-25 08:16:59

标签: ruby-on-rails-3 rvm

我刚刚开始使用git-deploy而不是capistrano,问题是虽然我在我的服务器上使用rvm并且两者混合不好。

以下是我正在使用的git-deploy的链接: https://github.com/mislav/git-deploy

我在通过rvm为用户安装的服务器上使用ruby 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/ruby-1.9.2-p180@global
export RUBY_VERSION=ruby-1.9.2-p180
export PATH=/home/vps/.rvm/gems/ruby-1.9.2-p180/bin:/home/vps/.rvm/gems/ruby-1.9.2-p180@global/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

这是我的deploy / 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"

它不仅将它安装在vendor / .bundle中,而且还为系统版本的ruby安装了1.9.1,因此我无法将其用于运行apache2的rvm版本。我目前解决的所有问题是手动ssh并在该目录中运行bundle install。

有更清洁的方法吗?

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

更新:

即使我手动进入目录并运行bundle install,它也会出于某种原因将gem放入vendor / bundle。

更新

在我的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,但它仍然坚持在ruby 1.9.1的vendor / bundle中安装我的宝石

1 个答案:

答案 0 :(得分: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"以检查其路径。