Search code examples
phpgitamazon-web-servicescapistrano

Deploy code on multiple servers from same branch


This is my situation.

I have a project that has always been deployed on a single server. Our situation has changed, now the project is deployed on several servers internationally. We still have only one branch that we deploy so far. The project now contains generic code but also country-specific code.

I want to change that but I do not know how. There are two possibilities for me. The first is to create one branch per country from my origin one. But before that I have to do some cleaning work to isolate the generic code and leave that specific code for each country. The disadvantage of this solution is that people can quickly be lost between many branches.

enter image description here

The second solution is to keep a single branch but I must update the code to create generic controllers that will redirect to specific controllers depending on the country.

enter image description here

I am interested, if you think there are other solutions to remedy this problem.


Solution

  • Keep in mind that git is a source control tool, and structures like branches are intended to solve source control problems. Someone long ago observed that because git has a protocol for transmitting changes to a remote repo, it could be used as a deployment tool; and in very simple cases, it can do that job well. But too often people start off with this, and then as their build/deployment requirements become more complex they expect git to scale with that. Which it probably would, if it were a build and deployment tool. But it's not.

    The downside to "branch per country" is not merely that people could get lost among the branches. The bigger downside is that keeping the common code in sync across all branches will be tedious and, ultimately, will probably not happen reliably.

    Your other solution is perhaps better, but it treats identification of country as a dynamic run-time decision, when in fact it could be decided at deployment time (since clearly a given deployed instance is either always in country-1, or always in country-2, or ...).

    Why not use build and deployment tools that can support multiple configurations, so that you can use a single code base and let the tools construct the correct version of the site for any given server?