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

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

问题描述

在对 Heroku 进行一些更改后,我注意到有关 vendor/bundle 的警告(请参阅下面的警告).

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

如果根据警告应该从 Git 跟踪中删除"该目录的用途是什么?

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

为什么 vendor/bundle 在默认情况下不被 Rails 自动.gitignore?

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

我应该运行 bundle pack 吗?(真的是捆绑包??)

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

bundle pack 的优缺点是什么(相对于 developmentproduction)?

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

为了让这更令人困惑,有一篇由 Ryan McGeary 撰写的热门博客文章,标题为 "Vendor Everything" 仍然适用 强烈主张运行 bundle install --path vendorecho 'vendor/ruby' >>.gitignore 并通过运行 bundle packagevendor/cache 中打包 gem.如果您能就我的其他问题对此有所了解,我们将不胜感激.

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.

谢谢.

-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)
       ...

推荐答案

如果您的项目中有 vendor/bundle 目录,那么在某些时候 您必须使用 --path vendor/bundle 运行 bundle 命令代码>参数.这会将您项目的所有 gem(在 Gemfile 中列出)的文件加载到本地项目的 vendor/bundle 目录中,而不是加载到系统 gem 位置.您可以这样做以将项目的 gem 与任何其他项目完全隔离.

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 擅长解决所有依赖关系,因此没有必要使用 --path,但有些人选择这样做是因为他们希望将他们的 gem 与他们的项目分开并组织起来.这也意味着本地机器上的 bundler 的设置方式与 Heroku 使用 bundler 的方式相同.

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.

使用此选项,您仍然每次都从 rubygems 服务器下载所有宝石你运行 bundle 命令.

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

bundle package 更进一步,实际下载了原始文件来自 rubygems 的 gem 文件并将它们缓存到 vendor/cache 目录中.这意味着您不再需要连接到 rubygems 来运行 bundle 命令,因为它将使用打包文件作为源.如果您需要更新 gem 版本,那么它需要连接到 rubygems 以在第一次请求时收集新版本.使用 bundle package 当然需要额外的磁盘空间,这取决于具体情况,这可能是也可能不是问题.每次推送到 Heroku 时,它还会增加部署时间和带宽要求.

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 每次 git push 时都会运行 bundle 命令,读取你的 Gemfile.lock 并安装应用程序所需的 gems.默认情况下使用 --path vendor/bundle 选项.这样每个应用程序都有一组与 Heroku 上所有其他应用程序分开的 gem 文件.如果您的源代码管理中有 vendor/bundle 目录并将其推送到 Heroku,那么您可以看到存在重大冲突的可能性,因为它然后尝试将 gems 加载到 vendor/bundle 目录已经存在.如果它被推送,那么 Heroku 会在运行 bundle install 之前删除 vendor/bundle 目录以删除这些潜在的冲突.如果是这种情况,那么您将 vendor/bundle 置于版本控制之下将浪费部署时间和带宽,最好将其添加到您的 .gitignore.

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.

如果您想在 Heroku 上完全控制您的 gem,请使用 bundle package 命令并确保 vendor/cache 目录处于源代码控制之下.当 Heroku 运行 bundle install 时,它将使用 vendor/cache 的内容作为 gem 源,而不是使用 rubygems.这是否有用取决于个人喜好、您正在构建的应用程序类型以及更新 gem 的频率.Ryan McGeary 的帖子建议使用 bundle package 以防旧 gem 在将来的某个时候变得不可用.对于不定期更新的项目/应用来说,这似乎是一个更大的问题.

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.

从我的角度来看,我通常使用 --path vendor/bundle 来使我的本地设置尽可能接近 Heroku 的设置.我将 vendor/bundle 放入我项目的 .gitignore 文件中,我不打包 gems,因为我的项目更新相对定期.

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 有一个非常有限的 .gitignore 文件.您实际上需要自己构建所需的内容,这就是默认情况下不包含 vendor/bundle 的原因.

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.

我假设 Heroku 的意思是 bundle package 当他们说 bundle pack 时.

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

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

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