Deploy v novém kabátu
prosím čtěte…
This commit is contained in:
parent
4f7c4057ea
commit
a9e7cd7af2
4 changed files with 95 additions and 35 deletions
35
Makefile_old
35
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 \
|
||||
|
|
22
make/deploy
22
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
|
||||
|
|
|
@ -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
|
||||
|
|
42
make/lib.sh
42
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 <branch> <current-script>"
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue