我正在使用 Capistrano 将 Ruby on Rails 应用程序部署到服务器。一切运行正常,直到调用 bundle install 时,我收到错误“您的 vendor/cache 目录中似乎缺少一些 gem。”
导致此错误的原因是 Capistrano 正在从中克隆的 git 存储库的 vendor/cache 目录中签入了一些 gem。我知道最好的方法是清理 git 存储库,但由于这对我来说不是一个选择,所以我想让 Capistrano 在 git clone 之后但在调用 bundle 之前删除远程服务器上的 vendor/cache 目录。我手动运行了这些步骤,发现通过手动删除目录,bundle 可以正确执行,但我似乎无法弄清楚如何让 Capistrano 执行删除操作。
以下是我的 deploy.rb 文件中的相关片段:
after "deploy:update_code" do
run "rm -rf #{release_path}/vendor/cache"
end
after "deploy:update_code", "bundle:install"
以下是命令行输出
executing `deploy:update_code'
executing locally: "git ls-remote my_git_repository HEAD"
command finished in xxxms
* executing "git clone [snipped for brevity]
servers: ["my_server"]
[my_server] executing command
** [my_server :: out] Error reading response length from authentication socket.
** [my_server :: out]
command finished in xxxms
* executing `deploy:finalize_update'
triggering before callbacks for `deploy:finalize_update'
* executing `bundle:install'
* executing "[snipped for brevity] bundle install [snipped for brevity]"
servers: ["my_server"]
[my_server] executing command
** [out :: my_server] Some gems seem to be missing from your vendor/cache directory.
** [out :: my_server]
** [out :: my_server] Could not find gem-version in any of the sources
** [out :: my_server]
command finished in xxxms
它似乎run "rm -rf #{release_path}/vendor/cache"
从未运行过。我使用的命令正确吗?还有其他我应该怎么做的想法吗?
答案1
我想知道这是否是任务运行顺序的问题;也许可以尝试以下方法?
task :clean_vendor_cache do
run "rm -rf #{release_path}/vendor/cache"
end
before "bundle:install", "clean_vendor_cache"