供应商/包的目的是什么? Heroku告诉我删除它 [英] What is the purpose of vendor/bundle? Heroku tells me to remove it

查看:87
本文介绍了供应商/包的目的是什么? Heroku告诉我删除它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在推动对Heroku的一些更改后,我发现了一个关于 vendor / bundle 的警告(请参阅下面的 WARNING )。
$ b

这个目录的目的是什么,如果根据警告,应该从Git跟踪中删除它?



为什么选择isn 't vendor / bundle 自动 .gitignore '默认情况下由Rails引用?



我应该运行捆绑包吗? (它实际上是 bundle package ??)



捆绑包(相对于开发生产)?



为了使这更加令人困惑,Ryan McGeary撰写了一篇颇受欢迎的博客文章,标题为Vendor Everything仍然适用,强烈主张运行 bundle install --path vendor echo 'vendor / ruby​​'>> .gitignore 并通过运行 bundle package vendor / cache 中打包gem。任何与此相关的灯光都将不胜感激。



谢谢。

  -bash> git push production master 
...

-----> Heroku接收推送
-----> Ruby / Rails应用程序检测到
----->警告:删除`vendor / bundle`。
不支持`vendor / bundle`签入。请删除此目录
并将其添加到您的.gitignore。要使用Bundler供应您的宝石,请使用
`bundle pack`。
----->使用Bundler版本1.2.1安装依赖项
运行:bundle install - 无需开发:test --path vendor / bundle --binstubs bin / --deployment
使用rake(0.9.2.2)
使用i18n(0.6.0)
...


解决方案

如果你的项目中有 vendor / bundle 目录,那么在某个时候你必须用 - path vendor / bundle 参数运行 bundle 命令。这会将所有项目的gems文件(列在 Gemfile 中)加载到本地的 vendor / bundle 目录中项目而不是系统宝石位置。你可以这样做,以完全隔离项目的任何其他项目的宝石。

Bundler善于解析所有依赖关系,因此不需要使用 - path 但有些人选择这样做,因为他们希望保持他们的宝石与他们的项目分离和组织。这也意味着本地机器上的捆绑器的设置方式与Heroku使用捆绑器的方式相同。



使用此选项,您仍然可以从软件包命令时,都需要https://rubygems.org/> ruby​​gems 服务器。



捆绑软件包 将其更进一步,并实际从 ruby​​gems 下载原始gem文件并将它们缓存到 vendor / cache 目录。这意味着您不再需要连接到 ruby​​gems 来运行bundle命令,因为它将使用打包文件作为源文件。如果您需要更新宝石版本,则需要连接到 ruby​​gems 以在第一次请求时收集新版本。使用捆绑软件包当然需要额外的磁盘空间,这可能会或可能不会成为问题,具体取决于具体情况。每次推到Heroku时,它还会增加部署时间和带宽需求。



Heroku每运行一次命令当你 git push 时,阅读你的 Gemfile.lock 并安装应用程序工作所需的gem。默认情况下使用 - 路径vendor / bundle 选项。这样每个应用程序都有一套独立于Heroku上所有其他应用程序的gem文件。如果您的源代码管理中有 vendor / bundle 目录,并将其推送到Heroku,那么您可以看到存在显着冲突的可能性,因为它会尝试加载宝石到 vendor / bundle 目录中,该目录已经存在。如果它被推送,那么Heroku会在运行 bundle install 之前移除 vendor / bundle 目录以消除这些潜在的冲突。如果是这种情况,那么您将通过在版本控制下保留 vendor / bundle 来浪费部署时间和带宽,最好将它添加到中。 gitignore



如果你想完全控制Heroku上的gems,那么使用 bundle package 命令并确保供应商/缓存目录在源代码管理下。当Heroku运行 bundle install 时,它将使用 vendor / cache 的内容作为宝石源,而不是使用的rubygems 。这是否有用将取决于个人偏好,您正在构建的应用类型以及您更新宝石的频率。 Ryan McGeary的帖子表明,使用捆绑软件包非常有用,因为在未来的某个时间点,旧的宝石将无法使用。这对于那些不经常更新的项目/应用来说似乎是一个更大的问题。



