61 lines
1.7 KiB
Makefile
61 lines
1.7 KiB
Makefile
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
|
|
|
|
VENV := .env
|
|
BIN := $(VENV)/bin
|
|
PYTHON := $(BIN)/python
|
|
SHELL := /bin/bash
|
|
|
|
IGNORE = .git .env
|
|
PYFILES := $(filter-out $(IGNORE),$(call rwildcard,.,*.py))
|
|
HTMLFILES := $(filter-out $(IGNORE),$(call rwildcard,.,*.html))
|
|
MODELS := $(filter-out .git,$(call rwildcard,.,*/models.py))
|
|
|
|
$(VENV)/.install: requirements.txt
|
|
test -d $(VENV) || python3 -m venv $(VENV)
|
|
$(BIN)/pip install --upgrade -r requirements.txt
|
|
touch $(VENV)/.install
|
|
|
|
$(VENV)/.migrate: $(MODELS)
|
|
$(PYTHON) manage.py makemigrations
|
|
$(PYTHON) manage.py migrate
|
|
touch $(VENV)/.migrate
|
|
|
|
$(VENV)/.start: $(HTMLFILES) $(PYFILES)
|
|
$(PYTHON) manage.py collectstatic --noinput
|
|
sudo systemctl restart gunicorn.service gunicorn.socket
|
|
touch $(VENV)/.start
|
|
|
|
.PHONY: migrate
|
|
migrate: $(VENV)/.migrate ## Make and run migrations
|
|
|
|
.PHONY: test
|
|
test: ## Run tests
|
|
$(PYTHON) manage.py test application --verbosity=0 --parallel --failfast
|
|
|
|
.PHONY: pull
|
|
pull:
|
|
git pull
|
|
|
|
.PHONY: start
|
|
start: ## Restart gunicorn
|
|
sudo systemctl restart gunicorn.service gunicorn.socket
|
|
|
|
.PHONY: update
|
|
update: pull $(VENV)/.install $(VENV)/.migrate $(VENV)/.start ## Pull latest from remote and restart
|
|
|
|
.PHONY: backup
|
|
backup: ## Backup database to json file.
|
|
$(PYTHON) manage.py dumpdata --exclude auth.permission --exclude contenttypes --indent=2 > db.json
|
|
|
|
.PHONY: restore
|
|
restore: ## Restore previous backup file.
|
|
$(PYTHON) manage.py loaddata db.json
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
find -iname "*.pyc" -delete
|
|
|
|
help: ## Self-documented Makefile
|
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
|
|