2016-07-25 20:57:35 +02:00
|
|
|
.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
|
2015-03-07 12:07:53 +01:00
|
|
|
PYTHON=python2.7
|
2018-05-24 22:12:19 +02:00
|
|
|
VE_VER=16.0.0
|
2015-03-07 12:07:53 +01:00
|
|
|
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
|
2015-09-25 12:33:59 +02:00
|
|
|
bin/pip install -r requirements.txt --upgrade
|
2015-03-07 12:07:53 +01:00
|
|
|
|
|
|
|
# phony
|
|
|
|
clean_env:
|
|
|
|
rm -rf bin/ include/ lib/ local/ share/
|
|
|
|
rm -f pip-selfcheck.json
|
2015-03-14 23:39:16 +01:00
|
|
|
rm -f schema_seminar.pdf schema_all.pdf
|
2015-03-07 12:07:53 +01:00
|
|
|
|
|
|
|
# binary name representing set-up env
|
|
|
|
${LOCAL_PYTHON}: virtualenv
|
|
|
|
${PYTHON} virtualenv/virtualenv.py .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# directory name
|
|
|
|
virtualenv:
|
2018-05-24 22:12:19 +02:00
|
|
|
# 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
|
2015-03-07 12:07:53 +01:00
|
|
|
tar xvfz virtualenv-${VE_VER}.tar.gz
|
2015-10-01 21:44:50 +02:00
|
|
|
mv -T virtualenv-${VE_VER} virtualenv
|
2015-03-07 12:07:53 +01:00
|
|
|
rm virtualenv-${VE_VER}.tar.gz
|
|
|
|
|
|
|
|
# phony
|
|
|
|
clean_virtualenv:
|
|
|
|
rm -rf virtualenv/
|
2015-09-25 12:33:59 +02:00
|
|
|
rm -rf virtualenv-*.tar.gz
|
2015-03-07 12:07:53 +01:00
|
|
|
|
2015-03-14 15:41:29 +01:00
|
|
|
run:
|
2016-03-03 15:34:30 +01:00
|
|
|
./manage.py runserver
|
2015-03-14 15:41:29 +01:00
|
|
|
|
2015-03-14 23:39:16 +01:00
|
|
|
test:
|
2015-05-14 00:54:07 +02:00
|
|
|
./manage.py test -v2 seminar mamweb
|
2015-03-14 23:39:16 +01:00
|
|
|
|
|
|
|
# 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:
|
2018-08-20 21:18:26 +02:00
|
|
|
@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
|
2018-05-24 22:57:51 +02:00
|
|
|
@echo "Installing version from origin/test ..."
|
2018-09-18 02:20:55 +02:00
|
|
|
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 )
|
2018-08-20 21:18:26 +02:00
|
|
|
@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:
|
2018-08-20 21:18:26 +02:00
|
|
|
@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 )
|
2018-05-24 22:57:51 +02:00
|
|
|
@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
|
2018-08-20 21:18:26 +02:00
|
|
|
systemctl --user restart mamweb-prod.service
|
2015-09-14 22:59:25 +02:00
|
|
|
@echo Done.
|
2015-03-07 12:07:53 +01:00
|
|
|
|
2016-07-25 20:57:35 +02:00
|
|
|
|
|
|
|
# Sync test media directory with production
|
|
|
|
sync_test_media:
|
2018-08-20 21:18:26 +02:00
|
|
|
@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
|
2016-07-25 20:57:35 +02:00
|
|
|
|
|
|
|
# Sync test database with production database
|
|
|
|
sync_test_db:
|
2018-08-20 21:18:26 +02:00
|
|
|
@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
|
2016-07-25 20:57:35 +02:00
|
|
|
rm dump-prod.sql
|
|
|
|
@echo Done.
|
|
|
|
|
|
|
|
# Sync test with production
|
|
|
|
sync_test: sync_test_media sync_test_db
|
|
|
|
|
|
|
|
|
2016-02-27 17:12:16 +01:00
|
|
|
# Sync media directory with atrey. Useful for local development with production database
|
|
|
|
# Does not sync Galerie and CACHE (too huge).
|
2016-07-25 20:57:35 +02:00
|
|
|
sync_local_media:
|
2016-02-27 17:12:16 +01:00
|
|
|
rsync -ave ssh --exclude Galerie --exclude CACHE\
|
2018-09-14 17:53:26 +02:00
|
|
|
mam-web@gimli.ms.mff.cuni.cz:/akce/mam/www/mamweb-prod/media/ ./media/
|
2016-02-27 17:12:16 +01:00
|
|
|
# Downloads and restores production database to local database. PostgreSQL only.
|
2016-07-25 20:57:35 +02:00
|
|
|
sync_local_db:
|
2018-09-14 17:53:26 +02:00
|
|
|
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
|
2016-02-27 17:12:16 +01:00
|
|
|
|
|
|
|
# Sync database and media. See above lines
|
2016-07-25 20:57:35 +02:00
|
|
|
sync_local: sync_media sync_db
|