Skip to content
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

Enables PIXL DB to operate as a service separate from Orthanc Raw #593

Merged
merged 42 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2c69f1b
Updates orthanc-raw postgres config
tomaroberts Jan 13, 2025
8521c34
define ORTHANC_RAW_DB_ vars
p-j-smith Jan 14, 2025
65142aa
pass orthanc-raw-db vars to orthanc-raw
p-j-smith Jan 14, 2025
4c0849c
Separate POSTGRES_PORT into PIXL_DB_ and ORTHANC_RAW_DB_
tomaroberts Jan 14, 2025
1dc0640
Adds PIXL DB service to system-test
tomaroberts Jan 14, 2025
eaf193d
Unique PIXL_DB and ORTHANC_RAW_DB .env values
tomaroberts Jan 14, 2025
1d1bb24
Merge branch 'main' into tom/517-separate-dbs
tomaroberts Jan 14, 2025
502f27e
Removes env_file: - already inherited from root docker-compose.yml
tomaroberts Jan 20, 2025
3d4ad07
Moves POSTGRES_PIXL_DB_HOST var to more logical location
tomaroberts Jan 27, 2025
2307d94
Fixes port numbering so 7001 always used for Orthanc Raw
tomaroberts Jan 27, 2025
9ce2348
Update .sample.env (so aligns with test/.env)
tomaroberts Jan 27, 2025
2d30097
Update service name to more explicitly reflect external db
tomaroberts Jan 27, 2025
b8d5ec3
Adds comment about postgres ports
tomaroberts Jan 27, 2025
f50d431
Revert "Update service name to more explicitly reflect external db"
tomaroberts Jan 27, 2025
9611dec
Updates system-test conftest external PIXL DB port
tomaroberts Jan 27, 2025
2feae68
Merge branch 'main' into tom/517-separate-dbs
tomaroberts Jan 27, 2025
6139c2b
Adds missing env variable
tomaroberts Jan 27, 2025
e1380ec
Minor README tweak for clarity
tomaroberts Jan 27, 2025
325d938
Updates README with newly introduced env variables
tomaroberts Jan 27, 2025
91456c7
Introduces env var CLI_PIXL_DB_PORT
tomaroberts Jan 29, 2025
b07d4ed
Updates variable naming
tomaroberts Jan 29, 2025
661b614
Creates postgres / postgres-exposed services and assigns profiles
tomaroberts Jan 29, 2025
eb38215
Adds service depends_on logic
tomaroberts Jan 29, 2025
a846438
Adds --profile option to run system tests
tomaroberts Jan 29, 2025
4cb9ebd
Update .env.sample
tomaroberts Jan 29, 2025
ca6c1fc
Fixes system test PIXL DB port number
tomaroberts Jan 29, 2025
6e0dd33
Adds default `--profile postgres-exposed` option to pixl dc up
tomaroberts Jan 29, 2025
3b63662
Adds pixl dc up start-up explanation
tomaroberts Jan 29, 2025
06d8a13
Update .env.sample
tomaroberts Jan 29, 2025
25eeef6
linting bugfix: extra whitespace
tomaroberts Jan 30, 2025
0c6e356
Updates export-api depends_on interaction with postgres dbs
tomaroberts Jan 30, 2025
30a3e7f
Amends order of pixl dc up args so docker compose command works
tomaroberts Jan 30, 2025
d05829d
Resolve linting error
tomaroberts Jan 30, 2025
fe6ba69
Amends location of "up" in args_list
tomaroberts Feb 3, 2025
49388be
Linting fix
tomaroberts Feb 3, 2025
ba3f495
Removes old env vars
tomaroberts Feb 3, 2025
e193d47
Update README.md
tomaroberts Feb 3, 2025
93a7cde
Removes orthanc-anon postgres dependency
tomaroberts Feb 3, 2025
0f6a5dc
Set --profile in pixl dc up using env var
tomaroberts Feb 5, 2025
3d7a8f3
Update README.md
tomaroberts Feb 5, 2025
e1c6d7b
Amend env var parsing to use decouple
tomaroberts Feb 5, 2025
5dfad17
Merge branch 'main' into tom/517-separate-dbs
tomaroberts Feb 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@ PIXL_QUERY_TIMEOUT=10
CLI_RETRY_SECONDS=300

# PIXL PostgreSQL instance
PIXL_DB_HOST=postgres
PIXL_DB_HOST=postgres-exposed
PIXL_DB_PORT=5432
PIXL_DB_NAME=pixl
PIXL_DB_USER=pixl
PIXL_DB_PASSWORD=
SKIP_ALEMBIC=false

