使捆绑器将不同的gem用于不同的平台 [英] Make bundler use different gems for different platforms

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

问题描述

我正在将一个Rails 2.3.8应用程序升级到Rails 3,并且在捆绑程序和部署方面遇到了令人讨厌的问题。我在Windows机器上开发应用程序,但是生产环境正在运行Ubuntu Linux。现在,我的问题是捆绑程序在生产环境中忽略了 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生成以下 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是否以任何方式提供处理这些问题?还是我必须记得每次在开发机上运行捆绑安装时都在生成的 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?

谢谢!

更新

似乎打包程序团队知道此问题

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

推荐答案

这是 Bundler中的已知问题。解决方法是:


  • 在与生产环境足够类似的系统上生成Gemfile.lock,从而获得与生产平台匹配的结果。实际上,这意味着,如果您的生产系统是Windows,则只能在Windows上生成Gemfile.lock文件。

  • 完全不要提交Gemfile.lock文件,并确定对生产机器在部署时(捆绑安装而没有-部署)。虽然通常不建议这样做,但这是解决该错误之前的一种常用解决方法。例如,这是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. :)

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

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