-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve native execution #702
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
.PHONY: start | ||
|
||
# Read values as needed from .env | ||
# | ||
# Optionally pass 'environment=<something>' to load env vars from '.env.something' instead | ||
# Useful to separate i.e. dev from testing databases | ||
# | ||
# If using the same variables in recipes that need to use a dotenv file other | ||
# than .env, remember to check that no values from .env are being used | ||
# inadvertently. | ||
ENVFILE := $(if $(environment), .env-test-e2e, .env) | ||
ENVFILE := $(if $(environment),.env.$(environment),.env) | ||
ifneq (,$(wildcard $(ENVFILE))) | ||
include $(ENVFILE) | ||
DOCKER_COMPOSE_FILE := --env-file $(ENVFILE) | ||
export | ||
endif | ||
|
||
CIENV := $(if $(filter $(environment), ci), -f docker-compose-test-e2e.ci.yml , -f docker-compose-test-e2e.local.yml) | ||
API_DB_INSTANCE := $(if $(environment), test-e2e-postgresql-api, postgresql-api) | ||
GEO_DB_INSTANCE := $(if $(environment), test-e2e-postgresql-geo-api, postgresql-geo-api) | ||
REDIS_INSTANCE := $(if $(environment), test-e2e-redis, redis) | ||
API_DB_INSTANCE := $(if $(filter $(IS_DOCKER_E2E_TESTS_RUNTIME), true), test-e2e-postgresql-api, postgresql-api) | ||
GEO_DB_INSTANCE := $(if $(filter $(IS_DOCKER_E2E_TESTS_RUNTIME), true), test-e2e-postgresql-geo-api, postgresql-geo-api) | ||
REDIS_INSTANCE := $(if $(filter $(IS_DOCKER_E2E_TESTS_RUNTIME), true), test-e2e-redis, redis) | ||
|
||
DOCKER_COMPOSE_FILE := $(if $(environment), -f docker-compose-test-e2e.yml $(CIENV), -f docker-compose.yml ) | ||
DOCKER_COMPOSE_FILE := $(DOCKER_COMPOSE_FILE) $(if $(filter $(IS_DOCKER_E2E_TESTS_RUNTIME), true), -f docker-compose-test-e2e.yml, -f docker-compose.yml ) | ||
DOCKER_CLEAN_VOLUMES := $(if $(environment), , \ | ||
docker volume rm -f marxan-cloud_marxan-cloud-postgresql-api-data && \ | ||
docker volume rm -f marxan-cloud_marxan-cloud-postgresql-geo-data && \ | ||
|
@@ -29,7 +33,6 @@ NC :=\033[0m # No Color | |
test-commands: | ||
@echo $(ENVFILE) | ||
@echo $(DOCKER_COMPOSE_FILE) | ||
@echo $(CIENV) | ||
@echo $(API_POSTGRES_DB) | ||
@echo $(GEO_POSTGRES_USER) | ||
|
||
|
@@ -103,7 +106,7 @@ seed-geoapi-init-data: | |
sed -e "s/\$$feature_id/$$featureid/g" api/apps/api/test/fixtures/features/$${table_name}.sql | docker-compose $(DOCKER_COMPOSE_FILE) exec -T $(GEO_DB_INSTANCE) psql -U "${GEO_POSTGRES_USER}"; \ | ||
done; | ||
|
||
# need notebook service to execute a expecific notebook. this requires a full geodb | ||
# need notebook service to execute a specific notebook. this requires a full geodb | ||
generate-geo-test-data: extract-geo-test-data | ||
docker-compose --project-name ${COMPOSE_PROJECT_NAME} -f ./data/docker-compose.yml exec marxan-science-notebooks papermill --progress-bar --log-output work/notebooks/Lab/convert_csv_sql.ipynb /dev/null | ||
mv -f -u -Z data/data/processed/test-wdpa-data.sql api/apps/api/test/fixtures/test-wdpa-data.sql | ||
|
@@ -124,8 +127,7 @@ test-start-services: clean-slate | |
docker-compose $(DOCKER_COMPOSE_FILE) exec -T api ./apps/api/entrypoint.sh run-migrations-for-e2e-tests && \ | ||
docker-compose $(DOCKER_COMPOSE_FILE) exec -T geoprocessing ./apps/geoprocessing/entrypoint.sh run-migrations-for-e2e-tests | ||
|
||
seed-dbs-e2e: test-start-services | ||
$(MAKE) seed-api-with-test-data | ||
seed-dbs-e2e: test-start-services seed-api-with-test-data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this happens to work, but is not fully correct, because |
||
|
||
test-e2e-api: seed-dbs-e2e | ||
docker-compose $(DOCKER_COMPOSE_FILE) exec -T api ./apps/api/entrypoint.sh test-e2e | ||
|
@@ -134,13 +136,7 @@ test-e2e-geoprocessing: seed-dbs-e2e | |
docker-compose $(DOCKER_COMPOSE_FILE) exec -T geoprocessing ./apps/geoprocessing/entrypoint.sh test-e2e | ||
|
||
test-e2e-backend: test-e2e-api test-e2e-geoprocessing | ||
$(MAKE) test-clean-slate | ||
|
||
run-test-e2e-local: | ||
$(MAKE) --keep-going test-e2e-backend environment=local | ||
|
||
run-test-e2e-ci: | ||
$(MAKE) --keep-going test-e2e-backend environment=ci | ||
$(MAKE) test-clean-slate $(ARGS) | ||
|
||
setup-test-unit-backend: | ||
# build API and geoprocessing containers | ||
|
@@ -157,7 +153,7 @@ test-unit-geo: | |
test-unit-backend: setup-test-unit-backend test-unit-api test-unit-geo | ||
|
||
run-test-unit: | ||
$(MAKE) --keep-going test-unit-backend | ||
$(MAKE) --keep-going test-unit-backend $(ARGS) | ||
|
||
dump-geodb-data: | ||
docker-compose exec -T postgresql-geo-api pg_dump -T migrations -a -U "${GEO_POSTGRES_USER}" -F t ${GEO_POSTGRES_DB} | gzip > data/data/processed/db_dumps/geo_db-$$(date +%Y-%m-%d).tar.gz | ||
|
@@ -236,4 +232,5 @@ native-seed-geoapi-init-data: | |
done; | ||
|
||
native-seed-api-with-test-data: native-db-migrate native-seed-api-init-data | native-seed-geoapi-init-data | ||
kgajowy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@echo "seeding db with testing project and scenarios" | ||
psql -U "${API_POSTGRES_USER}" -h "${API_POSTGRES_HOST}" ${API_POSTGRES_DB} < api/apps/api/test/fixtures/test-data.sql |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
"concurrency": 50 | ||
}, | ||
"postgresApi": { | ||
"url": null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am fine with your suggestion. IIRC I copypasta'd this strategy from earlier projects as I thought it would be a good way to on one hand let devs configure each aspect of the connection through a separate envvar (in case they want/need to define or override only some values while leaving the rest to env defaults or other defaults), while allowing to configure staging/prod environments with one single variable. But of course it's part of a set-once-and-forget-about-it flow, so mapping 6 vars instead of 1 in a k8s manifest is not the end of the world either 😄 . |
||
"port": 5432, | ||
"host": null, | ||
"username": null, | ||
|
@@ -27,7 +26,6 @@ | |
"logging": "error" | ||
}, | ||
"postgresGeoApi": { | ||
"url": null, | ||
"port": 5432, | ||
"host": null, | ||
"username": null, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,14 @@ process.env.NETWORK_CORS_ORIGINS = extraCorsOrigin; | |
import { AppConfig } from './config.utils'; | ||
|
||
describe('AppConfig', () => { | ||
beforeAll(() => { | ||
if (process.env.NODE_CONFIG_DIR !== 'apps/api/config') { | ||
throw Error( | ||
`Running the test suite with NODE_CONFIG_DIR=${process.env.NODE_CONFIG_DIR}, which may cause this test to fail. Please use NODE_CONFIG_DIR=apps/api/config.`, | ||
); | ||
} | ||
Comment on lines
+12
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. due to how In the long run, I would suggest to replace the mechanism with https://docs.nestjs.com/techniques/configuration There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree, the Nest-y way would be handy as part of a future tech debt cleanup (and alignment with the Nest way wherever there's no need to go ad-hoc). |
||
}); | ||
|
||
describe('getFromArrayAndParsedString', () => { | ||
// Expected full result from `network.cors.origins`. If updating the default | ||
// list in `config`, relevant tests should break and this list should be | ||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the way you added the ability to manage arbitrary environments and then adapted the previous hardcoded special treatment of two environments (ci and non-ci) here, but I am not clear (no wonder, it's make-land and it's late Friday afternoon) how this new bool var is supposed to be working: I don't have it defined locally, so IIUC the else branch of these conditional assignments should be used, but then e2e tests still work fine, so I am losing the plot.
Irrespective of my puzzlement, I would suggest to add a comment (in the Makefile itself, maybe, for this all to be self-contained? or in the main
README.md
to go along all/most of the other env vars we may use in.env
files) about how to use this var and when/where to set it.