forked from jonra1993/fastapi-alembic-sqlmodel-async
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
144 lines (118 loc) · 3.81 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/make
include .env
define SERVERS_JSON
{
"Servers": {
"1": {
"Name": "fastapi-alembic",
"Group": "Servers",
"Host": "$(DATABASE_HOST)",
"Port": 5432,
"MaintenanceDB": "postgres",
"Username": "$(DATABASE_USER)",
"SSLMode": "prefer",
"PassFile": "/tmp/pgpassfile"
}
}
}
endef
export SERVERS_JSON
help:
@echo "make"
@echo " install"
@echo " Install all packages of poetry project locally."
@echo " run-dev-build"
@echo " Run development docker compose and force build containers."
@echo " run-dev"
@echo " Run development docker compose."
@echo " stop-dev"
@echo " Stop development docker compose."
@echo " run-prod"
@echo " Run production docker compose."
@echo " stop-prod"
@echo " Run production docker compose."
@echo " init-db"
@echo " Init database with sample data."
@echo " add-dev-migration"
@echo " Add new database migration using alembic."
@echo " upgrade-migration"
@echo " This helps to upgrade pending migrations."
@echo " run-pgadmin"
@echo " Run pgadmin4."
@echo " load-server-pgadmin"
@echo " Load server on pgadmin4."
@echo " clean-pgadmin"
@echo " Clean pgadmin4 data."
@echo " formatter"
@echo " Apply black formatting to code."
@echo " lint"
@echo " Lint code with ruff, and check if black formatter should be applied."
@echo " lint-watch"
@echo " Lint code with ruff in watch mode."
@echo " lint-fix"
@echo " Lint code with ruff and try to fix."
@echo " run-sonarqube"
@echo " Starts Sonarqube container."
@echo " run-sonar-scanner"
@echo " Starts Sonarqube container."
@echo " stop-sonarqube"
@echo " Stops Sonarqube container."
install:
cd backend/app && \
poetry shell && \
poetry install
run-dev-build:
docker compose -f docker-compose-dev.yml up --build
run-dev:
docker compose -f docker-compose-dev.yml up
stop-dev:
docker compose -f docker-compose-dev.yml down
run-prod:
docker compose up
stop-prod:
docker compose down
create-celery-db:
if ! docker compose -f docker-compose-dev.yml exec database psql -U ${DATABASE_USER} -h localhost -lqt | cut -d \| -f 1 | grep -qw ${DATABASE_CELERY_NAME}; then \
docker compose -f docker-compose-dev.yml exec database createdb -U ${DATABASE_USER} -W ${DATABASE_PASSWORD} -h localhost -O ${DATABASE_USER} ${DATABASE_CELERY_NAME}; \
fi
init-db:
docker compose -f docker-compose-dev.yml exec fastapi_server python app/initial_data.py && \
echo "Initial data created."
formatter:
cd backend/app && \
poetry run black app
lint:
cd backend/app && \
poetry run ruff app && poetry run black --check app
mypy:
cd backend/app && \
poetry run mypy .
lint-watch:
cd backend/app && \
poetry run ruff app --watch
lint-fix:
cd backend/app && \
poetry run ruff app --fix
run-sonarqube:
docker compose -f docker-compose-sonarqube.yml up
stop-sonarqube:
docker compose -f docker-compose-sonarqube.yml down
run-sonar-scanner:
docker run --rm -v "${PWD}/backend:/usr/src" sonarsource/sonar-scanner-cli -X
add-dev-migration:
docker compose -f docker-compose-dev.yml exec fastapi_server alembic revision --autogenerate && \
docker compose -f docker-compose-dev.yml exec fastapi_server alembic upgrade head && \
echo "Migration added and applied."
upgrade-migration:
docker compose -f docker-compose-dev.yml exec fastapi_server alembic upgrade head && \
echo "Migration upgraded."
run-pgadmin:
echo "$$SERVERS_JSON" > ./pgadmin/servers.json && \
docker volume create pgadmin_data && \
docker compose -f pgadmin.yml up --force-recreate
clean-pgadmin:
docker volume rm pgadmin_data
run-test:
docker compose -f docker-compose-test.yml up --build
pytest:
docker compose -f docker-compose-test.yml exec fastapi_server pytest