将2个rails应用程序组合到一个代码库中

时间:2021-05-21 23:33:12

Our company started out with a single product, a rails app backed by some java services, then decided they wanted another product that was initially considerably different than the first, but as time has gone on we've realized they are starting to converge, and making a code change to one requires a similar code change to the other for a new feature/bug fix. This is obviously becoming a pain.

我们公司开始使用单一产品,一些由一些Java服务支持的rails应用程序,然后决定他们想要另一种产品,这种产品最初与第一种产品大不相同,但随着时间的推移,我们已经意识到它们开始趋同,将代码更改为一个需要对另一个进行类似的代码更改以进行新功能/错误修复。这显然是一种痛苦。

In some cases we have gems that share some of this functionality but it goes beyond ruby into javascript, css etc..

在某些情况下,我们拥有共享一些此功能的宝石,但它超越了ruby到javascript,css等。

So I'm tasked with merging these two apps into one codebase. I think eventually we'd like it to be a single app with permission based role access but that will come much later.

所以我的任务是将这两个应用程序合并到一个代码库中。我认为最终我们希望它是一个具有基于权限的角色访问权限的单个应用程序,但这将会更晚。

My first thought to quickly put them together is to create two rails engines and share common libs between them. I think this is the quickest way to combine the code, find common sections and start sharing.

我第一次想到将它们快速组合在一起就是创建两个rails引擎并在它们之间共享公共库。我认为这是组合代码,查找常见部分和开始共享的最快捷方式。

My first problem though is how to route between the apps. One app uses a single domain name that never changes, the other app has many domains. Can someone suggest how I might route a particular request to a particular app so they can remain separate to start whilst sharing a common codebase of libs?

我的第一个问题是如何在应用程序之间进行路由。一个应用程序使用永远不会更改的单个域名,另一个应用程序具有许多域。有人可以建议我如何将特定请求路由到特定应用程序,以便在共享库的公共代码库时可以保持独立开始吗?

Or, if anyone has other suggestions as to a way to combine these apps I'm all ears.

或者,如果有人有关于组合这些应用程序的方法的其他建议,我会全神贯注。

They're both Rails 2.3.10 apps running JRUBY 1.5.3, but we're open to possibly upgrading to Rails3 if that would make things significantly easier or cleaner (ie with better Rack integration)

它们都是运行JRUBY 1.5.3的Rails 2.3.10应用程序,但我们可能会升级到Rails3,如果这会使事情变得更容易或更清晰(即更好的Rack集成)

I haven't done any Rack programming but never hurts to learn if that will make our lives easier.

我没有做任何Rack编程,但从来没有伤害过,如果这将使我们的生活更轻松。

2 个解决方案

#1


1  

Your idea of using engines is what I would suggest.

你建议使用引擎的想法。

For routing, I would handle it outside of Rails.

对于路由,我会在Rails之外处理它。

For instance, you would do the following in nginx:

例如,您将在nginx中执行以下操作:

server {
    # Match only one host.                                                      
    listen 80 default;
    server_name YOUR_SINGLE_APP_DOMAIN;

    location / {
        upstream YOUR_SINGLE_APP_RAILS;
    }
}


server {
    # Fall thru and match any other host.                                                      
    listen 80 default;
    server_name ~^.*$;

    location / {
        upstream YOUR_MULTI_DOMAIN_APP_RAILS;
    }
}

#2


2  

You should avoid sharing code on server level, best to do that would be building libraries including common code base and use them during development. Probably the best shoot would be using helpers as it is easiest way to provide modules that provide functionalities all over your code.

您应该避免在服务器级别共享代码,最好的做法是构建包括公共代码库的库,并在开发期间使用它们。可能最好的拍摄是使用帮助器,因为它是提供在代码中提供功能的模块的最简单方法。

Regarding rewriting functionalities to one application, choose that one with bigger set of ready code as a base. It should be possible to migrate code per method using web server supporting url rewriting. I thought of using apache with mod_rewrite. So the plan would be:

