/
Makefile
69 lines (53 loc) · 1.86 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
.PHONY := install, help, update, postgres-docker
.DEFAULT_GOAL := install
INS=$(wildcard requirements.*.in)
REQS=$(subst in,txt,$(INS))
DB_DOCKER=rom-postgres
DB_USER=romuser
DB_PASS=rompass
DB_NAME=romdb
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
requirements.%.txt: requirements.%.in requirements.txt
@echo "Builing $@"
@pip-compile -q -o $@ $<
@touch $@
requirements.txt: requirements.in
@echo "Builing $@"
@pip-compile -q $^
install: requirements.txt $(REQS) ## Install development requirements
@echo "Installing $^"
@pip-sync $^
$(HOOKS):
pre-commit install
pre-init:
pip install wheel pip-tools
init: .envrc pre-init install $(HOOKS) ## Initalise a dev enviroment
@echo "Read to dev"
@which direnv > /dev/null || echo "direnv not found but recommended"
update:
@echo "Upgrading"
pip-compile --upgrade requirements.in > requirements.txt
pip-compile --upgrade requirements.dev.in > requirements.dev.txt
.envrc: runtime.txt Makefile
@echo > $@
@echo layout python $(shell cat $^ | tr -d "-" | egrep -o "python[0-9]\.[0-9]+") >> $@
@echo export DATABASE_URL="postgres://$(DB_USER):$(DB_PASS)@localhost:5432/$(DB_NAME)" >> $@
@cat $@
@echo
@direnv allow
@touch $@
postgres-docker: .envrc
@docker stop $(DB_DOCKER) || true
docker run --rm --name $(DB_DOCKER) -p 5432:5432 -e POSTGRES_PASSWORD=$(DB_PASS) -e POSTGRES_USER=$(DB_USER) -e POSTGRES_DB=$(DB_NAME) -d postgres
latest.dump:
heroku pg:backups:capture
heroku pg:backups:download
import-db: latest.dump
export "PGPASSWORD=$(DB_PASS)" && pg_restore --verbose --clean --no-acl --no-owner -h localhost -U $(DB_USER) -d $(DB_NAME) $^
clean:
rm -f latest.dump
shrink:
heroku run 'python manage.py thumbnail_cleanup'
heroku run 'python manage.py clean_dogs'
heroku run 'python manage.py clearsessions'