ruby-bundle包在rake任务中运行时失败

前端之家收集整理的这篇文章主要介绍了ruby-bundle包在rake任务中运行时失败前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的环境

香草Ubuntu 12.10,没有rvm或renv.

> gem --version
1.8.23

> ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]

> bundle --version
Bundler version 1.2.1

我的问题

我有一个rake任务来打包我的宝石并将它们上传到我的开发和生产服务器.问题是当Gemfile包含git或path gems时,rake任务失败. Bundler已经支持这些类型的宝石的包装,它在我的终端上工作得很好但是在运行rake任务时失败了,我找不到原因.

我的佣金任务

> cat lib/tasks/upload.rake

namespace :deploy do
  desc "Package all gems and upload to remote server"
  task :upload => [:environment] do |t,args|
    if ! system("bundle package --all")
      raise "TOTAL FAIL"
    end

    # Magic method to upload vendor/cache to remote server
  end
end

我的尝试

在终端中运行捆绑包工作:

> bundle package --all
....
Using bson (1.7.0) 
Using bson_ext (1.7.0) 
Using cancan (1.6.8) from git://github.com/ryanb/cancan.git (at /home/ryujin/Projects/rails/Encluster4/vendor/cache/cancan-4dcd54459482) 
Using carrierwave (0.7.0) 
Using coffee-script-source (1.4.0) 
....
Updating files in vendor/cache
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Updating files in vendor/cache

使用irb运行捆绑包也可以:

> irb
irb> system("bundle package --all")
...
Using ansi (1.4.3) 
Using bson (1.7.0) 
Using bson_ext (1.7.0) 
Using cancan (1.6.8) from git://github.com/ryanb/cancan.git (at /home/ryujin/Projects/rails/Encluster4/vendor/cache/cancan-4dcd54459482) 
Using carrierwave (0.7.0) 
Using coffee-script-source (1.4.0) 
...
Updating files in vendor/cache
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Updating files in vendor/cache
=> true

但是在我的简单rake任务中执行时,bundle package不起作用:

> bundle exec rake deploy:upload
Updating files in vendor/cache
Could not find cancan-1.6.8.gem for installation
rake aborted!
TOTAL FAIL

Tasks: TOP => deploy:upload
(See full trace by running task with --trace)

我发现没有理由为什么会失败.我一直在相同的环境中运行.我已经在所有三种情况下检查了捆绑exec文件是否相同(/usr/local / bin / bundle).我没有痕迹或rvm或renv或类似的东西.还试过没有bundle exec运行任务和同样的问题.

提前感谢任何关于为什么会发生这种情况的提示.

解决方法

我遇到了同样的麻烦.
我检查了环境变量,发现捆绑器修改了RUBYOPT:
$bundle exec env > benv.txt
$env > env.txt
$diff -u env.txt benv.txt
--- env.txt 2012-12-05 17:13:10.000000000 +0400
+++ benv.txt  2012-12-05 17:13:07.000000000 +0400
@@ -72,4 +72,8 @@
 CDPATH=.
 install_flag=1
 rvm_hook=
-_=/usr/bin/env
+_=/Users/denis/.rvm/gems/ruby-1.9.3-p327@global/bin/bundle
+_ORIGINAL_GEM_PATH=/Users/denis/.rvm/gems/ruby-1.9.3-p327:/Users/denis/.rvm/gems/ruby-1.9.3-p327@global
+BUNDLE_BIN_PATH=/Users/denis/.rvm/gems/ruby-1.9.3-p327@global/gems/bundler-1.2.3/bin/bundle
+BUNDLE_GEMFILE=/Users/denis/src/my-project/Gemfile
+RUBYOPT=-I/Users/denis/.rvm/gems/ruby-1.9.3-p327@global/gems/bundler-1.2.3/lib -rbundler/setup

所以,解决方法我这样做:

system %Q(/usr/bin/env RUBYOPT= bundle package)

希望这可以帮助!

原文链接:https://www.f2er.com/ruby/268132.html

猜你在找的Ruby相关文章