# PIXL DB Postgres host
CLI_PIXL_DB_HOST=localhost

# Orthanc Raw PostgreSQL instance
ORTHANC_RAW_DB_HOST=postgres-exposed # change to `postgres` if PIXL DB is external postgres instance
tomaroberts marked this conversation as resolved.
Show resolved Hide resolved
ORTHANC_RAW_DB_PORT=5432
ORTHANC_RAW_DB_NAME=pixl
ORTHANC_RAW_DB_USER=pixl
ORTHANC_RAW_DB_PASSWORD=

# Exposed ports
HASHER_API_PORT=
POSTGRES_PORT=
CLI_PIXL_DB_PORT=
ORTHANC_ANON_DICOM_PORT=
ORTHANC_ANON_WEB_PORT=
ORTHANC_RAW_DICOM_PORT=
Expand Down
33 changes: 27 additions & 6 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,41 @@ uv sync

## Usage

**Note** The `rabbitmq`, `export-api` and `imaging-api` services must be started prior to using the CLI
**Note:** The `rabbitmq`, `export-api` and `imaging-api` services must be started prior to using the CLI
This is done by spinning up the necessary Docker containers through `docker compose`.

See general pixl commands and subcommands with:

```bash
pixl --help
```

### Starting PIXL

For convenience, we provide the `pixl dc` command, which acts as a wrapper for `docker compose`,
but takes care of some of the configuration for you.

See the commands and subcommands with
**1) Default Start-up**
```bash
pixl dc up
```
By default, `pixl dc up` runs with the option: `--profile postgres-exposed`. This means PIXL DB and Orthanc Raw
will share the same postgres instance.
tomaroberts marked this conversation as resolved.
Show resolved Hide resolved

**2) Start-up with External PIXL DB**
Set the port number environment variable of your external PIXL DB:
```bash
pixl --help
CLI_PIXL_DB_PORT=7001
```

Start-up PIXL:
```bash
pixl dc up --profile postgres
```

### Configuration

The `rabbitmq` and `postgres` services are configured by setting the following environment variables
The `rabbitmq` and PIXL DB `postgres` services are configured by setting the following environment variables
(default values shown):

