From ecbf18e97530ad365bb6f87a38dacea8ec6ccce4 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Mon, 14 Sep 2015 22:59:25 +0200 Subject: [PATCH] Zmena zpusobu deploy a backupu --- Makefile | 84 ++++++++++++++++------------------------------- backup_prod_db.sh | 10 ------ 2 files changed, 29 insertions(+), 65 deletions(-) delete mode 100755 backup_prod_db.sh diff --git a/Makefile b/Makefile index 972ab3f6..09a67a11 100644 --- a/Makefile +++ b/Makefile @@ -58,59 +58,33 @@ schema_seminar.pdf: schema_all.pdf: ./manage.py graph_models -a -g | dot -Tpdf > schema_all.pdf -# remote commands - -TEST_USER=test-mam -TEST_SERVER=atrey.karlin.mff.cuni.cz -TEST_DIR=/home/test-mam/mamweb-test/ - -PROD_USER=test-mam -PROD_SERVER=atrey.karlin.mff.cuni.cz -PROD_DIR=/home/test-mam/mamweb-prod/ - -HEAD=`git log --color=never |head -1|sed 's/.*commit //'` - -push_test: - @echo "Checking out commited HEAD (${HEAD}) state at ${TEST_SSH} ..." - git tag deploy-test-`date +%Y-%m-%d-%H-%M`-${USER} - git push --all - ssh ${TEST_USER}@${TEST_SERVER} -n -x "\ - cd ${TEST_DIR} && \ - git fetch --all && \ - git checkout ${HEAD} -f && \ - git clean -f && \ - cp mamweb/settings_test.py mamweb/settings.py && \ - make install && \ - ./manage.py collectstatic --noinput && \ - ./manage.py migrate --noinput && \ - (chown -Rf :mam . || true ) && \ - (chmod -Rf g+w . || true ) && \ - echo 'Reloading apache ... (You may have to start it manually on error!)' && \ - ~/etc/apache2/apache2ctl -k restart && \ - echo Done." - @echo "Test pushed to ${TEST_SERVER}:${TEST_DIR} successfully." - -push_prod: - @echo "Checking out commited HEAD (${HEAD}) state at ${PROD_SSH} ..." - git tag deploy-prod-`date +%Y-%m-%d-%H-%M`-${USER} - git push --all - ssh ${PROD_USER}@${PROD_SERVER} -n -x "\ - echo 'Stopping apache ... (You may have to start it manually on error!)' && \ - ~/etc/apache2/apache2ctl -k stop && \ - cd ${PROD_DIR} && \ - ./backup_prod_db.sh && \ - git fetch --all && \ - git checkout ${HEAD} -f && \ - git clean -f && \ - cp mamweb/settings_prod.py mamweb/settings.py && \ - make install && \ - ./manage.py collectstatic --noinput && \ - ./manage.py migrate --noinput && \ - (chown -Rf :mam . || true ) && \ - (chmod -Rf g+w . || true ) && \ - echo 'Starting apache ... (You may have to start it manually on error!)' && \ - ~/etc/apache2/apache2ctl -k start && \ - echo Done." - @echo "Deployed to ${PROD_SERVER}:${PROD_DIR} successfully." - +# Deploy to current *mamweb-test* directory +deploy_test: + @if [[ `pwd` != "/akce/MaM/WWW/mamweb-test" ]]; then echo "Only possible in /akce/MaM/WWW/mamweb-test"; exit 1; fi + @echo "Installing version from origin/master ..." + git pull origin master + git clean -f + make install + ./manage.py migrate + ./manage.py collectstatic --noinput + (chown -Rf :mam . || true ) + (chmod -Rf g+w . || true ) + touch mamweb/wsgi.py + @echo Done. + +# Deploy to current *mamweb-prod* directory +deploy_prod: + @if [[ `pwd` != "/akce/MaM/WWW/mamweb-prod" ]]; then echo "Only possible in /akce/MaM/WWW/mamweb-prod"; exit 1; fi + @echo "Backing up production DB ..." + cd .. && ./backup_prod_db.sh + @echo "Installing version from origin/stable ..." + git pull origin stable + git clean -f + make install + ./manage.py migrate + ./manage.py collectstatic --noinput + (chown -Rf :mam . || true ) + (chmod -Rf g+w . || true ) + touch mamweb/wsgi.py + @echo Done. diff --git a/backup_prod_db.sh b/backup_prod_db.sh deleted file mode 100755 index e31512a5..00000000 --- a/backup_prod_db.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -DBNAME=mam-prod -FNAME=backup-db/$DBNAME-`date '+%F-%T'`.bz2 -echo Backing up production DB $DBNAME to $FNAME ... - -pg_dump $DBNAME -U mam | bzip2 -9 > $FNAME - -echo Done. -