From 828f0076025c827d2a46633e7803ee401d5d8b9e Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Tue, 28 Jan 2025 16:33:39 +0000 Subject: [PATCH 1/3] Make pixl cli use POSTGRES_EXTERNAL_PORT if present in .env --- cli/src/pixl_cli/_config.py | 3 +++ test/.env | 3 +++ 2 files changed, 6 insertions(+) diff --git a/cli/src/pixl_cli/_config.py b/cli/src/pixl_cli/_config.py index 7a4f578cc..d33fb7a52 100644 --- a/cli/src/pixl_cli/_config.py +++ b/cli/src/pixl_cli/_config.py @@ -37,6 +37,9 @@ }, } # type: dict +if config("POSTGRES_EXTERNAL_PORT"): + SERVICE_SETTINGS["postgres"]["port"] = int(config("POSTGRES_EXTERNAL_PORT")) + class APIConfig: """API Configuration""" diff --git a/test/.env b/test/.env index 5b2f8a634..80a532c25 100644 --- a/test/.env +++ b/test/.env @@ -15,6 +15,9 @@ PIXL_DB_USER=pixl_db_username PIXL_DB_PASSWORD=pixl_db_password SKIP_ALEMBIC=false +# External postgres +POSTGRES_EXTERNAL_PORT=7011 + # Exposed ports HASHER_API_PORT=7010 POSTGRES_PORT=7001 From 1eed259791d1dc0e45f7f8710b25bd0305307387 Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Tue, 28 Jan 2025 16:34:29 +0000 Subject: [PATCH 2/3] Adds postgres-external service with profile external-pixl-db --- docker-compose.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 0f4c753b3..5323edbc9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -62,6 +62,7 @@ volumes: orthanc-anon-data: orthanc-raw-data: postgres-data: + external-pixl-db-data: exports: rabbitmq: @@ -380,3 +381,32 @@ services: restart: always networks: - pixl-net + postgres-external: + profiles: [external-pixl-db] + build: + context: . + dockerfile: ./docker/postgres/Dockerfile + args: + <<: *build-args-common + environment: + POSTGRES_USER: ${PIXL_DB_USER} + POSTGRES_PASSWORD: ${PIXL_DB_PASSWORD} + POSTGRES_DB: ${PIXL_DB_NAME} + PGTZ: ${TZ:-Europe/London} + env_file: + - ./docker/common.env + command: postgres -c 'config_file=/etc/postgresql/postgresql.conf' + volumes: + - type: volume + source: external-pixl-db-data + target: /var/lib/postgresql/data + ports: + - "${POSTGRES_EXTERNAL_PORT}:5432" + healthcheck: + test: ["CMD", "pg_isready", "-U", "${PIXL_DB_USER}", "--dbname", "${PIXL_DB_NAME}"] + interval: 10s + timeout: 30s + retries: 5 + restart: always + networks: + - pixl-net From a4c9fc217f9f133effcccf31a3974b04bb5c6b43 Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Tue, 28 Jan 2025 16:35:07 +0000 Subject: [PATCH 3/3] Invoke external-pixl-db profile in system-test --- test/run-system-test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/run-system-test.sh b/test/run-system-test.sh index da7c71fd7..7efd9dd5d 100755 --- a/test/run-system-test.sh +++ b/test/run-system-test.sh @@ -28,14 +28,14 @@ setup() { # Warning: Requires to be run from the project root ( cd "${PACKAGE_DIR}" - docker compose --env-file test/.env --env-file test/.secrets.env -p system-test up --wait -d --build + docker compose --env-file test/.env --env-file test/.secrets.env --profile external-pixl-db -p system-test up --wait -d --build ) } teardown() { ( cd "${PACKAGE_DIR}" - docker compose -f docker-compose.yml -f test/docker-compose.yml -p system-test down --volumes + docker compose -f docker-compose.yml -f test/docker-compose.yml --profile external-pixl-db -p system-test down --volumes ) }