How do I deploy my CodeIgniter applications using Subversion
This little guide is intended to explain how do I update some of my applications running on development environment or production using Subversion and a simple hook.
This idea was based on the great article published time ago by Imran Nazar about automating deployment with Subversion.
Basically it updates a SVN repository in your development environment each time you commit a message with a signal string like *DEPLOY*. This assumes that you have a copy of your repository in your development environment.
The main difference is that instead of using svn update locally, I run a wget command that dispatch the svn update remotely.
So, this idea involves the following concepts and elements:
- a post-commit hook that checks for a *DEPLOY* signal and sends an email.
- a PHP script that executes svn update in the development server.
- svn-mailer (can be installed using yum install svn-mailer)
- a wget call to a remote script that runs svn update remotely.
The Remote Script
For remote script, I used a simple PHP script that I called mydeploy.php with the following code:
<?php
echo exec('svn update');
?>
Upload that file mydeploy.php to your development or production environment.
It just does a simple svn update. For security reasons I added a couple of other lines to check the remote IP so you can prevent unauthorized people to call the script, but that’s out of this scope.
This file can be placed in the development environment where you want to keep the code up to date on each DEPLOY signal.
The Hook
In your repository, you can go to /hooks/ and edit post-commit (rename post-commit.tmpl to post-commit and make it executable with chmod +x post-commit).
Then, use svn look to check the last commit message and grep to check if the signal was present or not. If the signal was present, then it indicates that we should call mydeploy.php to run the svn update remotely. If not, then do nothing.
REPOS="$1" REV="$2" if ( svnlook log -r $REV $REPOS | grep "*DEPLOY*" ) then wget http://yourdomainhere/mydeploy.php /usr/bin/svn-mailer -d "$REPOS" -r "$REV" -f /srv/svn/svn-mailer.conf fi
The Signal
Suppose that you are coding and often you want to update your development or staging environment, but you want to avoid doing a SSH and then a svn update each time.
So, what you using this approach is committing with your usual message logs until you want to commit and deploy. That’s where the Deploy Signal takes place. In order to commit and deploy, you just need to put the string *DEPLOY* in the commit message, for example while committing with Tortoise SVN (or just the command line, whatever).
So, when the hook detects the last commit has the signal string *DEPLOY*, it will call the remote script and execute a remote svn update to keep your code up to date.
Pros:
- It’s really simple and easy to implement.
- You don’t need to run SSH each time or upload your updated files through FTP.
- Don’t need to use password in your bash scripts or hook files.
Cons:
- Require a commit (with the signal string) in order to deploy.
- Require to have a repository in your development or production environment. There may exist people that dislike this idea, but in my case it was not a problem (moreover, I usually keep .svn folders and files inaccessible for web visitors using htaccess rules).
- If you require database changes, you definitely need to access to your server and update the .sql schema. BTW, a good idea could be to add support for DB changes deployment, too.
Related searches:
- codeigniter deployment
- how to deploy svn from remote server
- svn deployment
- svn deploy linux
- how to deploye codeigniter in customer server
- codeigniter SVN
- php svn post-commit deploy script
- codeigniter db deployment
- php remote deploying ssh
- script deployment with subversion




