-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
215 lines (177 loc) · 8.26 KB
/
Makefile
File metadata and controls
215 lines (177 loc) · 8.26 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# It'd be nice to keep these in sync with the defaults of the Dockerfiles
PYTHON_IMAGE_VER ?= 3.12
POSTGRES_IMAGE_VER ?= 18
ACT := act --rm --container-options "--privileged -u root" --container-architecture linux/amd64 --platform ubuntu-latest=catthehacker/ubuntu:act-latest
.DEFAULT_GOAL := help
## behave-django: runs behave inside the django containers against all of your features.
.Phony: behave-django
behave-django: compose.override.yml
@docker compose run --rm -w /app -e PYTHONPATH=/app/src django coverage run -a src/manage.py behave --no-input --simple
## behave-django-feature: runs a single django behave feature (append FEATURE=feature_name_here)
.Phony: behave-django-feature
behave-django-feature: compose.override.yml
@docker compose run --rm -w /app -e PYTHONPATH=/app/src django python src/manage.py behave --no-input --simple -i $(FEATURE)
## behave-translator: runs translator behave tests with coverage
.Phony: behave-translator
behave-translator: compose.override.yml
@docker compose exec -T translator coverage run --source=translator -m behave /app/tests/acceptance/features
@docker compose exec -T translator coverage xml -o /app/coverage.xml
## behave-translator-feature: runs a single translator behave feature (append FEATURE=feature_name_here)
.Phony: behave-translator-feature
behave-translator-feature: compose.override.yml
@docker compose exec -T translator python -m behave /app/tests/acceptance/features -i $(FEATURE)
## build: rebuilds all your containers or a single one if CONTAINER is specified
.Phony: build
build: compose.override.yml
@docker compose build --build-arg PYTHON_IMAGE_VER=$(PYTHON_IMAGE_VER) --build-arg POSTGRES_IMAGE_VER=$(POSTGRES_IMAGE_VER) $(CONTAINER)
@docker compose up -d --no-deps $(CONTAINER)
@docker compose restart $(CONTAINER)
## ci-test: runs all CI workflows locally via act; requires act (`brew install act`)
.Phony: ci-test
ci-test:
@$(ACT) push --workflows .github/workflows/ruff.yml
@$(ACT) push --workflows .github/workflows/scripts.yml
@$(ACT) push --workflows .github/workflows/scheduler.yml
@$(ACT) push --workflows .github/workflows/translator.yml
@$(ACT) push --workflows .github/workflows/django.yml
@$(ACT) push --workflows .github/workflows/type-check.yml
## clean: remove local containers and volumes
.Phony: clean
clean: compose.override.yml
@docker compose rm -f -s
@docker volume prune -f
## collectstatic: run collect static admin command
.Phony: collectstatic
collectstatic: compose.override.yml
@docker compose run --rm django python manage.py collectstatic
# Since toggle-(local|prod) are phony targets, this file is not
# tracked to compare if its "newer" so running another target with
# this as a prereq will not run this target again. That would
# overwrite compose.override.yml back to compose.override.local.yml no
# matter what, which is bad. Phony targets prevents this
## compose.override.yml: creates file compose.override.yml on first run (as a prereq)
compose.override.yml:
@ln -sf compose.override.local.yml compose.override.yml
## copy-libs: copy the translator autogenerated libraries into the translator directory
.Phony: copy-libs
copy-libs:
@docker compose cp translator:/app/gobgp_pb2.py translator/
@docker compose cp translator:/app/gobgp_pb2.pyi translator/
@docker compose cp translator:/app/gobgp_pb2_grpc.py translator/
@docker compose cp translator:/app/attribute_pb2.py translator/
@docker compose cp translator:/app/attribute_pb2.pyi translator/
@docker compose cp translator:/app/attribute_pb2_grpc.py translator/
@docker compose cp translator:/app/capability_pb2.py translator/
@docker compose cp translator:/app/capability_pb2.pyi translator/
@docker compose cp translator:/app/capability_pb2_grpc.py translator/
## django-addr: get the IP and ephemeral port assigned to docker:8000
.Phony: django-addr
django-addr: compose.override.yml
@docker compose port django 8000
## django-open: open a browser for http://$(make django-addr)
.Phony: django-open
django-open: compose.override.yml
@open http://$$(make django-addr)
## django-url: get the URL based on http://$(make django-addr)
.Phony: django-url
django-url: compose.override.yml
@echo http://$$(make django-addr)
## docs-build: build the documentation
.Phony: docs-build
docs-build:
@docker compose run --rm docs mkdocs build
## docs-serve: build and run a server with the documentation
.Phony: docs-serve
docs-serve:
@docker compose run --rm docs mkdocs serve -a 0.0.0.0:8888
## down: turn down docker compose stack
.Phony: down
down: compose.override.yml
@docker compose down
## exec: executes a given command on a given container (append CONTAINER=container_name_here and COMMAND=command_here)
.Phony: exec
exec: compose.override.yml
@docker compose exec $(CONTAINER) $(COMMAND)
## gobgp-neighbor: shows the gobgp neighbor information (append neighbor IP for specific information)
.Phony: gobgp-neighbor
gobgp-neighbor: compose.override.yml
@docker compose exec gobgp gobgp neighbor $(NEIGHBOR)
# This automatically builds the help target based on commands prepended with a double hashbang
## help: print this help output
.Phony: help
help: Makefile
@sed -n 's/^##//p' $<
## integration-django: runs multi-instance system tests against docker compose running containers
.Phony: integration-django
integration-django: run
@docker compose exec -T -w /app -e PYTHONPATH=/app/src django coverage run -a src/manage.py behave --no-input --use-existing-database src/scram/route_manager/tests/integration
# TODO: When we move to flowspec this -a flag will change
## list-routes: list gobgp routes
.Phony: list-routes
list-routes: compose.override.yml
@docker compose exec gobgp gobgp global rib -a ipv4
@docker compose exec gobgp gobgp global rib -a ipv6
## migrate: makemigrations and then migrate
.Phony: migrate
migrate: compose.override.yml
@docker compose run --rm django python manage.py makemigrations
@docker compose run --rm django python manage.py migrate
## pass-reset: change admin's password
.Phony: pass-reset
pass-reset: compose.override.yml
@docker compose run --rm django python manage.py changepassword admin
## pytest-django: runs pytest inside the django container
.Phony: pytest-django
pytest-django: compose.override.yml
@docker compose run --rm -w /app -e PYTHONPATH=/app/src django coverage run -m pytest
## run: brings up the containers as described in compose.override.yml
.Phony: run
run: compose.override.yml
@docker compose up -d
## stop: turns off running containers
.Phony: stop
stop: compose.override.yml
@docker compose stop
## tail-log: tail a docker container's logs (append CONTAINER=container_name_here)
.Phony: tail-log
tail-log: compose.override.yml
@docker compose logs -f $(CONTAINER)
## test: run all tests (django + translator + scheduler + scripts)
.Phony: test
test: test-django test-translator test-scheduler test-scripts
## test-django: start everything and then run all django tests (pytest + behave + integration) generating coverage
.Phony: test-django
test-django: toggle-local build migrate run pytest-django behave-django integration-django
@docker compose run --rm -w /app django coverage report
@docker compose run --rm -w /app django coverage xml
## test-scheduler: runs scheduler package tests with coverage
.Phony: test-scheduler
test-scheduler:
@cd scheduler && uv run pytest
## test-scripts: runs scripts package tests with coverage
.Phony: test-scripts
test-scripts:
@cd scripts && uv run pytest tests/
## test-translator: start everything and run translator behave tests with coverage
.Phony: test-translator
test-translator: toggle-local build migrate run behave-translator
## toggle-local: configure make to use the local stack
.Phony: toggle-local
toggle-local:
@ln -sf compose.override.local.yml compose.override.yml
## toggle-prod: configure make to use the production stack
.Phony: toggle-prod
toggle-prod:
@ln -sf compose.override.production.yml compose.override.yml
## type-check: static type checking
.Phony: type-check
type-check: compose.override.yml
@docker compose run --rm -w /app -e PYTHONPATH=/app/src django mypy src/scram
## update-env-docs: update environment variable documentation append CHECK=true to get a diff if not up to date
.Phony: update-env-docs
update-env-docs:
ifeq ($(CHECK),true)
@uv run scripts/src/scripts/extract_env_vars.py --check
else
@uv run scripts/src/scripts/extract_env_vars.py
endif