我的环境
Vanilla 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 任务来打包我的 gem 并将它们上传到我的开发和生产服务器。问题是当 Gemfile 包含 git 或路径 gem 时 rake 任务失败。Bundler 已经支持打包这些类型的 gem,它在我的终端上运行良好,但是在运行 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 包可以:
> 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运行bundle 包也可以:
> 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
但是 bundle 包在我的简单 rake 任务中执行时不起作用:
> 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)
我找不到这可能失败的原因。我一直在同一个环境中运行。我已经检查了这三种情况下的 bundle exec 文件是否相同(/usr/local/bin/bundle)。我没有痕迹或 rvm 或 renv 或类似的东西。还尝试在没有 bundle exec 的情况下运行任务和同样的问题。
提前感谢有关为什么会发生这种情况的任何提示。