-

How I’ve setup Git for continuous deployment on a PHP project

I’ve been amazed with git’s powers lately. After using svn, bzr and hg, I can understand why there is so much talking about git.

Let me talk about this php project. It’s been built by 3 dev and a designer, versioned under SVN.

WHAT?! Is it about GIT or SVN?

That’s one of the reasons I’ve been amazed with Git. I got a few problems with the integration, so there are some tips:

  • From time to time run ‘git fsck’ to check your expository’s health
  • Some times, ‘git commit —amend’ require you to rebase your project before commiting it to SVN.
  • Never use ‘git checkout —force’! I lost half of my code doing it ):
  • Listen to what Git says. Don’t skip the messages about what is happening. I broke all my object database once trying to pull changes from the SVN without reading the messages.

Let me introduce the problems that I solved with Git and RSync

After a lot of local testing, the team gave me the instruction to deploy the project every day at 5:00pm on the outside testing environment.

So, for 3 days at 5:00pm a had task to upload everything using FTP, change the configuration files and check the system. All those .snv folders, images and stuff were such slow.

It was boring!

I decided to give a try to Git-Svn and set up a deploy branch to let the configurations ready to deploy. The .svn folders were gone and the problem was solved, right?

No, it was slow still ):

On the other day, the project migrated to another host. I was now on beta stage. And now the server has ssh. I got a smile on my face (:

RSync: It’s really fast!

With the deploy branch set up with the correct configurations, some continuous merges and a small bash script, the continuous deployment was ready to go.

The rule: Master is good and always can be deployed.

The steps:

  1. ssh-copy-id user@host #we don’t want that boring password prompt
  2. write deploy.sh¹
  3. run it and be happy

Now, every change made on the project are almost instantly on production.

You should give a try to those “native” tools on *nix some times (:

¹