Updated deploy.sh

- Added --dbmakemigrations to do makemigrations
    - Added call to restart celery
This commit is contained in:
PCoder 2017-08-19 18:28:17 +05:30
parent 2b71795431
commit 422b0ca93e

View file

@ -13,6 +13,7 @@ while true; do
case "$1" in case "$1" in
-h | --help ) HELP=true; shift ;; -h | --help ) HELP=true; shift ;;
-v | --verbose ) VERBOSE=true; shift ;; -v | --verbose ) VERBOSE=true; shift ;;
-D | --dbmakemigrations ) DB_MAKE_MIGRATIONS=true; shift ;;
-d | --dbmigrate ) DB_MIGRATE=true; shift ;; -d | --dbmigrate ) DB_MIGRATE=true; shift ;;
-n | --nogit ) NO_GIT=true; shift ;; -n | --nogit ) NO_GIT=true; shift ;;
-b | --branch ) BRANCH="$2"; shift 2 ;; -b | --branch ) BRANCH="$2"; shift 2 ;;
@ -31,13 +32,15 @@ if [ "$HELP" == "true" ]; then
echo "options are : " echo "options are : "
echo " -h, --help: Print this help message" echo " -h, --help: Print this help message"
echo " -v, --verbose: Show verbose output to stdout. Without this a deploy.log is written to ~/app folder" echo " -v, --verbose: Show verbose output to stdout. Without this a deploy.log is written to ~/app folder"
echo " -d, --dbmigrate: Do DB migrate" echo " -D, --dbmakemigrations: Do DB makemigrations"
echo " -n, --nogit: Don't execute git commands. With this --branch has no effect." echo " -d, --dbmigrate: Do DB migrate. To do both makemigrations and migrate, supply both switches -D and -d"
echo " -n, --nogit: Don't execute git commands. This is used to deploy the current code in the project repo. With this --branch has no effect."
echo " -b, --branch: The branch to pull from origin repo." echo " -b, --branch: The branch to pull from origin repo."
exit exit
fi fi
echo "BRANCH="$BRANCH echo "BRANCH="$BRANCH
echo "DB_MAKE_MIGRATIONS="$DB_MAKE_MIGRATIONS
echo "DB_MIGRATE="$DB_MIGRATE echo "DB_MIGRATE="$DB_MIGRATE
echo "NO_GIT="$NO_GIT echo "NO_GIT="$NO_GIT
echo "VERBOSE="$VERBOSE echo "VERBOSE="$VERBOSE
@ -45,7 +48,7 @@ echo "VERBOSE="$VERBOSE
# The project directory exists, we pull the specified branch # The project directory exists, we pull the specified branch
cd $APP_HOME_DIR cd $APP_HOME_DIR
if [ -z "$NO_GIT" ]; then if [ -z "$NO_GIT" ]; then
echo 'We are executing default git commands. Please -no_git to not use this.' echo 'We are executing default git commands. Please add --nogit to not do this.'
# Save any modified changes before git pulling # Save any modified changes before git pulling
git stash git stash
# Fetch all branches/tags # Fetch all branches/tags
@ -59,16 +62,23 @@ fi
source ~/pyvenv/bin/activate source ~/pyvenv/bin/activate
pip install -r requirements.txt > deploy.log 2>&1 pip install -r requirements.txt > deploy.log 2>&1
echo "###" >> deploy.log echo "###" >> deploy.log
if [ -z "$DB_MAKE_MIGRATIONS" ]; then
echo 'We are not doing DB makemigrations'
else
echo 'Doing DB makemigrations'
./manage.py makemigrations >> deploy.log 2>&1
echo "###" >> deploy.log
fi
if [ -z "$DB_MIGRATE" ]; then if [ -z "$DB_MIGRATE" ]; then
echo 'We are not doing DB migration' echo 'We are not doing DB migration'
else else
./manage.py makemigrations >> deploy.log 2>&1 echo 'Doing DB migrate'
echo "###" >> deploy.log
./manage.py migrate >> deploy.log 2>&1 ./manage.py migrate >> deploy.log 2>&1
echo "###" >> deploy.log echo "###" >> deploy.log
fi fi
printf 'yes' | ./manage.py collectstatic >> deploy.log 2>&1 printf 'yes' | ./manage.py collectstatic >> deploy.log 2>&1
echo "###" >> deploy.log echo "###" >> deploy.log
django-admin compilemessages django-admin compilemessages
sudo systemctl restart celery.service
sudo systemctl restart uwsgi sudo systemctl restart uwsgi