|
|
|
.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
|
|
|
|
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:
|
|
|
|
./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
|
|
|
|
|
|
|
|
# Deploy to current *mamweb-test* directory
|
|
|
|
deploy_test:
|
|
|
|
@echo "Installing version from origin/pseudo_test ..."
|
|
|
|
git pull origin pseudo_test
|
|
|
|
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:
|
|
|
|
@echo "Backing up production DB ..."
|
|
|
|
( cd -P .. && ./backup_prod_db.sh )
|
|
|
|
@echo "Installing version from origin/pseudo_master ..."
|
|
|
|
git pull origin pseudo_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 test media directory with production
|
|
|
|
sync_test_media:
|
|
|
|
rsync -av --delete /akce/mam/www/mamweb-prod/media/ ./media
|
|
|
|
|
|
|
|
# Sync test database with production database
|
|
|
|
sync_test_db:
|
|
|
|
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
|