Posts Tagged process

subversion hooks and “light” continuous integration

I recently made something really simple which developpers found really usefull:
When a developper commits some code on a subversion repository, he wants to test if it works on an integration plateform.
In my case, this was on a php project, so no complilation, to do so, I just need to copy the file in the right place !
Actually, the right place for me was on another machine.

So, how do you copy files on a remote machine automatically when developpers commits some new code ?
Easy: use hooks

In your subversion repository you will find a directory called “hooks” , all files in this directory are called something.tmpl , those files are examples / templates.

What i did was put this content in post-commit:

RESULT=`/usr/bin/svnlook dirs-changed "$REPOS" -r $REV | grep -e "the/dir/in/the/repo/project"`; 
if [ ! -z "$RESULT" ]; then 
    /usr/bin/svn export file:///var/lib/svn/the/dir/in/the/repo/project /tmp/project
    /usr/bin/scp -i /home/apache/id_dsa -r /tmp/project/* user@host:/var/www/project
    /bin/rm -rf /tmp/project

Then I needed to do some stuff:

  1. chmod +x post-commit
  2. I also needed to generate ssh keys, put the private key in /home/apache/id_dsa, make it owned by the process running subversion (for me apache, because I’m using apache’s mod_dav_svn), and copy the key to a users’ authorized_keys file …
  3. Authorize the remote host’s key for the user running the post-commit script (su www-data then ssh host and accept the key)

I you make a mistake in your post-commit script (like I did the first time I tried), you get the error on the output when you commit the code !

Easy, fun and nice !


Leave a Comment

watch your process !

I just discovered the watch command, it can be useful !
If you don’t know watch, it does what you would do like this:
while true ; do "your command" ; sleep 1 ; clear ; done
that is, it executes in a while loop the same command , with a sleep so that it doesn’t overkill your cpu.
It also has nice parameters, for exemple --differences that can only show the differences between current and last run.
“your command” could be a du or a df , --differences could be useful when used with an ls to monitor a directory …
Read the manpage and have fun ! 🙂

Leave a Comment