Posted by: Wildan Maulana | April 22, 2009

Simple Continuous Integration : symfony + Subversion

Put the script [a] on the hooks directory of your subversion project repository, for example :

$SVN_ROOT/your-project/hooks

name it : post-commit , and don’t forget to make it executable.

Adjust relevant variables to suit your needs, for example :

# The root of the SVN repository
SVNROOT="/var/lib/svn/SissyBooks"
# The path within the SVN repository to export whenever it's committed
SVNPATH="trunk"
# The directory to hold the checked-out copy
WORKING="/var/www/SissyBooks"

Set up Your new Virtual Host :

<VirtualHost -Your Server IP Address - >
 ServerName sissybooks.wm
 ServerAdmin wildan@tobethink.com

 Alias /sf   /usr/share/php/symfony/symfony12/data/web/sf

 <Directory "/usr/share/php/symfony/symfony12/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>

 php_flag register_globals Off

	DocumentRoot /var/www/SissyBooks/web
	<Directory "/var/www/SissyBooks/web">
		Options Indexes FollowSymLinks MultiViews
		AllowOverride All
		Order allow,deny
		allow from all
		# Uncomment this directive is you want to see apache2's
		# default start page (in /apache2-default) when you go to /
		#RedirectMatch ^/$ /apache2-default/
	</Directory>


	ErrorLog /var/log/apache2/sissybooks.error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog /var/log/apache2/sissybooks.access.log combined
	ServerSignature On
</VirtualHost>

You’re done !

[a] Script taken from [2] :

#!/bin/bash

# POST-COMMIT HOOK
#
# This is an SVN post-commit hook to automatically update a directory with the contents
# of some part of the SVN repository every time that part of the repository is changed.

fail() {
	echo "$@" 1>&2
	exit 1
}

# USER and PASS are the username and password of an SVN user with read access to the 
# relevant part of the repository
USER=""
PASS=""
# The root of the SVN repository
SVNROOT=""
# The path within the SVN repository to export whenever it's committed
SVNPATH=""
# The directory to hold the checked-out copy
WORKING=""

# Since environment variables are unset
export PATH="/bin:/usr/bin:/usr/local/bin"

getopt=$(which getopt)

TEMP=`$getopt -o u:p:U:P:d: --long user:,pass:,password:,svn-root:,svn-path:,working-dir: -n $0 -- "$@"`

if [ $? != 0 ]; then
	fail "Terminating...getopt failed"
fi

# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"

while true; do
	case "$1" in
		-u|--user)
			USER=$2
			shift 2;;
		-p|--pass|--password)
			PASS=$2
			shift 2;;
		-U|--svn-root)
			SVNROOT=$2
			shift 2;;
		-P|--svn-path)
			SVNPATH=$2
			shift 2;;
		-d|--working-dir)
			WORKING=$2
			shift 2;;
		--)
			shift
			break ;;
		*)
			fail "Option error!";;
	esac
done

test -n $SVNROOT || fail "Missing option --svn-root"
test -n $SVNPATH || fail "Missing option --svn-path"
test -n $WORKING || fail "Missing option --working-dir"

REPOS="$1"
REV="$2"

# The path to SVN executables
svnbin=$(which svn)
svnlook=$(which svnlook)
# The path to grep
grep=$(which egrep)

if test -n "$USER"; then
	AUTHSTR="--username $USER --password $PASS"
else
	AUTHSTR=""
fi
svnexport="$svnbin export --revision $REV $AUTHSTR"
svnupdate="$svnbin update --revision $REV $AUTHSTR"
svncheckout="$svnbin checkout --revision $REV $AUTHSTR"
svnchanged="$svnlook changed $REPOS --revision $REV"
grepq="$grep -q"

# If anything in the desired path has been changed
if $svnchanged | $grepq "^[A-Z]+[[:space:]]+$SVNPATH"; then
	# Check it out to the web root
	if test -d $WORKING/.svn; then
		$svnupdate $WORKING || fail "svnupdate failed"
	else
		$svncheckout file://$SVNROOT/$SVNPATH $WORKING || fail "svncheckout failed"
	fi
fi

Reference :
[1] Continuous Integration, Martin Fowler
[2] Having latest copy of SVN’ed files in document root, Stackoverfloe discussion entry
[3] Running hook scripts in subversion, Vincent Danen


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: