diff --git a/Makefile_old b/Makefile_old index d9f1f8a2..20a19bdf 100644 --- a/Makefile_old +++ b/Makefile_old @@ -1,38 +1,3 @@ -# Deploy to current *mamweb-test* directory -deploy: venv_check - @if [ ${USER} != "mam-web" ]; then echo "Only possible by user mam-web"; exit 1; fi - @if [ `readlink -f .` != "/aux/akce/mam/www/mamweb-test" ]; then echo "Only possible in directory mamweb-test"; exit 1; fi - @echo "Installing version from origin/${BRANCH} ..." - git pull origin ${BRANCH} - git clean -f - make install - ./manage.py migrate - ./manage.py collectstatic --noinput - (chown -R :mam . || true ) - (chmod -R g+rX,go-w . || true ) - @echo Restarting systemd unit - systemctl --user restart mamweb-test.service - @echo Done. - -# Deploy to current *mamweb-prod* directory -deploy_prod: venv_check - @if [ ${USER} != "mam-web" ]; then echo "Only possible by user mam-web"; exit 1; fi - @if [ `readlink -f .` != "/aux/akce/mam/www/mamweb-prod" ]; then echo "Only possible in directory mamweb-prod"; exit 1; fi - @echo "Backing up production DB ..." - ( cd -P .. && ./backup_prod_db.sh ) - @echo "Installing version from origin/master ..." - git pull origin master - git clean -f - make install - ./manage.py migrate - ./manage.py collectstatic --noinput - (chown -R :mam . || true ) - (chmod -R g+rX,go-w . || true ) - @echo Restarting systemd user unit for MaM web - systemctl --user restart mamweb-prod.service - @echo Done. - - sync_prod_flatpages: venv_check @echo Downloading current version of flatpages from mamweb-prod. ssh mam-web@gimli.ms.mff.cuni.cz \ diff --git a/make/deploy b/make/deploy index 60347f1e..d25df6ce 100755 --- a/make/deploy +++ b/make/deploy @@ -1,3 +1,25 @@ #!/bin/bash set -exuo pipefail +. make/lib.sh + +if test "$USER" != "mam-web"; +then + echo >&2 "Nasadit web smí jen uživatel mam-web" + exit 1 +fi + +if test "$(readlink -f .)" != "$TESTWEB"; +then + echo >&2 "Nasadit testweb lze jen v jeho složce" + exit 1 +fi + +CURRENT_BRANCH="$(git branch --show-current)" +BRANCH="${1:-$CURRENT_BRANCH}" + +safe_checkout_branch "$BRANCH" "$0" + +# Teď máme správnou větev, jdeme vše nainstalovat +install_everything +systemctl --user restart mamweb-test.service diff --git a/make/deploy_prod b/make/deploy_prod index 60347f1e..8e006938 100755 --- a/make/deploy_prod +++ b/make/deploy_prod @@ -1,3 +1,34 @@ #!/bin/bash set -exuo pipefail +. make/lib.sh + +if test "$USER" != "mam-web" +then + echo >&2 "Nasadit web smí jen uživatel mam-web" + exit 1 +fi + +if test "$(readlink -f .)" != "$PRODWEB" +then + echo >&2 "Nasadit testweb lze jen v jeho složce" + exit 1 +fi + +CURRENT_BRANCH="$(git branch --show-current)" +BRANCH="${1:-$CURRENT_BRANCH}" + +if test "$BRANCH" != master +then + echo "Pozor, nasazuješ na produkci větev, která není master ($BRANCH), chceš pokračovat? Pokud ne, sestřel tento skript." + read +fi + +# Záloha DB +( cd -P .. && ./backup_prod_db.sh ) + +safe_checkout_branch "$BRANCH" "$0" + +# Teď máme správnou větev, jdeme vše nainstalovat +install_everything +systemctl --user restart mamweb-prod.service diff --git a/make/lib.sh b/make/lib.sh index 3e4e99c9..fb56e991 100644 --- a/make/lib.sh +++ b/make/lib.sh @@ -25,3 +25,45 @@ function ensure_venv { test -f "$VENV_PATH/bin/activate" || $VENV "$VENV_PATH" . "$VENV_PATH/bin/activate" } + + +function safe_checkout_branch { + if "$#" -ne 2; + then + echo >&2 "Použití: $0 " + return 1 + fi + + BRANCH="$1" + SCRIPT="$2" + + echo "Debug: I am $0, $SCRIPT as param" + + git fetch --all + # Od teď si musíme dát pozor, abychom nezměnili kód, který právě běží. + # Zkontrolujeme, že se nemění tahle knihovna a skript, který běží. + if test $(git rev-parse @:make/lib.sh) != $(git rev-parse "$BRANCH":make/lib.sh) + then + echo >&2 "Změna v make/lib.sh, prosím pullni manuálně" + exit 1 + fi + if test $(git rev-parse @:"$SCRIPT") != $(git rev-parse "$BRANCH":"$SCRIPT") + then + echo >&2 "Změna v $SCRIPT, prosím pullni manuálně" + exit 1 + fi + git checkout "$BRANCH" + git pull + git clean -f +} + +function install_everything { + # Skoro celé nasazení webu je stejné pro testweb i pro produkci, tak je to tady dohromady + ensure_venv + make/install + ./manage.py migrate + ./manage.py collectstatic --noinput + chown -R :mam . || true + chmod -R g+rX,go-w . || true +} +