#! /bin/bash ROOT_PATH=. PROJECT_NAME="{{ project_name }}" PRODUCTION="production" ################################################################################ # Prerequis pour le fonctionnement du script ################################################################################ if [ ! -e "$ROOT_PATH/README.rst" ]; then echo "Placez vous a la racine du projet." exit -1 fi ################################################################################ # Selection de la configuration ################################################################################ BUILD=$1 if [ "$BUILD" = "" ]; then BUILD=$PRODUCTION fi REQUIREMENTS=$ROOT_PATH/requirements/$BUILD.txt SETTINGS=$PROJECT_NAME.settings.$BUILD ################################################################################ # VCS ################################################################################ if [ "$BUILD" = "$PRODUCTION" ]; then echo "Commandes du VCS" GIT_CLEAN="# On branch master\n nothing to commit (working directory clean)" GIT_STATUS=`git status` if [ "$GIT_STATUS" != "$GIT_CLEAN" ]; then echo "Le depot local n'est pas dans un etat acceptable pour deployer" exit -1 fi fi ################################################################################ # Tests concerant la configuration ################################################################################ if [ ! -e "$ROOT_PATH/conf.py" ]; then echo "Il n'y a pas le fichier conf.py a la racine du projet." exit -1 fi DIFF=`diff -y conf.py.edit conf.py | grep '<' | colordiff` if [ "$DIFF" != "" ]; then echo 'Ajuster le conf.py' diff -y conf.py.edit conf.py | grep '<' | colordiff exit -1 fi ################################################################################ # Preparation de l'environnement ################################################################################ VENV_PATH=$ROOT_PATH/.virtualenv if [ -e "$VENV_PATH" ]; then echo "l'environnement virtuel existe deja." else echo "Creation de l'environnement virtuel." virtualenv $VENV_PATH rm -f distribute*.tar.gz fi echo "Installation des dependances." echo $VENV_PATH/bin/pip $VENV_PATH/bin/pip install -r $REQUIREMENTS if [ "$BUILD" != "$PRODUCTION" ]; then exit -1 fi ################################################################################ # Preparation du projet (en production uniquement) ################################################################################ echo "Commandes Django" echo "settings: " $SETTINGS $ROOT_PATH/bin/django syncdb --settings=$SETTINGS --noinput $ROOT_PATH/bin/django migrate --settings=$SETTINGS --noinput $ROOT_PATH/bin/django collectstatic --settings=$SETTINGS --noinput