Skip to content

Instantly share code, notes, and snippets.

@mylokin
Created August 1, 2012 12:37
Show Gist options
  • Save mylokin/3226454 to your computer and use it in GitHub Desktop.
Save mylokin/3226454 to your computer and use it in GitHub Desktop.
post-receive git hook
#!/bin/bash
unset GIT_DIR
REPO_PATH=/var/www/casahop/travelocial
ENV_PATH=/usr/local/share/virtualenvs/casahop
CONFIG_PATH=/home/ben/configs
BRANCH=master
while read oldrev newrev refname
do
if [[ -z `git branch --contains $newrev | grep $BRANCH` ]]; then
echo '### Casahop: Deploy aborted. '$BRANCH' branch required'
fi
if [[ -n `git branch --contains $newrev | grep $BRANCH` ]]; then
if [ -f $CONFIG_PATH/django/settings_local.py.prod ]; then
cd $CONFIG_PATH
git stash
git pull origin master
cp $CONFIG_PATH/django/settings_local.py.prod $REPO_PATH/settings_local.py
fi
source $ENV_PATH/bin/activate
cd $REPO_PATH
which python
git reset --hard HEAD
echo '### Casahop: Deploying'
git checkout $newrev
if [[ -n `git log --pretty=oneline --abbrev-commit $oldrev..$newrev -- requirements.txt` ]]; then
pip install -r requirements.txt
fi
if [[ -n `git log --pretty=oneline --abbrev-commit $oldrev..$newrev -- app/migrations/` ]] || \
[[ -n `git log --pretty=oneline --abbrev-commit $oldrev..$newrev -- users/migrations/` ]]; then
python $REPO_PATH/manage.py migrate
fi
if [[ -n `git log --pretty=oneline --abbrev-commit $oldrev..$newrev -- static/` ]]; then
compass compile $REPO_PATH/static
python $REPO_PATH/manage.py generatemedia
python $REPO_PATH/manage.py collectstatic --noinput
fi
touch script.wsgi
echo '### Casahop: Success'
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment