-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
142 lines (84 loc) · 2.73 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
# Projeto
srcdir = src
migrationsdir = migrations
testdir = tests
# Run
.PHONY: run
run:
poetry run fastapi dev $(srcdir)/madr/api.py
# Init
.PHONY: init init-settings init-python
init: init-settings init-python
init-settings:
[ -e .env ] || cp .env.example .env
init-python:
poetry install --sync
# Format
.PHONY: fmt fmt-python
fmt: fmt-python
fmt-python:
poetry run ruff check --select I001 --fix $(srcdir) $(migrationsdir) $(testdir)
poetry run ruff format $(srcdir) $(migrationsdir) $(testdir)
# Lint
.PHONY: lint lint-python lint-poetry lint-ruff-format lint-ruff-check lint-mypy lint-k8s lint-helm
lint: lint-python lint-k8s
lint-python: lint-poetry lint-ruff-format lint-ruff-check lint-mypy
lint-poetry:
poetry check --lock
lint-ruff-format:
poetry run ruff format --diff $(srcdir) $(migrationsdir) $(testdir)
lint-ruff-check:
poetry run ruff check $(srcdir) $(migrationsdir) $(testdir)
lint-mypy:
poetry run mypy --show-error-context --pretty $(srcdir) $(migrationsdir) $(testsdir)
lint-k8s: lint-helm
lint-helm:
helm lint chart
# Test
.PHONY: test test-python test-pytest coverage-html
test: test-python
test-python: test-pytest
test-pytest:
poetry run pytest --cov=madr --cov-report=term-missing --no-cov-on-fail --cov-fail-under=100 $(testdir)
coverage-html: test-pytest
poetry run coverage html
# Database
.PHONY: db-migrate db-gen-migrate db-test-migrate
db-migrate:
poetry run alembic upgrade head
db-gen-migrate:
poetry run alembic revision --autogenerate -m "$(shell read -rp 'Nome da migração: ' nome; echo "$$nome")"
db-test-migrate:
alembic upgrade head
alembic downgrade base
alembic upgrade head
alembic downgrade base
# Kubernetes
.PHONY: minikube-start minikube-stop minikube-delete minikube-dashboard minikube-run-app minikube-delete-app
minikube-start:
minikube start --addons=registry,ingress --insecure-registry 192.168.0.0/16
minikube-stop:
minikube stop
minikube-delete:
minikube delete
minikube-dashboard:
minikube dashboard --port=6001
minikube-run-app:
./scripts/deploy-in-k8s.sh k8s-values.yaml
kubectl wait deployments/madr-api --for=condition=available --timeout=-1s
kubectl port-forward service/madr-api 8000:80
minikube-delete-app:
helm uninstall madr
# Clean
.PHONY: clean clean-python clean-pycache clean-python-tools clean-k8s dist-clean
clean: clean-python clean-coverage clean-k8s
clean-python: clean-pycache clean-python-tools
clean-pycache:
find $(srcdir) $(migrationsdir) $(testdir) -name __pycache__ -exec rm -rf {} +
find $(srcdir) $(migrationsdir) $(testdir) -type d -empty -delete
clean-python-tools:
rm -rf .ruff_cache .mypy_cache .pytest_cache .coverage .coverage.* htmlcov
clean-k8s:
rm -rf k8s-values.yaml
dist-clean: clean
rm -rf .env .venv dist