/
makefile
111 lines (73 loc) · 2.63 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
105
106
107
108
109
110
111
MODULE = gyrosg
include .env
################
# DEV COMMANDS #
################
.PHONY: run-dev
run-dev:
env/bin/python -m uvicorn app.main:app --reload --host 0.0.0.0 --port ${SERVER_PORT}
.PHONY: clean
clean:
rm -rf env || true
python3 -m venv env
.PHONY: develop
develop:
env/bin/pip install -r requirements.txt
.PHONY: requirements
requirements:
env/bin/pip freeze > requirements.txt
.PHONY: format
format:
env/bin/python -m black app tests
.PHONY: test
test:
env/bin/python -m pytest tests
.PHONY: create-dev-db
create-dev-db:
PGPASSWORD=gyrosg psql postgres -U gyrosg -h localhost -c "CREATE DATABASE ${DB_NAME};"
PGPASSWORD=gyrosg psql postgres -U gyrosg -h localhost -c "CREATE DATABASE ${MODULE}_test;"
.PHONY: clean-dev-db
clean-dev-db:
PGPASSWORD=gyrosg psql postgres -U gyrosg -h localhost -c "DROP DATABASE IF EXISTS ${DB_NAME};"
PGPASSWORD=gyrosg psql postgres -U gyrosg -h localhost -c "CREATE DATABASE ${DB_NAME};"
.PHONY: clean-test-db
clean-test-db:
PGPASSWORD=gyrosg psql postgres -U gyrosg -h localhost -c "DROP DATABASE IF EXISTS ${MODULE}_test;"
PGPASSWORD=gyrosg psql postgres -U gyrosg -h localhost -c "CREATE DATABASE ${MODULE}_test;"
.PHONY: create-migrations
create-migrations:
@read -p "Enter a migration name for this migration: " MIGRATION_NAME; \
GYROSG_API_ENV=dev env/bin/python -m alembic revision --autogenerate -m $$MIGRATION_NAME
.PHONY: migrate-dev
migrate-dev:
GYROSG_API_ENV=dev env/bin/python -m alembic upgrade head
.PHONY: migrate-rollback
migrate-rollback:
GYROSG_API_ENV=dev env/bin/python -m alembic downgrade -1
.PHONY: init-dev-db
init-dev-db: migrate-dev
env/bin/python -m app.init_db
.PHONY: deploy-dev
deploy-dev:
rsync -av -e 'ssh -i ~/.ssh/gyrosg-server.pem' --exclude '.env' --exclude 'env' --exclude '.git*' --exclude '.idea*' --exclude 'tests' . \
ubuntu@gyrosg-api.com:~/gyrosg/dev/server
#################
# PROD COMMANDS #
#################
.PHONY: deploy-prod
deploy-prod:
rsync -av -e 'ssh -i ~/.ssh/gyrosg-server.pem' --exclude '.env' --exclude 'env' --exclude '.git*' --exclude '.idea*' --exclude 'tests' . \
ubuntu@gyrosg-api.com:~/gyrosg/server
.PHONY: create-prod-db
create-prod-db:
PGPASSWORD=gyrosg psql postgres -U gyrosg -h localhost -c "CREATE DATABASE ${DB_NAME};"
.PHONY: migrate-prod
migrate-prod:
GYROSG_API_ENV=prod env/bin/python -m alembic upgrade head
.PHONY: clean-prod-db
clean-prod-db:
PGPASSWORD=gyrosg psql postgres -U gyrosg -h localhost -c "DROP DATABASE IF EXISTS ${DB_NAME};"
PGPASSWORD=gyrosg psql postgres -U gyrosg -h localhost -c "CREATE DATABASE ${MODULE};"
.PHONY: init-prod-db
init-prod-db: migrate-prod
env/bin/python -m app.init_db