```sh
Expand All @@ -42,8 +63,8 @@ RABBITMQ_PORT=7008
RABBITMQ_USERNAME=rabbitmq_username
RABBITMQ_PASSWORD=rabbitmq_password

POSTGRES_HOST=localhost
POSTGRES_PORT=7001
CLI_PIXL_DB_HOST=localhost
CLI_PIXL_DB_PORT=7001
PIXL_DB_USER=pixl_db_username
PIXL_DB_PASSWORD=pixl_db_password
PIXL_DB_NAME=pixl
Expand Down
4 changes: 2 additions & 2 deletions cli/src/pixl_cli/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"password": config("RABBITMQ_PASSWORD"),
},
"postgres": {
"host": config("POSTGRES_HOST"),
"port": int(config("POSTGRES_PORT")),
"host": config("CLI_PIXL_DB_HOST"),
"port": int(config("CLI_PIXL_DB_PORT")),
"username": config("PIXL_DB_USER"),
"password": config("PIXL_DB_PASSWORD"),
"database": config("PIXL_DB_NAME"),
Expand Down
15 changes: 14 additions & 1 deletion cli/src/pixl_cli/_docker_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,26 @@ def dc(args: tuple[str]) -> None:
docker_args = list(args)

if "up" in args:
docker_args = [*args, "--wait", "--build", "--remove-orphans"]
docker_args = _parse_up_args(args)
if "down" in args:
docker_args = _check_down_args(args)

run_docker_compose(docker_args, working_dir=PIXL_ROOT)


def _parse_up_args(args: tuple[str, ...]) -> list:
"""Check up args and define default profile if not set"""
args_list = list(args)
if "--profile" not in args:
args_list = [arg for arg in args_list if arg != "up"] + [
"--profile",
"postgres-exposed",
"up",
]
tomaroberts marked this conversation as resolved.
Show resolved Hide resolved
args_list.extend(["--wait", "--build", "--remove-orphans"])
return args_list


def _check_down_args(args: tuple[str, ...]) -> list:
"""Stop all the PIXL services"""
if config("ENV") == "prod" and "--volumes" in args:
Expand Down
61 changes: 54 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ x-pixl-db: &pixl-db
PIXL_DB_PASSWORD: ${PIXL_DB_PASSWORD}
PIXL_DB_NAME: ${PIXL_DB_NAME}

x-orthanc-raw-db: &orthanc-raw-db
ORTHANC_RAW_DB_HOST: ${ORTHANC_RAW_DB_HOST}
ORTHANC_RAW_DB_PORT: ${ORTHANC_RAW_DB_PORT}
ORTHANC_RAW_DB_USER: ${ORTHANC_RAW_DB_USER}
ORTHANC_RAW_DB_PASSWORD: ${ORTHANC_RAW_DB_PASSWORD}
ORTHANC_RAW_DB_NAME: ${ORTHANC_RAW_DB_NAME}

x-azure-keyvault: &azure-keyvault
AZURE_CLIENT_ID: ${EXPORT_AZ_CLIENT_ID}
AZURE_CLIENT_SECRET: ${EXPORT_AZ_CLIENT_PASSWORD}
Expand Down Expand Up @@ -160,6 +167,10 @@ services:
depends_on:
postgres:
condition: service_healthy
required: false
postgres-exposed:
condition: service_healthy
required: false
tomaroberts marked this conversation as resolved.
Show resolved Hide resolved
healthcheck:
test:
[
Expand All @@ -186,7 +197,7 @@ services:
platform: linux/amd64
command: /run/secrets
environment:
<<: [*pixl-db, *proxy-common, *pixl-common-env]
<<: [*orthanc-raw-db, *proxy-common, *pixl-common-env]
ORTHANC_NAME: "PIXL: Raw"
ORTHANC_USERNAME: ${ORTHANC_RAW_USERNAME}
ORTHANC_PASSWORD: ${ORTHANC_RAW_PASSWORD}
Expand Down Expand Up @@ -216,6 +227,10 @@ services:
depends_on:
postgres:
condition: service_healthy
required: false
postgres-exposed:
condition: service_healthy
required: false
orthanc-anon:
condition: service_started
healthcheck:
Expand Down Expand Up @@ -283,6 +298,10 @@ services:
condition: service_healthy
postgres:
condition: service_healthy
required: false
postgres-exposed:
condition: service_healthy
required: false
hasher-api:
condition: service_healthy
ports:
Expand Down Expand Up @@ -352,16 +371,17 @@ services:

################################################################################
# Data Stores
postgres:
postgres-exposed:
profiles: [postgres-exposed]
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}
POSTGRES_USER: ${ORTHANC_RAW_DB_USER}
POSTGRES_PASSWORD: ${ORTHANC_RAW_DB_PASSWORD}
POSTGRES_DB: ${ORTHANC_RAW_DB_NAME}
PGTZ: ${TZ:-Europe/London}
env_file:
- ./docker/common.env
Expand All @@ -371,9 +391,36 @@ services:
source: postgres-data
target: /var/lib/postgresql/data
ports:
- "${POSTGRES_PORT}:5432"
- "${CLI_PIXL_DB_PORT}:5432"
healthcheck:
test: ["CMD", "pg_isready", "-U", "${ORTHANC_RAW_DB_USER}", "--dbname", "${ORTHANC_RAW_DB_NAME}"]
interval: 10s
timeout: 30s
retries: 5
restart: always
networks:
- pixl-net
postgres:
profiles: [postgres]
build:
context: .
dockerfile: ./docker/postgres/Dockerfile
args:
<<: *build-args-common
environment:
POSTGRES_USER: ${ORTHANC_RAW_DB_USER}
POSTGRES_PASSWORD: ${ORTHANC_RAW_DB_PASSWORD}
POSTGRES_DB: ${ORTHANC_RAW_DB_NAME}
PGTZ: ${TZ:-Europe/London}
env_file:
- ./docker/common.env
command: postgres -c 'config_file=/etc/postgresql/postgresql.conf'
volumes:
- type: volume
source: postgres-data
target: /var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready", "-U", "${PIXL_DB_USER}", "--dbname", "${PIXL_DB_NAME}"]
test: ["CMD", "pg_isready", "-U", "${ORTHANC_RAW_DB_USER}", "--dbname", "${ORTHANC_RAW_DB_NAME}"]
interval: 10s
timeout: 30s
retries: 5
Expand Down
14 changes: 13 additions & 1 deletion orthanc/orthanc-raw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ secrets. Orthanc interprets all `.json` files in the `/run/secrets` mount as con

### Step 1

Save credentials `.env` for the VNA (primary) and PACS (secondary) Q/R targets, postgreSQL and 'Orthanc anon'.
Save credentials `.env` for the VNA (primary) and PACS (secondary) Q/R targets, postgreSQL and 'Orthanc Anon':
tomaroberts marked this conversation as resolved.
Show resolved Hide resolved
```
# PIXL PostgreSQL instance
PIXL_DB_HOST=
Expand All @@ -50,7 +50,19 @@ PIXL_DB_NAME=
PIXL_DB_USER=
PIXL_DB_PASSWORD=

