捆绑器可以在rsync部署中使用? [英] can bundler be used in rsync deployments?

查看:92
本文介绍了捆绑器可以在rsync部署中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不运行 bundle install ...的情况下使用Bundler的Gemfile部署Rails3应用程序,即仅将Rails项目目录复制到Apache /乘客?

Can you deploy a Rails3 app using Bundler's Gemfile WITHOUT running bundle install... i.e. just by copying a rails project directory to the appropriate dir within Apache/Passenger?

因此,我们有一个遗留环境,该环境是为Ruby1.8.6 / Rails2时间段内的内部项目设计的,它取决于复制本地轨道目录到Apache / Passenger下的网络安装。虽然此部署模型在Rails2(使用冻结的宝石等)上可以很好地工作,但对于带有Bundle的Rails3,它却以许多痛苦的方式中断了。

So, we have a legacy environment that was designed for internal projects during the Ruby1.8.6/Rails2 timeframe and it depends on copying your local rails directory to a network mount under Apache/Passenger. While this deployment model worked fine for Rails2 (with frozen gems, etc.), it breaks in many painful ways for Rails3 with Bundler.

特别是,我看到了gem即使在部署到:production时,:test和:development组中gem的依赖关系错误。我发现以下SO帖子起初很有帮助:

Specifically, I'm seeing gem dependency errors for gems in :test and :development groups even when deploying to :production. I found the following SO post helpful at first:

  • bundler incorrectly trying to install "development" and "test" group gems in production

所以我执行了捆绑安装-不进行测试开发在我的本地计算机上,然后尝试将.bundle / config从我的目录手动复制到网络目录,但这没有用。 Bundler仍尝试加载排除的gem。

So I executed bundle install --without test development on my local and then tried to manually copy .bundle/config from my directory to the network dir, but that didn't work. Bundler still tried to load the excluded gems.

这对我们来说很痛苦,因为我们没有在这些服务器上安装gem的管理员权限(即,我们不允许以任何形式运行捆绑安装)。同样,管理员也不想每5分钟部署一次我们的应用程序,因为这是一个内部原型站点,而不是一个外部生产站点。他们也不想运行捆绑安装,因为他们想严格控制在所有应用程序中部署了哪些gems-例如,某些应用程序仍基于Rails2,而还没有使用Bundler,所以如果安装了错误的gem,它们可能会损坏。

This is painful for us because we don't have admin privileges to install gems on these servers (i.e. we aren't allowed to ever run bundle install in any form). Likewise, the admins do not want to be bothered with deploying our apps every 5 mins since this is an internal prototyping site and not an external production site. They also don't want to run bundle install because they want tight control of which gems are deployed across all applications -- for example, some apps are still Rails2 based and don't use Bundler yet, so they may break if the wrong gem is installed.

有没有办法以被动/异步方式使用Bundler,或者我们应该重新设计吗?我们的环境允许开发人员通过capistrano或类似工具运行捆绑安装

Is there any way to use Bundler in a passive/rsync way, or should we just redesign our environment to let developers run bundle install via capistrano or some such?

帮助?

谢谢!

更新: 1/18 / 2012年:在进一步调查了:test和:development组错误的原因之后,我发现:在Rails应用获得机会进入 boot.rb <之前,Pusion Passenger实际上执行了 Bundle.setup()。 / code>。如果没有任何参数, setup()会检查所有gem依赖项,这意味着如果它在服务器上找不到gem,它会在Passenger中被炸毁,甚至无法获得机会加载Rails。

UPDATE: 1/18/2012: After investigating the reason for the :test and :development group errors some more, I discovered that Phusion Passenger actually executes Bundle.setup() before the Rails app gets a chance to in boot.rb. Without any arguments, setup() checks all gem dependencies, which means if it doesn't find a gem on the server, it will blow up in Passenger before it even gets a chance to load Rails.

