-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
212 lines (174 loc) · 8.32 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
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
SHELL := /bin/bash
GIT_BRANCH := $(shell git branch --show-current)
PRERELEASE := $(shell if [[ $(GIT_BRANCH) =~ main ]]; then echo '--minor'; else echo '--no-tag --no-commit'; fi)
PY_VENV := .venv/
UV_LOCKFILE := uv.lock
#------------------------------------------------------------------------------
# Default help target (thanks ChatGPT)
#------------------------------------------------------------------------------
help:
@echo "Available targets:"
@awk -F':' '/^[a-zA-Z0-9\._-]+:/ && !/^[ \t]*\.PHONY/ {print $$1}' $(MAKEFILE_LIST) | sort -u | column
#------------------------------------------------------------------------------
# DX: Use uv to bootstrap project
#------------------------------------------------------------------------------
$(UV_LOCKFILE):
uv lock --build-isolation
$(PY_VENV): $(UV_LOCKFILE)
uv sync --frozen
.PHONY: clean
clean:
rm -rf $(PY_VENV)
rm -f test_cm.db
rm -rf ./output
find src -type d -name '__pycache__' | xargs rm -rf
find tests -type d -name '__pycache__' | xargs rm -rf
.PHONY: update-deps
update-deps:
uv lock --upgrade --build-isolation
.PHONY: init
init: $(PY_VENV)
uv run playwright install
uv run pre-commit install
.PHONY: update
update: update-deps init
.PHONY: build
build: export BUILDKIT_PROGRESS=plain
build:
docker compose build cmservice
docker compose build cmworker
.PHONY: uv
uv:
script/bootstrap_uv
#------------------------------------------------------------------------------
# Target to create a "release" that consists of an increment of the version
# patch level in the appropriate file, a git commit and a matching git tag on
# the "main" trunk; else a prerelease version is created and no tag is created.
#------------------------------------------------------------------------------
.PHONY: release
release: export GIT_COMMIT_AUTHOR="$(shell git config user.name) <$(shell git config user.email)>"
release:
uv run semantic-release version $(PRERELEASE) --no-push --no-vcs-release --skip-build --no-changelog
#------------------------------------------------------------------------------
# Convenience targets to run pre-commit hooks ("lint") and mypy ("typing")
#------------------------------------------------------------------------------
.PHONY: lint
lint:
pre-commit run --all-files
.PHONY: typing
typing:
mypy src tests
#------------------------------------------------------------------------------
# Targets for develpers to debug against a local Postgres run under docker
# compose. Can be used on local machines and in github CI, but not on USDF dev
# nodes since we can't run docker there.
#------------------------------------------------------------------------------
.PHONY: run-compose
run-compose:
docker compose up --wait
.PHONY: psql
psql: PGPORT=$(shell docker compose port postgresql 5432 | cut -d: -f2)
psql: export DB__PASSWORD=INSECURE-PASSWORD
psql: run-compose
psql postgresql://cm-service:${DB__PASSWORD}@localhost:${PGPORT}/cm-service
.PHONY: test
test: PGPORT=$(shell docker compose port postgresql 5432 | cut -d: -f2)
test: export DB__URL=postgresql://cm-service@localhost:${PGPORT}/cm-service
test: export DB__PASSWORD=INSECURE-PASSWORD
test: export DB__SCHEMA=cm_service_test
test: run-compose
alembic upgrade head
pytest -vvv --asyncio-mode=auto --cov=lsst.cmservice --cov-branch --cov-report=term --cov-report=html ${PYTEST_ARGS}
.PHONY: run
run: PGPORT=$(shell docker compose port postgresql 5432 | cut -d: -f2)
run: export DB__URL=postgresql://cm-service@localhost:${PGPORT}/cm-service
run: export DB__PASSWORD=INSECURE-PASSWORD
run: export DB__ECHO=true
run: run-compose
alembic upgrade head
python3 -m lsst.cmservice.cli.server run
.PHONY: run-worker
run-worker: PGPORT=$(shell docker compose port postgresql 5432 | cut -d: -f2)
run-worker: export DB__URL=postgresql://cm-service@localhost:${PGPORT}/cm-service
run-worker: export DB__PASSWORD=INSECURE-PASSWORD
run-worker: export DB__ECHO=true
run-worker: run-compose
alembic upgrade head
python3 -m lsst.cmservice.daemon
.PHONY: migrate
migrate: export PGUSER=cm-service
migrate: export PGDATABASE=cm-service
migrate: export PGHOST=localhost
migrate: export DB__PORT=$(shell docker compose port postgresql 5432 | cut -d: -f2)
migrate: export DB__PASSWORD=INSECURE-PASSWORD
migrate: export DB__URL=postgresql://${PGHOST}/${PGDATABASE}
migrate: run-compose
alembic upgrade head
#------------------------------------------------------------------------------
# Targets for developers to debug running against local sqlite. Can be used on
# local machines or USDF dev nodes.
#------------------------------------------------------------------------------
.PHONY: test-sqlite
test-sqlite: export DB__URL=sqlite+aiosqlite://///test_cm.db
test-sqlite:
alembic -x cm_database_url=sqlite:///test_cm.db upgrade head
pytest -vvv --asyncio-mode=auto --cov=lsst.cmservice --cov-branch --cov-report=term --cov-report=html ${PYTEST_ARGS}
.PHONY: run-sqlite
run-sqlite: export DB__URL=sqlite+aiosqlite://///test_cm.db
run-sqlite: export DB__ECHO=true
run-sqlite:
alembic -x cm_database_url=sqlite:///test_cm.db upgrade head
python3 -m lsst.cmservice.cli.server run
.PHONY: run-worker-sqlite
run-worker-sqlite: export DB__URL=sqlite+aiosqlite://///test_cm.db
run-worker-sqlite: export DB__ECHO=true
run-worker-sqlite:
alembic -x cm_database_url=sqlite:///test_cm.db upgrade head
python3 -m lsst.cmservice.daemon
#------------------------------------------------------------------------------
# Targets for running per-developer service instances on USDF Rubin dev nodes,
# using a single shared backend cnpg Postgres in the usdf-cm-dev k8s vcluster.
# Currently used by most devs for development/debug, and also by pilots for
# production runs.
#
# FIXME: TO BE DEPRECATED as soon as we can reliably use shared phalanx service
# for production and sqlite for development/debug.
#------------------------------------------------------------------------------
.PHONY: psql-usdf-dev
psql-usdf-dev: export PGHOST=$(shell kubectl --cluster=usdf-cm-dev -n cm-service get svc/cm-pg-lb -o jsonpath='{..ingress[0].ip}')'
psql-usdf-dev: export PGPASSWORD=$(shell kubectl --cluster=usdf-cm-dev -n cm-service get secret/cm-pg-app -o jsonpath='{.data.password}' | base64 --decode)
psql-usdf-dev: export PGUSER=cm-service
psql-usdf-dev: export PGDATABASE=cm-service
psql-usdf-dev: ## Connect psql client to backend Postgres (shared USDF)
psql
.PHONY: test-usdf-dev
test-usdf-dev: DB__HOST=$(shell kubectl --cluster=usdf-cm-dev -n cm-service get svc/cm-pg-lb -o jsonpath='{..ingress[0].ip}')'
test-usdf-dev: export DB__URL=postgresql://cm-service@${DB__HOST}:5432/cm-service
test-usdf-dev: export DB__PASSWORD=$(shell kubectl --cluster=usdf-cm-dev -n cm-service get secret/cm-pg-app -o jsonpath='{.data.password}' | base64 --decode)
test-usdf-dev: export DB__SCHEMA=cm_service_test
test-usdf-dev:
pytest -vvv --cov=lsst.cmservice --cov-branch --cov-report=term --cov-report=html ${PYTEST_ARGS}
.PHONY: run-usdf-dev
run-usdf-dev:DB__HOST=$(shell kubectl --cluster=usdf-cm-dev -n cm-service get svc/cm-pg-lb -o jsonpath='{..ingress[0].ip}')'
run-usdf-dev: export DB__URL=postgresql://cm-service@${DB__HOST}:5432/cm-service
run-usdf-dev: export DB__PASSWORD=$(shell kubectl --cluster=usdf-cm-dev -n cm-service get secret/cm-pg-app -o jsonpath='{.data.password}' | base64 --decode)
run-usdf-dev: export DB__ECHO=true
run-usdf-dev:
alembic upgrade head
python3 -m lsst.cmservice.cli.server run
.PHONY: run-worker-usdf-dev
run-worker-usdf-dev: DB__HOST=$(shell kubectl --cluster=usdf-cm-dev -n cm-service get svc/cm-pg-lb -o jsonpath='{..ingress[0].ip}')
run-worker-usdf-dev: export DB__URL=postgresql://cm-service@${DB__HOST}:5432/cm-service
run-worker-usdf-dev: export DB__PASSWORD=$(shell kubectl --cluster=usdf-cm-dev -n cm-service get secret/cm-pg-app -o jsonpath='{.data.password}' | base64 --decode)
run-worker-usdf-dev: export DB__ECHO=true
run-worker-usdf-dev:
python3 -m lsst.cmservice.daemon
get-env-%: DB__HOST=$(shell kubectl --cluster=$* -n cm-service get svc/cm-pg-lb -o jsonpath='{..ingress[0].ip}')
get-env-%: export DB__URL=postgresql://cm-servicer@${DB__HOST}:5432/cm-service
get-env-%: export DB__PASSWORD=$(shell kubectl --cluster=$* -n cm-service get secret/cm-pg-app -o jsonpath='{.data.password}' | base64 --decode)
get-env-%: export DB__ECHO=true
get-env-%:
rm -f .env.$*
echo DB__URL=$${DB__URL} > .env.$*
echo DB__ECHO=$${DB__ECHO} >> .env.$*
echo DB__PASSWORD=$${DB__PASSWORD} >> .env.$*