forked from lucyparsons/OpenOversight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
104 lines (84 loc) · 2.97 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
export UID=$(shell id -u)
default: build start create_db populate test stop clean
.PHONY: build
build: ## Build containers
docker compose build
.PHONY: start
start: build ## Run containers
docker compose up -d
.PHONY: create_db
create_db: start
@until docker compose exec postgres psql -h localhost -U openoversight -c '\l' postgres &>/dev/null; do \
echo "Postgres is unavailable - sleeping..."; \
sleep 1; \
done
@echo "Postgres is up"
## Creating database
docker compose run --rm web python ../create_db.py
.PHONY: assets
assets:
docker compose run --rm web yarn build
.PHONY: dev
dev: build start create_db populate
.PHONY: populate
populate: create_db ## Build and run containers
@until docker compose exec postgres psql -h localhost -U openoversight -c '\l' postgres &>/dev/null; do \
echo "Postgres is unavailable - sleeping..."; \
sleep 1; \
done
@echo "Postgres is up"
## Populate database with test data
docker compose run --rm web python ../test_data.py -p
.PHONY: test
test: start ## Run tests
if [ -z "$(name)" ]; then \
if [ "$$(uname)" == "Darwin" ]; then \
FLASK_ENV=testing docker compose run --rm web pytest --doctest-modules -n $$(sysctl -n hw.logicalcpu) --dist=loadfile -v tests/ app; \
else \
FLASK_ENV=testing docker compose run --rm web pytest --doctest-modules -n $$(nproc --all) --dist=loadfile -v tests/ app; \
fi; \
else \
FLASK_ENV=testing docker compose run --rm web pytest --doctest-modules -v tests/ app -k $(name); \
fi
.PHONY: lint
lint:
docker compose run --no-deps --rm web /bin/bash -c 'flake8; mypy app --config="../mypy.ini"'
.PHONY: cleanassets
cleanassets:
rm -rf ./OpenOversight/app/static/dist/
.PHONY: stop
stop: ## Stop containers
docker compose stop
.PHONY: clean
clean: cleanassets stop ## Remove containers
docker compose rm -f
.PHONY: clean_all
clean_all: clean stop ## Wipe database
docker compose down -v
.PHONY: docs
docs: ## Build project documentation in live reload for editing
make -C docs/ clean && sphinx-autobuild docs/ docs/_build/html
.PHONY: help
help: ## Print this message and exit
@printf "OpenOversight: Makefile for development, documentation and testing.\n"
@printf "Subcommands:\n\n"
@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z_-]+:.*?## / {printf "\033[36m%s\033[0m : %s\n", $$1, $$2}' $(MAKEFILE_LIST) \
| sort \
| column -s ':' -t
.PHONY: attach
attach:
docker compose exec postgres psql -h localhost -U openoversight openoversight-dev
.PHONY: backup
backup:
ssh bpdwatch.com "bpdwatch.com/backup.sh"
scp bpdwatch.com:/srv/bpdwatch/bpdwatch.com.sql.gz backup/
gunzip -f backup/bpdwatch.com.sql.gz
.PHONY: import
import:
docker exec -it bpdwatch-development-postgres psql -U bpdwatch -d bpdwatch -f /backups/bpdwatch.com.sql
.PHONY: sync
sync: backup import
.PHONY: sync_staging
sync_staging: backup
ssh bpdwatch.com "gunzip -k -f /srv/bpdwatch/bpdwatch.com.sql.gz"
ssh bpdwatch.com "docker exec bpdwatch-staging-postgres psql -U bpdwatch -d bpdwatch -f /backups/bpdwatch.com.sql"