-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
319 lines (255 loc) · 13.3 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
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
INFRA_FOLDER="$(shell pwd)/infra/configurations/"
HOST_MIGRATIONS_FOLDER=$(shell pwd)/backend/src/main/resources/db/migration
SHELL := /bin/bash
.SHELLFLAGS = -ec
.SILENT:
MAKEFLAGS += --silent
.ONESHELL:
.DEFAULT_GOAL: help
.PHONY: help ##OTHER 🛟 To display this prompts. This will list all available targets with their documentation
help:
echo "❓ Use \`make <target>' where <target> is one of 👇"
echo ""
echo -e "\033[1mLocal Development\033[0m:"
grep -E '^\.PHONY: [a-zA-Z0-9_-]+ .*?##LOCAL' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = "(: |##LOCAL)"}; {printf "\033[36m%-30s\033[0m %s\n", $$2, $$3}'
echo ""
echo -e "\033[1mTesting\033[0m:"
grep -E '^\.PHONY: [a-zA-Z0-9_-]+ .*?##TEST' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = "(: |##TEST)"}; {printf "\033[36m%-30s\033[0m %s\n", $$2, $$3}'
echo ""
echo -e "\033[1mCommands for RUN (STAGING and PROD)\033[0m:"
grep -E '^\.PHONY: [a-zA-Z0-9_-]+ .*?##RUN' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = "(: |##RUN)"}; {printf "\033[36m%-30s\033[0m %s\n", $$2, $$3}'
echo ""
echo -e "\033[1mOther commands\033[0m:"
grep -E '^\.PHONY: [a-zA-Z0-9_-]+ .*?##OTHER' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = "(: |##OTHER)"}; {printf "\033[36m%-30s\033[0m %s\n", $$2, $$3}'
echo ""
echo "Tips 💡"
echo " - use tab for auto-completion"
echo " - use the dry run option '-n' to show what make is attempting to do. example: environmentName=dev make -n deploy"
docker-env:
cd ./infra/docker && ../../frontend/node_modules/.bin/import-meta-env-prepare -u -x ./.env.local.defaults\
################################################################################
# Local Development
.PHONY: check-clean-archi ##LOCAL Check clean architecture imports
check-clean-archi:
cd backend/tools && ./check-clean-architecture.sh
.PHONY: clean ##LOCAL Clean all backend assets and stop docker containers
clean: docker-env
rm -Rf ./backend/target
docker compose down -v
docker compose --env-file ./infra/docker/.env -f ./infra/docker/docker-compose.monitorenv.dev.yml down -v
docker compose --env-file ./infra/docker/.env -f ./infra/docker/docker-compose.cypress.yml down -v
docker compose -f ./infra/docker/docker-compose.puppeteer.yml down -v
.PHONY: generate-test-data ##LOCAL Generate test data (SQL files from .jsonc)
generate-test-data:
cd frontend && npm run generate:testdata
compile-back:
cd backend && ./gradlew assemble
init-local-sig:
./infra/local/postgis_insert_layers.sh && ./infra/init/geoserver_init_layers.sh
.PHONY: install-front ##LOCAL ⬇️ Install frontend dependencies
install-front:
cd ./frontend && npm i
.PHONY: run-back ##LOCAL ▶️ Run backend API
run-back: run-stubbed-apis
docker compose up -d --quiet-pull --wait db keycloak
cd backend && ./gradlew bootRun --args='--spring.profiles.active=local --spring.config.additional-location=$(INFRA_FOLDER)'
.PHONY: run-front ##LOCAL ▶️ Run frontend for development
run-front:
cd ./frontend && npm run dev
.PHONY: run-back-with-monitorenv ##LOCAL ▶️ Run backend API when running MonitorEnv app (in another terminal)
run-back-with-monitorenv: run-monitorenv
docker compose up -d --quiet-pull --wait db
cd backend && MONITORENV_URL=http://localhost:9880 ./gradlew bootRun --args='--spring.profiles.active=local --spring.config.additional-location=$(INFRA_FOLDER)'
.PHONY: run-monitorenv ##LOCAL ▶️ Run MonitorEnv app containers
run-monitorenv: docker-env
docker compose \
--project-directory ./infra/docker \
--env-file ./infra/docker/.env \
-f ./infra/docker/docker-compose.monitorenv.dev.yml \
up -d monitorenv_app
.PHONY: lint-back ##LOCAL 🪮 ✨ Lint and format backend code
lint-back:
cd ./backend && ./gradlew ktlintFormat | grep -v \
-e "Exceeded max line length" \
-e "Package name must not contain underscore" \
-e "Wildcard import"
run-stubbed-apis:
docker compose stop geoserver-monitorenv-stubs
docker compose up -d --quiet-pull --wait geoserver-monitorenv-stubs
stop-stubbed-apis:
docker stop cypress-geoserver-1
update-test-data:
cd frontend && node ./scripts/generate_test_data_seeds.js
dev-backup-db:
@export CONFIG_FILE_PATH=$$(pwd)/infra/dev/database/pg_backup.config; \
./infra/remote/backup/pg_backup_rotated.sh
dev-restore-db:
docker compose down -v
docker compose up -d --quiet-pull --wait db
sleep 5
@export CONFIG_FILE_PATH=$$(pwd)/infra/dev/database/pg_backup.config; \
./infra/remote/backup/pg_restore.sh -t "$(TAG)"
################################################################################
# Testing
.PHONY: test ##TEST ✅ Run all tests
test: test-back
cd frontend && CI=true npm run test:unit -- --coverage
.PHONY: run-back-for-cypress ##TEST ▶️ Run backend API when using Cypress 📝
run-back-for-cypress: run-stubbed-apis
docker compose up -d --quiet-pull --wait db keycloak
cd backend && MONITORFISH_SCHEDULING_ENABLED=false ./gradlew bootRun --args='--spring.profiles.active=local --spring.config.additional-location=$(INFRA_FOLDER)'
.PHONY: run-cypress ##TEST ▶️ Run Cypress 📝
run-cypress:
cd ./frontend && npm run test:e2e:open
.PHONY: run-puppeteer ##TEST ▶️ Run Puppeteer 📝
run-puppeteer:
cd ./frontend && npm run test:multi-windows:open
test-back: check-clean-archi
@if [ -z "$(class)" ]; then \
echo "Running all Backend tests..."; \
cd backend && ./gradlew clean test; \
else \
echo "Running single Backend test class $(class)..."; \
cd backend && ./gradlew test --console plain --no-continue --parallel --tests "$(class)"; \
fi
.PHONY: test-back-watch ##TEST ✅ Watch backend tests
test-back-watch:
./backend/scripts/test-watch.sh
.PHONY: run-back-with-monitorenv-for-cypress ##TEST ▶️ Run backend API when using Cypress connected to a local MonitorEnv app 📝
run-back-with-monitorenv-for-cypress: run-monitorenv run-stubbed-apis
docker compose up -d --quiet-pull --wait db keycloak
cd backend && MONITORENV_URL=http://localhost:9880 MONITORFISH_OIDC_ENABLED=false MONITORFISH_SCHEDULING_ENABLED=false ./gradlew bootRun --args='--spring.profiles.active=local --spring.config.additional-location=$(INFRA_FOLDER)'
.PHONY: run-back-for-puppeteer ##TEST ▶️ Run backend API when using Puppeteer 📝
run-back-for-puppeteer: docker-env run-stubbed-apis
docker compose up -d --quiet-pull --wait db
docker compose -f ./infra/docker/docker-compose.puppeteer.yml up -d monitorenv-app
cd backend && MONITORFISH_OIDC_ENABLED=false MONITORENV_URL=http://localhost:9880 ./gradlew bootRun --args='--spring.profiles.active=local --spring.config.additional-location=$(INFRA_FOLDER)'
.PHONY: run-front-for-puppeteer ##TEST ▶️ Run frontend when using Puppeteer 📝
run-front-for-puppeteer:
cd ./frontend && npm run dev-puppeteer
################################################################################
# Remote (Integration / Production)
# ----------------------------------------------------------
# Remote: Run commands
.PHONY: restart-remote-app ##RUN ▶️ Restart app
restart-remote-app:
cd infra/remote && docker compose pull && docker compose up -d --build app --force-recreate
.PHONY: register-pipeline-flows-prod ##RUN ▶️ Register pipeline flows in PROD
register-pipeline-flows-prod:
docker pull docker.pkg.github.com/mtes-mct/monitorfish/monitorfish-pipeline:$(MONITORFISH_VERSION) && \
infra/remote/data-pipeline/register-flows-prod.sh
.PHONY: register-pipeline-flows-int ##RUN ▶️ Register pipeline flows in STAGING
register-pipeline-flows-int:
docker pull docker.pkg.github.com/mtes-mct/monitorfish/monitorfish-pipeline:$(MONITORFISH_VERSION) && \
infra/remote/data-pipeline/register-flows-int.sh
.PHONY: init-remote-sig ##RUN Initialize Geoserver layers
init-remote-sig:
./infra/remote/postgis_insert_layers.sh && ./infra/init/geoserver_init_layers.sh
################################################################################
# Database upgrade
check-database-extensions-versions:
docker exec -i monitorfish_database bash < infra/remote/database_upgrade/check_extensions_versions.sh
update-database-extensions:
docker exec -i monitorfish_database bash < infra/remote/database_upgrade/update_timescaledb.sh && \
docker exec -i monitorfish_database bash < infra/remote/database_upgrade/update_postgis.sh
upgrade-postgres-11-to-13:
docker run --rm \
-v $(PG_11_DATA_VOLUME_NAME):/var/lib/postgresql/11/data \
-v $(PG_13_DATA_VOLUME_NAME):/var/lib/postgresql/13/data \
ghcr.io/mtes-mct/monitorfish/monitorfish-database-upgrade:pg11_to_pg13-ts2.3.1-postgis3.3.4 -O "-c timescaledb.restoring='on'" -O "-c shared_preload_libraries=timescaledb";
upgrade-postgres-13-to-16-dev:
docker run --rm \
-v $(PG_13_DATA_VOLUME_NAME):/var/lib/postgresql/13/data \
-v $(PG_16_DATA_VOLUME_NAME):/var/lib/postgresql/16/data \
ghcr.io/mtes-mct/monitorfish/monitorfish-database-upgrade:pg13_to_pg16-ts2.14.2-postgis3.4.2 -O "-c timescaledb.restoring='on'" -O "-c shared_preload_libraries=timescaledb";
print_pg_conf_files:
docker run --rm -i \
-v $(DB_DATA_VOLUME_NAME):/var/lib/postgresql/data \
debian:buster \
bash < infra/remote/database_upgrade/print_pg_conf_files.sh;
fix_pg_hba:
docker run --rm \
-v $(DB_DATA_VOLUME_NAME):/var/lib/postgresql/data \
debian:buster \
bash -c 'echo "host all all all md5" >> /var/lib/postgresql/data/pg_hba.conf';
add_timescaledb_to_shared_preload_libraries:
docker run --rm \
-v $(DB_DATA_VOLUME_NAME):/var/lib/postgresql/data \
debian:buster \
bash -c "echo \"shared_preload_libraries = 'timescaledb'\" >> /var/lib/postgresql/data/postgresql.conf";
################################################################################
# CI
# ----------------------------------------------------------
# CI: App Commands
docker-build:
docker build --no-cache -f infra/docker/app/Dockerfile . -t monitorfish-app:$(VERSION) \
--build-arg VERSION=$(VERSION) \
--build-arg ENV_PROFILE=$(ENV_PROFILE) \
--build-arg GITHUB_SHA=$(GITHUB_SHA) \
--build-arg SENTRY_URL=$(SENTRY_URL) \
--build-arg SENTRY_AUTH_TOKEN=$(SENTRY_AUTH_TOKEN) \
--build-arg SENTRY_ORG=$(SENTRY_ORG) \
--build-arg SENTRY_PROJECT=$(SENTRY_PROJECT)
docker-tag:
docker tag monitorfish-app:$(VERSION) docker.pkg.github.com/mtes-mct/monitorfish/monitorfish-app:$(VERSION)
docker-push:
docker push docker.pkg.github.com/mtes-mct/monitorfish/monitorfish-app:$(VERSION)
docker-compose-down:
docker compose -f ./infra/docker/docker-compose.cypress.yml down -v
docker-compose-up:
docker compose -f ./infra/docker/docker-compose.cypress.yml up -d --quiet-pull db
docker compose -f ./infra/docker/docker-compose.cypress.yml up --quiet-pull flyway
docker compose -f ./infra/docker/docker-compose.cypress.yml up -d --quiet-pull app
@printf 'Waiting for backend app to be ready'
@until curl --output /dev/null --silent --fail "http://localhost:8880/api/v1/healthcheck"; do printf '.' && sleep 1; done
docker-compose-puppeteer-up: docker-env
docker compose -f ./infra/docker/docker-compose.puppeteer.yml up -d monitorenv-app
docker compose -f ./infra/docker/docker-compose.puppeteer.yml up -d monitorfish-app
@printf 'Waiting for MonitorEnv app to be ready'
@until curl --output /dev/null --silent --fail "http://localhost:9880/api/v1/healthcheck"; do printf '.' && sleep 1; done
@printf 'Waiting for MonitorFish app to be ready'
@until curl --output /dev/null --silent --fail "http://localhost:8880/api/v1/healthcheck"; do printf '.' && sleep 1; done
# ----------------------------------------------------------
# CI: Pipeline Commands
docker-build-pipeline:
docker build -f ./infra/docker/datapipeline/Dockerfile . -t monitorfish-pipeline:$(VERSION)
docker-test-pipeline:
docker run --network host -v /var/run/docker.sock:/var/run/docker.sock -u monitorfish-pipeline:$(DOCKER_GROUP) --env-file datascience/.env.test --env HOST_MIGRATIONS_FOLDER=$(HOST_MIGRATIONS_FOLDER) monitorfish-pipeline:$(VERSION) coverage run -m pytest --pdb tests
docker-tag-pipeline:
docker tag monitorfish-pipeline:$(VERSION) docker.pkg.github.com/mtes-mct/monitorfish/monitorfish-pipeline:$(VERSION)
docker-push-pipeline:
docker push docker.pkg.github.com/mtes-mct/monitorfish/monitorfish-pipeline:$(VERSION)
# ----------------------------------------------------------
# Remote: Pipeline commands
install-pipeline:
cd datascience && poetry install
test-pipeline:
cd datascience && export TEST_LOCAL=True && poetry run coverage run -m pytest --pdb tests/ && poetry run coverage report && poetry run coverage html
# ----------------------------------------------------------
# Remote: Database commands
backup-db:
./infra/remote/backup/pg_backup_rotated.sh
restore-db:
./infra/remote/backup/pg_restore.sh
# ----------------------------------------------------------
# ???: Documentation commands
push-docs-to-transifex:
cd datascience/docs && \
poetry run sphinx-build -b gettext -D extensions="sphinx.ext.viewcode","sphinx.ext.napoleon" source pot && \
poetry run tx config mapping-bulk --project monitorfish --file-extension '.pot' --source-file-dir pot --source-lang en --type PO --expression 'locale/<lang>/LC_MESSAGES/{filepath}/{filename}.po' --execute && \
poetry run tx push --source
pull-translated-docs-from-transifex:
cd datascience/docs && \
poetry run tx pull --all
build-docs-locally:
cd datascience/docs && \
poetry run sphinx-build -b html source build/html/en && \
poetry run sphinx-build -b html -D language=fr source build/html/fr
################################################################################
# Alias commands
dev: clean run-back
dev-monitorenv: clean run-back-with-monitorenv