在我看来,我通常使用 - -path vendor / bundle 使我的本地设置尽可能接近Heroku的设置。我将 vendor / bundle 放入我的项目的 .gitignore 文件中,并且我不 package gems,因为我的项目会相对经常更新。

Rails有一个非常有限的 .gitignore 文件。您有效地期望自己建立自己的需求,这就是默认情况下不包含 vendor / bundle 的原因。



我假设Heroku当他们说 bundle pack 时意味着 bundle package


Upon pushing some changes to Heroku, I noticed a warning about vendor/bundle (see WARNING below).

What is the purpose of this directory if, according to the warning, it should be "removed" from Git tracking?

Why isn't vendor/bundle automatically .gitignore'd by default by Rails?

Should I run bundle pack? (Is it actually bundle package??)

What are the pros and cons around bundle pack (relative to both development and production)?

To make this even more confusing, there's a popular blog post, by Ryan McGeary, titled "Vendor Everything" Still Applies that strongly argues for running bundle install --path vendor and echo 'vendor/ruby' >> .gitignore and packaging gems in vendor/cache by running bundle package. Any light shed on this relative to my other concerns would be greatly appreciated.

Thank you.

-bash> git push production master
...

-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> WARNING:  Removing `vendor/bundle`.
       Checking in `vendor/bundle` is not supported. Please remove this directory
       and add it to your .gitignore. To vendor your gems with Bundler, use
       `bundle pack` instead.
-----> Installing dependencies using Bundler version 1.2.1
       Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
       Using rake (0.9.2.2)
       Using i18n (0.6.0)
       ...

解决方案

If you have the vendor/bundle directory in your project then at some point you must have run the bundle command with the --path vendor/bundle argument. This will load the files for all your project's gems (listed in Gemfile) into the vendor/bundle directory in your local project rather than to a system gem location. You would do this to completely isolate a project's gems from any other project.

Bundler is good at resolving all dependencies so it isn't necessary to use the --path but some people choose to do so as they wish to keep their gems separate and organised with their project. It also means that bundler on your local machine is set up the same way that Heroku uses bundler.

With this option you are still downloading all gems from the rubygems servers every time you run the bundle command.

bundle package takes it a step further and actually downloads the original gem files from rubygems and caches them into the vendor/cache directory. This means that you no longer need a connection to rubygems to run the bundle command as it will use the packaged files as the source. If you need to update a gem version then it will need to connect to rubygems to collect the new version the first time it is requested. Using bundle package will of course require additional disc space which may or may not be an issue depending on the situation. It would also increase deploy time and bandwidth requirements every time you pushed to Heroku.

Heroku runs the bundle command every time you git push, reading your Gemfile.lock and installing the gems required for the application to work. By default the --path vendor/bundle option is used. This is so that each application has a set of gem files separate from all other apps on Heroku. If you have the vendor/bundle directory in your source control and you push it to Heroku then you can see that there is the potential for significant conflict as it then attempts to load gems into vendor/bundle directory which already exists. If it is pushed then Heroku removes the vendor/bundle directory before it runs bundle install to remove these potential conflicts. If this is the case then you will be wasting deploy time and bandwidth by leaving vendor/bundle under version control, it's better to add it to your .gitignore.

If you want complete control over your gems on Heroku then use the bundle package command and make sure that the vendor/cache directory is under source control. When Heroku runs bundle install it will use the contents of vendor/cache as the gem source rather than using rubygems. Whether this is useful or not will be a matter of personal preference, the type of app that you are building and how often you update your gems. The Ryan McGeary post suggests that using bundle package is useful in case an old gem becomes unavailable at some point in the future. This would appear to be a bigger issue to projects/apps which are not regularly kept up to date.

From my perspective, I generally use --path vendor/bundle to keep my local setup as close as possible to Heroku's. I put vendor/bundle into my project's .gitignore file, and I don't package gems, as my projects are updated relatively regularly.

Rails has a very limited .gitignore file. You are effectively expected to build up what you need yourself, which is why vendor/bundle is not included by default.

I assume that Heroku means bundle package when they say bundle pack.

这篇关于供应商/包的目的是什么? Heroku告诉我删除它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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