关于将功能重写为一个应用程序,请选择具有较大就绪代码集的应用程序作为基础。应该可以使用支持URL重写的Web服务器来迁移每个方法的代码。我想过用mod_rewrite来使用apache。所以计划是:

  1. Setup both applications to be accessible through one apache.
  2. 设置两个应用程序可通过一个apache访问。

  3. Chose one method that is similar in both and rewrite it in one application to support both applications requirements.
  4. 选择一种类似的方法,并在一个应用程序中重写它以支持两种应用程序要求。

  5. In apache add a mod_rewrite rule to redirect traffic to one application only on this action.
  6. 在apache中添加mod_rewrite规则,仅在此操作上将流量重定向到一个应用程序。

  7. Go to point two till everything is rewritten.
  8. 转到第二点,直到所有内容都被重写。

  9. Remove old application and adjust routing/mod_rewrite to use the one application
  10. 删除旧应用程序并调整routing / mod_rewrite以使用一个应用程序

You do not have to use apache, there should be other web servers supporting url rewriting.

您不必使用apache,应该有其他支持URL重写的Web服务器。

I was thinking of using this algorithm to rewrite our application to rails 3.0.

我正在考虑使用此算法将我们的应用程序重写为rails 3.0。

#1


1  

Your idea of using engines is what I would suggest.

你建议使用引擎的想法。

For routing, I would handle it outside of Rails.

对于路由,我会在Rails之外处理它。

For instance, you would do the following in nginx:

例如,您将在nginx中执行以下操作:

server {
    # Match only one host.                                                      
    listen 80 default;
    server_name YOUR_SINGLE_APP_DOMAIN;

    location / {
        upstream YOUR_SINGLE_APP_RAILS;
    }
}


server {
    # Fall thru and match any other host.                                                      
    listen 80 default;
    server_name ~^.*$;

    location / {
        upstream YOUR_MULTI_DOMAIN_APP_RAILS;
    }
}

#2


2  

You should avoid sharing code on server level, best to do that would be building libraries including common code base and use them during development. Probably the best shoot would be using helpers as it is easiest way to provide modules that provide functionalities all over your code.

您应该避免在服务器级别共享代码,最好的做法是构建包括公共代码库的库,并在开发期间使用它们。可能最好的拍摄是使用帮助器,因为它是提供在代码中提供功能的模块的最简单方法。

Regarding rewriting functionalities to one application, choose that one with bigger set of ready code as a base. It should be possible to migrate code per method using web server supporting url rewriting. I thought of using apache with mod_rewrite. So the plan would be:

关于将功能重写为一个应用程序,请选择具有较大就绪代码集的应用程序作为基础。应该可以使用支持URL重写的Web服务器来迁移每个方法的代码。我想过用mod_rewrite来使用apache。所以计划是:

  1. Setup both applications to be accessible through one apache.
  2. 设置两个应用程序可通过一个apache访问。

  3. Chose one method that is similar in both and rewrite it in one application to support both applications requirements.
  4. 选择一种类似的方法,并在一个应用程序中重写它以支持两种应用程序要求。

  5. In apache add a mod_rewrite rule to redirect traffic to one application only on this action.
  6. 在apache中添加mod_rewrite规则,仅在此操作上将流量重定向到一个应用程序。

  7. Go to point two till everything is rewritten.
  8. 转到第二点,直到所有内容都被重写。

  9. Remove old application and adjust routing/mod_rewrite to use the one application
  10. 删除旧应用程序并调整routing / mod_rewrite以使用一个应用程序

You do not have to use apache, there should be other web servers supporting url rewriting.

您不必使用apache,应该有其他支持URL重写的Web服务器。

I was thinking of using this algorithm to rewrite our application to rails 3.0.

我正在考虑使用此算法将我们的应用程序重写为rails 3.0。