仅当您通过rsync或复制而不是运行 bundle install而不进行测试时,才会发生此特定错误 :development 在目标服务器上。大多数的Rails3应用程序都是通过Capistrano部署的,Capistrano会为您完成这一步骤,因此永远不会遇到这种特殊情况。

This particular 'bug' can only happen if you deploy via rsync or copy instead of running bundle install --without test:development on the target server. The majority of Rails3 apps are deployed with Capistrano, which does this step for you, and as such never encounter this particular edge case.

因此,我担心唯一的方法要让群组在gem文件中正常工作,请按预期使用捆绑安装。这意味着我们应该更改部署过程!

So I'm afraid the only way to get 'groups' to work correctly in your gem file is to use bundle install as intended. This means we should change our deployment process!

推荐答案

其他一些Rails开发人员,我正在讨论如何在Rails 3中有效冻结gem。我们制定了这个解决方案。这与@asymmetric提出的思路类似,但在某些关键方面有所不同。正如我后来从gemfile手册页中发现的那样,此方法也受到@indirect在 bundle install --deployment 中警告的相同限制,因为您的gem必须是纯红宝石(没有本机编译),或者必须在与舞台和产品服务器相同的架构上完成这些步骤。

Some other rails devs and I were discussing how to effectively freeze gems in Rails 3 and we worked out this solution. This is along the lines of what @asymmetric proposed, but different in some key ways. As I later discovered from the gemfile man page, this approach also suffers from the same limitation that @indirect warned of with bundle install --deployment, in that your gems must either be pure ruby (no native compilation), or these steps must be done on an identical architecture to your stage and prod servers.

好了,现在我们有了初步的准备顺便说一句,让我们来看看将一些宝石冻结到Rails 3中。

Ok, now that we have the preliminaries out of the way, let's see about "freezing" some gems into Rails 3...

首先,从一个干净的环境开始:

First, start with a clean environment:

$ rvm gemset use fresh
$ rvm gemset empty fresh
$ gem install rails
$ rails new strawman
$ cd strawman/

接下来,安装要使用的宝石:

Next, install the gem you want to use:

$ gem install condi

下一步,创建一个供应商/宝石目录并解压缩其中的宝石:

Next, create a vendor/gems directory and unpack the gem within it:

$ mkdir vendor/gems
$ cd vendor/gems
$ gem unpack condi
Unpacked gem: '/tmp/strawman/vendor/gems/condi-0.0.6'




可选

如果您的gem没有.gemspec文件(即规范是所包含的Rakefile构建的一部分),Bundler可能无法使用:path语句正确加载。在这种情况下,您必须使用以下命令从gem文件输出gemspec:

$ gem specification /tmp/condi-0.0.6.gem > condi-0.0.6/condi.gemspec


或者如果您已经在本地安装了gem,您可以:

Or if you already have the gem installed locally, you can:

$ gem specification condi -v=0.0.6 > condi-0.0.6/condi.gemspec

现在,更新 Gemfile 行:

gem 'condi', '0.0.6', :path => 'vendor/gems/condi-0.0.6'

注意:与:git不同,捆绑程序不会为指定为路径的gem编译C扩展。 [man gemfile] 因此,此 only 仅适用于纯红宝石宝石没有本地扩展!警告!

NOTE: "Unlike :git, bundler does not compile C extensions for gems specified as paths." [man gemfile] So this only works for pure ruby gems without native extensions! Be warned!

接下来,从您的宝石集中卸载该宝石:

Next, uninstall the gem from your gemset:

$ gem uninstall condi
Successfully uninstalled condi-0.0.6

并返回到轨道根环境,请尝试运行rails控制台:

And returning to the rails root environment, try to run the rails console:

$ cd ../..
$ rails c
Loading development environment (Rails 3.1.3)
1.9.3-p0 :001 > 

成功!!现在,您的纯红宝石宝石实际上已在Rails 3应用程序中冻结

Success!! Your pure ruby gem is now effectively frozen in a Rails 3 app.

这篇关于捆绑器可以在rsync部署中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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