-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
296 lines (255 loc) · 10.1 KB
/
Copy pathMakefile
File metadata and controls
296 lines (255 loc) · 10.1 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# Makefile
# set NPD_DEVELOPMENT to "True" in your shell to skip dangerous action
# confirmation steps
NPD_DEVELOPMENT ?= no
# default target
.DEFAULT_GOAL := help
help:
@echo "Available commands:"
@echo ""
@echo " build Build all Docker containers for the application"
@echo " setup Set up development environment (build + create-db + migrate)"
@echo " install-tools Install development support tools"
@echo " update Update development environment"
@echo ""
@echo " create-db Start postgres, create and populate a development DB"
@echo " migrate Apply pending migrations to the development database"
@echo " refresh-views Refresh all materialized views in the development database"
@echo ""
@echo " up Start the NPD application at http://localhost:8000"
@echo " down Stop all running docker compose services"
@echo " up-datadog Start the NPD application with datadog at http://localhost:8000"
@echo ""
@echo " test Run the full frontend and backend test suites with DB setup"
@echo " test-setup Set up test database (drop/create test DB + run test migrations)"
@echo " test-backend Run the backend test suite without rerunning database setup"
@echo " Use ARGS=... to pass arguments"
@echo " test-frontend Run the frontend test suite"
@echo " Use ARGS=... to pass arguments"
@echo " test-server Start a test server for e2e testing with Playwright"
@echo " playwright-local Create a test server and run the playwright e2e test suite (on host)"
@echo " playwright-local-ui Create a test server and run the playwright e2e test suite (on host) in ui mode"
@echo " playwright-uat Fetch test records and run the playwright e2e test suite against a deployed environment"
@echo ""
@echo " clean Remove cache files, test artifacts, and transient frontend assets"
@echo ""
@echo " lint Check code against the appropriate linter (ruff or eslint)"
@echo " format Format code with the approrpriate formatter (ruff or prettier)"
@echo ""
@echo " createsuperuser Interactively set up a Django superuser account."
@echo " Pass env vars to run automatically:"
@echo " DJANGO_SUPERUSER_EMAIL"
@echo " DJANGO_SUPERUSER_USERNAME"
@echo " DJANGO_SUPERUSER_PASSWORD"
@echo ""
@echo " drop-db \033[31m[DANGEROUS]\033[0m Drop the development database"
@echo " reset-db \033[31m[DANGEROUS]\033[0m Drop and fully recreate the development database"
@echo ""
@echo " help Show this help message"
@echo ""
@echo "Common workflows:"
@echo " First time setup: make setup && make install-tools && make up"
@echo " Daily development: git pull && make update && make up"
@echo " Before committing: make test && make lint"
@echo " Run isolated tests: make test"
@echo " Run e2e tests: make test-server &; make playwright"
@echo " Run some tests: make test-backend ARGS=npdfhir.tests"
@echo " Run one test: make test-backend ARGS=provider_directory.tests.test_frontend_settings.TestFeatureFlags.test_returns_flags_json"
@echo " Clean shutdown: make down && make clean"
.PHONY: build
build:
@docker compose build
.PHONY: install-tools
install-tools:
@echo "Setting up local python virtual environment"
@$(MAKE) -C backend .venv/bin/activate
@source backend/.venv/bin/activate; \
echo "Setting up local development tools using $(shell which pip)"; \
$(MAKE) -C backend install-tools; \
pre-commit install
@echo "Setting up playwright on host"
@cd playwright; \
npm install; \
npx playwright install --with-deps chromium;
.PHONY: lint
lint:
@echo "\033[2m[ lint backend ]\033[0m"
@$(MAKE) -C backend lint
@echo "\033[2m[ lint frontend ]\033[0m"
@bin/npr npm run lint
.PHONY: format
format:
@echo "\033[2m[ format backend ]\033[0m"
@$(MAKE) -C backend format
@echo "\033[2m[ format frontend ]\033[0m"
@bin/npr npm run format
###
## Database management
###
.PHONY: drop-db
drop-db:
ifneq ($(NPD_DEVELOPMENT), True)
@printf "Are you sure you want to drop your local database? [y/N] " && read ans && ( [[ "$${ans:-N}" == y ]] || ( echo "cancelling changes" && exit 1 ) )
endif
@echo "Dropping development database..."
@docker compose up -d --wait db
@docker compose run --rm db sh -c 'echo "dropping $$NPD_DB"; PGPASSWORD=$$POSTGRES_PASSWORD psql -h db -U $$POSTGRES_USER -d postgres -c "DROP DATABASE IF EXISTS $$NPD_DB" || echo "failed to drop $$NPD_DB"'
.PHONY: create-db
create-db:
@echo "Creating development database..."
@docker compose up -d --wait db
# create development database only if it doesn't already exist
@docker compose run --rm db sh -c '\
echo "ensuring $$NPD_DB exists"; \
printf "%s\n" \
"SELECT '\''CREATE DATABASE $$NPD_DB'\''" \
"WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '\''$$NPD_DB'\'')\\gexec" \
| PGPASSWORD=$$POSTGRES_PASSWORD psql -v ON_ERROR_STOP=1 -h db -U $$POSTGRES_USER -d postgres \
'
# refresh all materialized views in the development database
.PHONY: refresh-views
refresh-views:
@echo "Refreshing materialized views..."
@docker compose exec db psql -U postgres -d $${NPD_DB_NAME:-npd} -c "\
REFRESH MATERIALIZED VIEW npd.organization_view; \
REFRESH MATERIALIZED VIEW npd.provider_to_location_view; \
REFRESH MATERIALIZED VIEW npd.provider_view; \
REFRESH MATERIALIZED VIEW npd.organization_affiliation; \
"
@echo "Materialized views refreshed."
# run all flyway migrations for the development environment
.PHONY: migrate
migrate:
@echo "Migrating the development database..."
@docker compose up -d db
@bin/npr migrate
@$(MAKE) refresh-views
# drop, create, and then run all flyway migrations for the development environment
.PHONY: reset-db
reset-db:
@echo "Resetting the development database..."
@docker compose down db
@$(MAKE) drop-db
@$(MAKE) create-db
@$(MAKE) migrate
###
# Frontend asset management
###
.PHONY: clean-frontend
clean-frontend:
@echo "Removing frontend assets from backend/provider_directory/static"
@rm -rf backend/provider_directory/static/*
@rm -rf backend/provider_directory/static/.vite
# only rebuild frontend assets if they don't already exist
backend/provider_directory/static/.vite/manifest.json:
@echo "Building frontend assets with VITE_API_BASE_URL=$(VITE_API_BASE_URL)"
@bin/npr npm install
@bin/npr -e VITE_API_BASE_URL=$(VITE_API_BASE_URL) npm run build
.PHONY: build-frontend-assets
build-frontend-assets: clean-frontend
export VITE_API_BASE_URL=http://localhost:8000; \
$(MAKE) backend/provider_directory/static/.vite/manifest.json
# build frontend assets and ensure the backend application is running
.PHONY: up
up:
@echo "Staring django-web and web services..."
@docker compose up -d django-web web
@echo "Backend is running"
@echo " site: http://localhost:8000/"
@echo " docs: http://localhost:8000/fhir/docs/"
.PHONY: down
down:
@echo "Shutting down all docker compose services..."
@docker compose down
.PHONY: test-down
test-down:
@echo "Shutting down all test docker compose services..."
@docker compose -f compose.test.yml down
.PHONY: test-setup
test-setup:
@echo "Setting up test database..."
@docker compose -f compose.test.yml up -d --wait db
# drop, create, and migrate test database
@docker compose -f compose.test.yml exec db sh -c 'echo "DROP $$POSTGRES_DB"; PGPASSWORD=$$POSTGRES_PASSWORD psql -q -h localhost -U "$$POSTGRES_USER" -d postgres -c "DROP DATABASE IF EXISTS $$POSTGRES_DB"'
@docker compose -f compose.test.yml exec db sh -c 'echo "CREATE $$POSTGRES_DB"; PGPASSWORD=$$POSTGRES_PASSWORD psql -q -h localhost -U "$$POSTGRES_USER" -d postgres -c "CREATE DATABASE $$POSTGRES_DB"'
@bin/npr -t migrate
.PHONY: test-backend
test-backend:
@echo "Running backend tests..."
@bin/npr -t python manage.py test $(ARGS)
.PHONY: test-frontend
test-frontend:
@echo "Running frontend tests..."
@bin/npr npm test $(ARGS)
.PHONY: test
test: test-setup
@$(MAKE) test-backend
@$(MAKE) test-frontend
.PHONY: playwright-local
playwright-local: test-down test-system-setup build-frontend-test-assets
@cd playwright; \
npx playwright test --project=local
.PHONY: playwright-local-ui
playwright-local-ui: test-down test-system-setup build-frontend-test-assets
@cd playwright; \
npx playwright test --project=local --ui
.PHONY: playwright-uat
playwright-uat:
@cd playwright; \
npm run get-data-and-test
# clean up test artifacts
.PHONY: clean
clean: clean-frontend
@$(MAKE) -C backend clean
###
# Data seeding utilities
###
.PHONY: createsuperuser
createsuperuser:
ifeq ($(and $(DJANGO_SUPERUSER_EMAIL),$(DJANGO_SUPERUSER_USERNAME),$(DJANGO_SUPERUSER_PASSWORD)),)
@bin/npr python manage.py createsuperuser
else
@bin/npr \
-e DJANGO_SUPERUSER_EMAIL="$(DJANGO_SUPERUSER_EMAIL)" \
-e DJANGO_SUPERUSER_USERNAME="$(DJANGO_SUPERUSER_USERNAME)" \
-e DJANGO_SUPERUSER_PASSWORD="$(DJANGO_SUPERUSER_PASSWORD)" \
python manage.py createsuperuser --no-input
endif
.PHONY: seed-users
seed-users:
@bin/npr \
-e DJANGO_SUPERUSER_EMAIL="npd.admin@cms.hhs.gov" \
-e DJANGO_SUPERUSER_USERNAME="npdadmin" \
-e DJANGO_SUPERUSER_PASSWORD="password123" \
python manage.py createsuperuser --no-input
##
# end-to-end test support
##
.PHONY: build-frontend-test-assets
build-frontend-test-assets: clean-frontend
export VITE_API_BASE_URL=http://localhost:8008; \
$(MAKE) backend/provider_directory/static/.vite/manifest.json
.PHONY: watch-frontend-test-assets
watch-frontend-test-assets:
bin/npr -e VITE_API_BASE_URL=http://localhost:8008 npm run watch
.PHONY: test-system-setup
test-system-setup: test-setup
bin/npr --test python manage.py seeduser
bin/npr --test python manage.py seedsystem
.PHONY: test-server
test-server: test-system-setup build-frontend-test-assets
docker compose -f compose.test.yml up django-web
###
# whole project concerns
###
# prepare the local working copy for NPD development
.PHONY: setup
setup: build create-db migrate
@$(MAKE) -C backend setup
# bring local working copy up to date
.PHONY: update
update: build migrate build-frontend-assets
# run the app locally with datadog
.PHONY: up-datadog
up-datadog:
@docker compose -f compose.datadog.yml up --build