How to tell Bundler to use gems installed systemwide (production deployment)?

核能气质少年 提交于 2019-12-05 07:13:28

问题


When deploying a Rails app with Capistrano, I want Bundler to install gems to shared/bundles dir ONLY IF it can't find gems installed systemwide already. How do I do it?

For example, if I have a pg gem v 0.14 already installed on the system, I want Bundler to use it and not build and install a new one into shared/bundles dir of my application.

I'm using Ubuntu Server and RVM is installed for multiple users.


回答1:


Bundler allows using shared(rubygems) and vendored(bundler) gems, by default bundler/capistrano is configured with:

set :bundle_flags, "--deployment --quiet"

which forces vendored gems only,

you can switch back to shared gems with explicit:

set :bundle_flags, "--system --quiet"

to still install in vendor but use shared gems too:

set :bundle_flags, "--path #{shared_path}/bundles --quiet"

if the deployment was already ran with --deployment(the default) then it could help to run the deploy once with:

set :bundle_flags, "--no-deployment"



回答2:


This is actually a feature of Bundler, essentially it's dependency isolation – you don't want your app depending on an outside, system gems like this. Updating the system gem could then have a impact on running applications.

If you're already using capistrano you should be using require "bundler/capistrano" in your script which will install them in shared/bundles anyway. You could look into packaging before hand as well: http://gembundler.com/v1.2/bundle_package.html



来源:https://stackoverflow.com/questions/14836119/how-to-tell-bundler-to-use-gems-installed-systemwide-production-deployment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!