Rails 3的“捆绑安装”和“捆绑安装-部署”两者都可以正常工作,只是第二个只是使用更多的磁盘空间? [英] Rails 3's "bundle install" and "bundle install --deployment" both work well except the 2nd one just uses more disk space?

查看:34
本文介绍了Rails 3的“捆绑安装”和“捆绑安装-部署”两者都可以正常工作,只是第二个只是使用更多的磁盘空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎在开发机器上(例如在Macbook上),如果我们使用 bundle install --deployment ,则所有gems都将安装到 vendor / bundle 文件夹,如果我们有多个Rails 3项目(某些项目仅用于测试Rails 3),它只会使用更多的磁盘空间。如果不是-deployment ,则gem将位于常规文件夹中,而不是在项目文件夹中,因此可以在各个项目之间共享。



另一件事是,我们是否需要将供应商/捆绑包下的所有文件添加到存储库中并推动它?看来,如果这样做,我们只会阻塞存储库,因为如果不这样做,所有适当的gem将通过 bundle install 使用所有指定的gem安装仍然在 Gemfile.lock 中。 ( Gemfile.lock 是存储库中的一个小文件)。

解决方案

是!是的。



当您使用-deployment 标志时,Bundler确保您需要的所有宝石都是 vendored ,即它们被复制到应用程序的文件夹结构的预定位置(按惯例,在Rails中恰好是 vendor / bundle )这对两件事有好处。



首先,如果权限有限,无法在部署机器中安装gem,则让您拥有应用内所需的所有gem。



第二,如果您想破解gems中的实际代码,可以对供应商的副本执行此操作,而不影响系统gem。您所做的更改只会影响您正在处理的应用程序。



这种供应方式曾经有另一种用途,那就是确保您使用的是特定版本宝石,并且即使系统宝石已升级到会破坏应用程序的更高版本,您的应用程序仍能正常工作。但是,由于Bundler本身使该用例在大多数情况下已过时,因为它可以自动安装和引用特定版本的gem。 Gemfile.lock 只是所需宝石的列表。如果您出售宝石,则它们将被全力复制到您的应用中。



因此,我建议您不要出售宝石(这也意味着不要使用-deployment 标志),除非您有上述原因之一。


It seems that on development machines (like on the Macbook), if we use bundle install --deployment, all the gems will be installed into the vendor/bundle folder and it just use more disk space if we have multiple Rails 3 projects (some project just for testing Rails 3). If it is not --deployment, then the gems will be in the "generic" folder instead of inside the project folder, and so can be shared across projects. Is this true?

Another thing is, do we need to add all files under vendor/bundle to our repository and push it? It seems that if we do it, we just jam up the repo, because if we don't, all the appropriate gems will be installed by bundle install using all the gems specified in Gemfile.lock anyway. (The Gemfile.lock is a small file in the repo). Is this true too?

解决方案

Yes! True.

When you use the --deployment flag, Bundler makes sure that every gem you need is vendored i.e. they are copied to a predetermined place your application's folder structure (which happens to be vendor/bundle in Rails by convention) This is good for two things.

First if you have limited permissions that prevent you from installing gems in your deployment machine, then let you have all the gems needed within your app.

Second, if you want to hack away at the actual code in the gems, you can do so on your vendored copies without affecting the system gems. The changes you make will only affect the application you're working on.

This vendoring approach used to have another use, that is making sure that you are using the specific version of a gem, and your application would keep working even if the system gems were upgraded to a higher version that would break your app. However, Bundler itself made this use case mostly obsolete, as it automated the installation and referencing of specific versions of gems.

And yes, vendoring would bloat your app's code. Gemfile.lock is just a list of the required gems. If you vendor your gems, they get copied into your app with all their might.

So, I recommend you don't vendor your gems (that also means don't use the --deployment flag) unless you have one of the reasons above.

这篇关于Rails 3的“捆绑安装”和“捆绑安装-部署”两者都可以正常工作,只是第二个只是使用更多的磁盘空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