| 1 | #! /bin/bash |
| 2 | |
| 3 | ROOT_PATH=. |
| 4 | PROJECT_NAME="{{ project_name }}" |
| 5 | PRODUCTION="production" |
| 6 | |
| 7 | ################################################################################ |
| 8 | # Prerequis pour le fonctionnement du script |
| 9 | ################################################################################ |
| 10 | if [ ! -e "$ROOT_PATH/README.rst" ]; then |
| 11 | echo "Placez vous a la racine du projet." |
| 12 | exit -1 |
| 13 | fi |
| 14 | |
| 15 | |
| 16 | ################################################################################ |
| 17 | # Selection de la configuration |
| 18 | ################################################################################ |
| 19 | BUILD=$1 |
| 20 | if [ "$BUILD" = "" ]; then |
| 21 | BUILD=$PRODUCTION |
| 22 | fi |
| 23 | REQUIREMENTS=$ROOT_PATH/requirements/$BUILD.txt |
| 24 | SETTINGS=$PROJECT_NAME.settings.$BUILD |
| 25 | |
| 26 | |
| 27 | ################################################################################ |
| 28 | # VCS |
| 29 | ################################################################################ |
| 30 | if [ "$BUILD" = "$PRODUCTION" ]; then |
| 31 | echo "Commandes du VCS" |
| 32 | GIT_CLEAN="# On branch master\n nothing to commit (working directory clean)" |
| 33 | GIT_STATUS=`git status` |
| 34 | if [ "$GIT_STATUS" != "$GIT_CLEAN" ]; then |
| 35 | echo "Le depot local n'est pas dans un etat acceptable pour deployer" |
| 36 | exit -1 |
| 37 | fi |
| 38 | fi |
| 39 | |
| 40 | |
| 41 | ################################################################################ |
| 42 | # Tests concerant la configuration |
| 43 | ################################################################################ |
| 44 | if [ ! -e "$ROOT_PATH/conf.py" ]; then |
| 45 | echo "Il n'y a pas le fichier conf.py a la racine du projet." |
| 46 | exit -1 |
| 47 | fi |
| 48 | |
| 49 | DIFF=`diff -y conf.py.edit conf.py | grep '<' | colordiff` |
| 50 | if [ "$DIFF" != "" ]; then |
| 51 | echo 'Ajuster le conf.py' |
| 52 | diff -y conf.py.edit conf.py | grep '<' | colordiff |
| 53 | exit -1 |
| 54 | fi |
| 55 | |
| 56 | ################################################################################ |
| 57 | # Preparation de l'environnement |
| 58 | ################################################################################ |
| 59 | VENV_PATH=$ROOT_PATH/.virtualenv |
| 60 | if [ -e "$VENV_PATH" ]; then |
| 61 | echo "l'environnement virtuel existe deja." |
| 62 | else |
| 63 | echo "Creation de l'environnement virtuel." |
| 64 | virtualenv $VENV_PATH |
| 65 | rm -f distribute*.tar.gz |
| 66 | fi |
| 67 | |
| 68 | echo "Installation des dependances." |
| 69 | echo $VENV_PATH/bin/pip |
| 70 | $VENV_PATH/bin/pip install -r $REQUIREMENTS |
| 71 | |
| 72 | if [ "$BUILD" != "$PRODUCTION" ]; then |
| 73 | exit -1 |
| 74 | fi |
| 75 | |
| 76 | ################################################################################ |
| 77 | # Preparation du projet (en production uniquement) |
| 78 | ################################################################################ |
| 79 | echo "Commandes Django" |
| 80 | echo "settings: " $SETTINGS |
| 81 | $ROOT_PATH/bin/django syncdb --settings=$SETTINGS --noinput |
| 82 | $ROOT_PATH/bin/django migrate --settings=$SETTINGS --noinput |
| 83 | $ROOT_PATH/bin/django collectstatic --settings=$SETTINGS --noinput |
| 84 | |
| 85 | |