Tuesday, 18 September 2012

Creating a Bare Git Repository and Polling it

What we are trying to do is create a database on one machine, dump it in a way which is most diff friendly and commit the dump to a change control system (git).

On another machine we want to poll git and when there is a change rebuild the database.

Creating a Bare Repository

A bare repository is one which does not have a working copy checked out.

A bare repository is how you implement a system similar to a CVS or SVN repository: a hub repository.

sudo su
apt-get install git-core
cd /srv
mkdir git
mkdir git/repository.git
cd git/repository.git
git init --bare

cd ..
chown -R jenkins:tomcat7 repository.git


To create the database on another machine first time through:

git clone timp@app4.wwarn.ox.ac.uk:/srv/chassis-data/git/repository.git
cd repository 
echo 'create database r2;' |mysql -u root

mysql -u root r2 < repository.sql

Now we can poll for changes:

git fetch > build_log.txt 2>&1
if [ -s build_log.txt ]
   git pull
   echo 'drop database r2;' | mysql -u root
   echo 'create database r2;' | mysql -u root
   mysql -u root r2 < repository.sql

Then just pop it into Jenkins

No comments:

Post a Comment