hillel hillel - 1 year ago 75
PHP Question

Deploying multiple applications into a single tree with Capistrano and Git

I'm trying to deploy a PHP website using Capistrano. The website is composed of 4 components (frontend code and 3 web-services), each stored in its own git repository. I want to deploy all 4 components into a single tree structure (see below), so that switching between website versions would be as simple as moving the "current" link.

I see that by default a Capistrano deployment is designed to deploy a single repository. If I understand it correctly, even using something like Caphub won't help me, since the 4 components would be deployed into 4 different trees making rollback to a specific point in time a cumbersome process.

Is there a way to get the configuration below using Capistrano? What's the best practice for this situation?

| current/
| releases/
| | <timestamp/>
| | | frontend/
| | | webservice-1/
| | | webservice-2/
| | | webservice-3/
| | <timestamp/>
| | | frontend/
| | | webservice-1/
| | | webservice-2/
| | | webservice-3/
| shared/


Wound up using a submodules solution as suggested in the accepted answer. I created a website repository holding the 4 submodules and a website-deploy repository where I keep the capistrano deployment files. I wrote a simple shell script to save me the trouble of updating the submodules on every deploy (quite a cumbersome process!). To deploy I run the script (source below) and then run "cap deploy".


git clone gitserver:path_to_git_repositories/website.git cloned
cd cloned
git submodule init
git submodule update
git submodule foreach git pull origin master # updating all modules to the current code in the master branch
git submodule foreach git add .
git commit -a -m "Updating submodules"
git push origin master
cd ..
rm -rf cloned

Answer Source

I had very similar problem when I was deploying rails application and one webservice. I decided to use git submodules, and it should solve all your problems.

You just need to create one main git repository that will add frontend and all webservices as submodules. Then in capistrano you just point to this main repository and set git_enable_submodules to 1.

Then you can develop all 4 components separately and when you want to deploy you just update submodules to correct points and commit main repository. This approach should give exactly this directory layout as you presented and should make it easy to rollback.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download