将 Rails 2 应用程序移植到新服务器
在此过程中我还提出了几个其他问题,但我更清楚自己要做什么,所以我想我会问这个问题。
我继承了一个 Rails 2.2.2 应用程序,该应用程序当前在我有权访问的服务器上以生产形式运行。我试图将该应用程序移植到我的服务器、版本控制等。我首先尝试复制源代码并让它在 Rails 3 和最新版本的 gems 下运行,但事实证明这比我以为会是这样。看起来最好的解决方案是简单地使用当前系统正在使用的相同版本的 Rails 和其他 gem,并按原样移植应用程序。
所以我想知道最好的方法是什么?我可以将源代码放入我的版本控制系统中,并像现在一样设置 Capistrano 和 Passenger。问题是将所有宝石都放在同一版本中。我听说过冻结 Rails 和冻结 gem,但很多关于它的教程看起来有点过时。在当前运行的生产服务器上冻结 gem 是否安全,或者我应该获取 gem 及其版本的列表,然后将它们全部手动安装到我要移植到的新服务器上?
编辑:我按照tadman的建议设置了一个Gemfile,其中包含生产服务器上安装的所有gems和最新版本,但现在我陷入了版本控制混乱,例如:
Bundler could not find compatible versions for gem "ruby2ruby":
In Gemfile:
merb-action-args (= 1.0.8.1) depends on
ruby2ruby (>= 1.1.9)
ambition (= 0.5.4) depends on
ruby2ruby (1.1.8)
生产服务器有时会安装同一 gem 的多达 4 个版本,但 Bundler 似乎只想处理每个版本的一个版本。有没有一种简单的方法来解决这样的情况,或者是回到研究生产中的冻结宝石?
编辑2:我最终从除rails之外的所有gem中删除版本并进行捆绑安装
。到目前为止,即使所有版本并不完全匹配,它似乎仍然有效。
I've posted a couple other questions during this process, but I have a better idea of what I'm trying to do so I thought I'd ask about that.
I've inherited a Rails 2.2.2 application, which is currently running in production form on a server I have access to. I'm trying to port that application over to my server, version control, etc. I first tried to copy over the source code and get it running under Rails 3 and the latest versions of gems, but that's proved to be much more difficult than I thought it would be. It seems like the best solution is to simply use the same version of Rails and other gems that the current system is using, and port over the application as-is.
So I'm wondering what the best way to do that is? I can put the source in my version control system and set up Capistrano and Passenger the same way as they are now. The issue is getting all the gems over in the same version. I've heard about freezing Rails and freezing gems, but a lot of the tutorials on it look a bit outdated. Is it safe to freeze the gems on the currently-running production server, or should I just get a list of the gems and their versions and manually install them all on the new server I'm porting over to?
Edit: I followed tadman's suggestion and set up a Gemfile with all the gems and latest versions installed on the production server, but now I've gotten into a versioning mess with those, for example:
Bundler could not find compatible versions for gem "ruby2ruby":
In Gemfile:
merb-action-args (= 1.0.8.1) depends on
ruby2ruby (>= 1.1.9)
ambition (= 0.5.4) depends on
ruby2ruby (1.1.8)
The production server has sometimes up to 4 versions of the same gem installed, but Bundler seems to only want to handle one version of each. Is there an easy way to solve a situation like this, or is it back to looking into freezing gems in production?
Edit 2: I wound up removing versions from all gems except for rails and doing bundle install
. So far, it seems to be working even though all the versions aren't matched exactly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
切换到 Rails 3 可能会让人非常头疼,但打包 gems 的历史版本可能会容易得多。在某种程度上,通过 bundler 可以更轻松地实现这一点,您可以在
Gemfile< 中声明所需的特定版本/code> 适合您的应用程序。虽然这是 Rails 3 中使用的事实上的方法,但它与平台无关,并且可以在任何版本的 Rails 上用作分发机制。
您通常可以确定与
gem list
一起使用的 gem 版本,除非在config/environment.rb
中另有指定,否则会自动选择最新版本。将 gem 列表转换为Gemfile
很容易。Switching to Rails 3 might be a serious headache, but packaging up the historical versions of the gems can be significantly easier. To a degree this is made easier by bundler where you can declare the specific versions you need in a
Gemfile
for your application. While this is the de-facto method used in Rails 3, it is platform agnostic and can be used on any version of Rails as a distribution mechanism.You can usually determine the version of gems used with
gem list
as, unless otherwise specified inconfig/environment.rb
the most recent version is selected automatically. It is easy to transform a gem list into aGemfile
.