# PIXL DB Postgres host
POSTGRES_PIXL_DB_HOST=localhost

# Orthanc Raw PostgreSQL instance
ORTHANC_RAW_DB_HOST=
ORTHANC_RAW_DB_PORT=
ORTHANC_RAW_DB_NAME=
ORTHANC_RAW_DB_USER=
ORTHANC_RAW_DB_PASSWORD=

# Exposed ports
POSTGRES_ORTHANC_RAW_DB_PORT=
POSTGRES_PIXL_DB_PORT=
ORTHANC_RAW_DICOM_PORT=XXXX
ORTHANC_RAW_WEB_PORT=YYYY

Expand Down
2 changes: 1 addition & 1 deletion orthanc/orthanc-raw/config/postgres.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"PostgreSQL" : {
"EnableIndex" : true,
"EnableStorage" : false,
"ConnectionUri" : "postgresql://${PIXL_DB_USER}:${PIXL_DB_PASSWORD}@${PIXL_DB_HOST}:${PIXL_DB_PORT}/${PIXL_DB_NAME}",
"ConnectionUri" : "postgresql://${ORTHANC_RAW_DB_USER}:${ORTHANC_RAW_DB_PASSWORD}@${ORTHANC_RAW_DB_HOST}:${ORTHANC_RAW_DB_PORT}/${ORTHANC_RAW_DB_NAME}",
"Lock" : true
}
}
15 changes: 12 additions & 3 deletions test/.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@ PIXL_MAX_MESSAGES_IN_FLIGHT=5
TZ=Europe/London

# PIXL PostgreSQL instance
PIXL_DB_HOST=postgres
PIXL_DB_HOST=postgres-pixl-db
PIXL_DB_PORT=5432
PIXL_DB_NAME=pixl
PIXL_DB_USER=pixl_db_username
PIXL_DB_PASSWORD=pixl_db_password
SKIP_ALEMBIC=false

# PIXL DB Postgres host
CLI_PIXL_DB_HOST=localhost

# Orthanc Raw PostgreSQL instance
ORTHANC_RAW_DB_HOST=postgres
ORTHANC_RAW_DB_PORT=5432
ORTHANC_RAW_DB_NAME=pixl
ORTHANC_RAW_DB_USER=orthanc_raw_db_username
ORTHANC_RAW_DB_PASSWORD=orthanc_raw_db_password

# Exposed ports
HASHER_API_PORT=7010
POSTGRES_PORT=7001
CLI_PIXL_DB_PORT=7001
ORTHANC_ANON_DICOM_PORT=7002
ORTHANC_ANON_WEB_PORT=7003
ORTHANC_RAW_DICOM_PORT=7004
Expand All @@ -29,7 +39,6 @@ RABBITMQ_ADMIN_PORT=7009
FTP_PORT=20021

# PIXL Export API
POSTGRES_HOST=localhost
PIXL_EXPORT_API_HOST=localhost

# PIXL Imaging API
Expand Down
25 changes: 25 additions & 0 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
volumes:
vna-qr-data:
postgres-pixl-db-data:

networks:
pixl-net:
Expand Down Expand Up @@ -73,3 +74,27 @@ services:
retries: 2
interval: 3s
timeout: 2s
postgres-pixl-db:
build:
context: ../
dockerfile: ./docker/postgres/Dockerfile
environment:
POSTGRES_USER: ${PIXL_DB_USER}
POSTGRES_PASSWORD: ${PIXL_DB_PASSWORD}
POSTGRES_DB: ${PIXL_DB_NAME}
PGTZ: ${TZ:-Europe/London}
command: postgres -c 'config_file=/etc/postgresql/postgresql.conf'
volumes:
- type: volume
source: postgres-pixl-db-data
target: /var/lib/postgresql/data
ports:
- "${CLI_PIXL_DB_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
4 changes: 2 additions & 2 deletions test/run-system-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 postgres -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 postgres -p system-test down --volumes
)
}

Expand Down