mamweb/Makefile

132 lines
4 KiB
Makefile
Raw Normal View History

.PHONY: clean_env init_env clean_virtualenv install_packages clean install run all schema_seminar.pdf schema_all.pdf sync_test_media sync_test_db sync_test sync_local_media sync_local_db sync_local
PYTHON=python2.7
VE_VER=16.0.0
LOCAL_PYTHON=bin/python
all: install
clean: clean_env
veryclean: clean clean_virtualenv
install: virtualenv bin/python install_packages
# phony, but depends on file
make_env: ${LOCAL_PYTHON}
# phony, but fast repeated execution
install_packages: make_env
bin/pip install -r requirements.txt --upgrade
# phony
clean_env:
rm -rf bin/ include/ lib/ local/ share/
rm -f pip-selfcheck.json
rm -f schema_seminar.pdf schema_all.pdf
# binary name representing set-up env
${LOCAL_PYTHON}: virtualenv
${PYTHON} virtualenv/virtualenv.py .
# directory name
virtualenv:
# I could not find a link without hash anymore. This will probably break in
# the future.
curl -O https://files.pythonhosted.org/packages/33/bc/fa0b5347139cd9564f0d44ebd2b147ac97c36b2403943dbee8a25fd74012/virtualenv-16.0.0.tar.gz
tar xvfz virtualenv-${VE_VER}.tar.gz
2015-10-01 21:44:50 +02:00
mv -T virtualenv-${VE_VER} virtualenv
rm virtualenv-${VE_VER}.tar.gz
# phony
clean_virtualenv:
rm -rf virtualenv/
rm -rf virtualenv-*.tar.gz
run:
./manage.py runserver
test:
2015-05-14 00:54:07 +02:00
./manage.py test -v2 seminar mamweb
# DB schemata
schema: schema_seminar.pdf schema_all.pdf
schema_seminar.pdf:
./manage.py graph_models seminar | dot -Tpdf > schema_seminar.pdf
schema_all.pdf:
./manage.py graph_models -a -g | dot -Tpdf > schema_all.pdf
2015-09-14 22:59:25 +02:00
# Deploy to current *mamweb-test* directory
deploy_test:
@if [ ${USER} != "mam-web" ]; then echo "Only possible by user mam-web"; exit 1; fi
@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/test ..."
git pull origin test
2015-09-14 22:59:25 +02:00
git clean -f
make install
./manage.py migrate
./manage.py collectstatic --noinput
2015-09-25 11:58:42 +02:00
(chown -R :mam . || true )
(chmod -R g+rX,go-w . || true )
@echo Restarting systemd unit
systemctl --user restart mamweb-test.service
2015-09-14 22:59:25 +02:00
@echo Done.
# Deploy to current *mamweb-prod* directory
deploy_prod:
@if [ ${USER} != "mam-web" ]; then echo "Only possible by user mam-web"; exit 1; fi
2018-08-20 20:22:44 +02:00
@if [ `pwd` != "/akce/mam/www/mamweb-prod" ]; then echo "Only possible in /akce/mam/www/mamweb-prod"; exit 1; fi
2015-09-14 22:59:25 +02:00
@echo "Backing up production DB ..."
2015-09-14 23:02:43 +02:00
( cd .. && ./backup_prod_db.sh )
@echo "Installing version from origin/master ..."
git pull origin master
2015-09-14 22:59:25 +02:00
git clean -f
make install
./manage.py migrate
./manage.py collectstatic --noinput
2015-09-25 11:58:42 +02:00
(chown -R :mam . || true )
(chmod -R g+rX,go-w . || true )
2018-08-20 20:22:44 +02:00
@echo Restarting systemd user unit for MaM web
systemctl --user restart mamweb-prod.service
2015-09-14 22:59:25 +02:00
@echo Done.
# Sync test media directory with production
sync_test_media:
@if [ ${USER} != "mam-web" ]; then echo "Only possible by user mam-web"; exit 1; fi
@if [ `pwd` != "/akce/mam/www/mamweb-test" ]; then echo "Only possible in /akce/mam/www/mamweb-test"; exit 1; fi
rsync -av --delete /akce/mam/www/mamweb-prod/media/ ./media
# Sync test database with production database
sync_test_db:
@if [ ${USER} != "mam-web" ]; then echo "Only possible by user mam-web"; exit 1; fi
pg_dump mam_test > dump-test-`date +"%Y%m%d_%H%M"`.sql
pg_dump -Fc mam_prod > dump-prod.sql
pg_restore -c -d mam_test dump-prod.sql
rm dump-prod.sql
@echo Done.
# Sync test with production
sync_test: sync_test_media sync_test_db
# Sync media directory with atrey. Useful for local development with production database
# Does not sync Galerie and CACHE (too huge).
sync_local_media:
rsync -ave ssh --exclude Galerie --exclude CACHE\
mam-web@gimli.ms.mff.cuni.cz:/akce/mam/www/mamweb-prod/media/ ./media/
# Downloads and restores production database to local database. PostgreSQL only.
sync_local_db:
scp mam-web@gimli.ms.mff.cuni.cz:`ssh mam-web@gimli.ms.mff.cuni.cz 'ls -v /akce/mam/www/backups/mam_prod-*\.pgdump.xz | tail -n 1'` \
./last.pgdump.xz
xz -fd last.pgdump.xz
pg_restore -c -d mam-prod last.pgdump
# Sync database and media. See above lines
sync_local: sync_media sync_db