让 bundler 为不同的平台使用不同的 gem [英] Make bundler use different gems for different platforms

查看:31
本文介绍了让 bundler 为不同的平台使用不同的 gem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我们的一个 Rails 2.3.8 应用程序升级到 Rails 3,但遇到了一个令人讨厌的捆绑程序和部署问题.我在 Windows 机器上开发应用程序,但生产环境运行的是 Ubuntu Linux.现在,我的问题是 bundler 在生产环境中忽略了 mysql gem,而Passenger 吐出:"!!! 缺少 mysql gem.将其添加到您的 Gemfile 中: gem 'mysql', '2.8.1'"

I'm working on upgrading one of our Rails 2.3.8 apps to Rails 3, and have run into an annoying problem with bundler and deployment. I develop the application on a Windows machine, but the production environment is running Ubuntu Linux. Now, my problem is that bundler is ignoring the mysql gem in the production environment, and Passenger spits out: "!!! Missing the mysql gem. Add it to your Gemfile: gem 'mysql', '2.8.1'"

这是我的Gemfile:

# Edit this Gemfile to bundle your application's dependencies.
# This preamble is the current preamble for Rails 3 apps; edit as needed.
source 'http://rubygems.org'

gem 'rails', '3.0.0'
gem 'net-ldap', :require => 'net/ldap'
gem 'highline', :require => 'highline/import'
gem 'mysql', '2.8.1'
gem 'net-ssh', :require => 'net/ssh'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :development, :test do
  gem 'fakeweb', :require => 'fakeweb'
  gem 'flexmock', :require => 'flexmock/test_unit'
end

如您所见,指定了 mysql gem.但是,在部署时,bundler 会忽略它.为什么?原因是Bundler生成如下Gemfile.lock(只包含相关部分):

As you can see, the mysql gem is specified. However, when deploying, bundler ignores it. Why? The reason is that Bundler generates the following Gemfile.lock (only relevant parts included):

....
mime-types (1.16)
mysql (2.8.1-x86-mingw32)
net-ldap (0.1.1)
....

请注意,它包含特定于平台的 gem.这显然不是我想要它做的,因为在 Linux 下运行时该 gem 不适合(并且似乎被忽略).

Notice that it includes the platform specific gem. This is obviously NOT what I want it to do, as that gem is not suitable (and appearently ignored) when running under Linux.

那么,Bundler 有没有办法解决这些问题?或者我是否必须记住每次在我的开发机器上运行 bundle install 时手动更改生成的 Gemfile.lock 中的 mysql gem 版本?

So, does Bundler come with any way to deal with these issues? Or do I have to remember to manually change the mysql gem version in the generated Gemfile.lock every time I run bundle install on my development machine?

先谢谢你!

更新

似乎 bundler 团队已经意识到这个问题.>

It seems like the bundler team is aware of this issue.

推荐答案

这是一个已知问题捆绑器.解决方法是:

This is a known issue in Bundler. The workarounds are either:

  • 在与您的生产环境足够相似的系统上生成 Gemfile.lock,以获得与您的生产平台相匹配的结果.实际上,这意味着如果您的生产系统是 Windows,您只能在 Windows 上生成 Gemfile.lock 文件.
  • 根本不要提交 Gemfile.lock 文件,并在部署时确定对生产机器的依赖关系(bundle install 没有 --deploy).虽然一般不推荐,但在修复错误之前,这是一种常用的解决方法.例如,这是 Heroku 提供的推荐解决方案.
  • 切换到 JRuby,它在 Windows 和 Linux 上都具有相同的平台字符串 (java).我不认真推荐这个,但我相信它会解决问题.
  • 修复 Bundler 源代码中的问题,即帮助 Bundler 团队修复错误.:)
  • Generate a Gemfile.lock on a system similar enough to your production environment that you get results that match your production platform. Effectively, that means you can only generate the Gemfile.lock file on Windows if your production system is Windows.
  • Don't commit a Gemfile.lock file at all, and determine dependencies on the production machine at deploy time (bundle install without --deploy). While not recommended in general, this is an often-used workaround until the bug is fixed. For example, this is the recommended solution offered by Heroku.
  • Switch to JRuby, which would have the same platform string across both Windows and Linux (java). I don't recommend this seriously, but I believe it would fix the problem.
  • Fix the problem in the Bundler source code, i.e., help the Bundler team fix the bug. :)

这篇关于让 bundler 为不同的平台使用不同的 gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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