Skip to content

Commit

Permalink
Limit orthanc raw storage size (#181)
Browse files Browse the repository at this point in the history
* Fix env variable names in `delete_oldest_n_studies.py`

These new variable names are consistent with what is set in `.env` and
`test/.env.test`

* Add MaximumStorageSize config for orthanc-raw

* MaximumStorageSize needs to be an integer

* Revert "Fix env variable names in `delete_oldest_n_studies.py`"

This reverts commit 0842f43.

* Set orthanc raw maximum storage in Dockerfile (#179)

* Set orthanc raw maximum storage in Dockerfile

* Orthanc raw defaults to no limit on storage

Saves us from faffing around with build args
for other tests

* Format README

* Document `ORTHANC_RAW_MAXIMUM_STORAGE_SIZE`

* Add simple test for `ORTHANC_RAW_MAXIMUM_STORAGE_SIZE`

---------

Co-authored-by: Milan Malfait <[email protected]>

---------

Co-authored-by: Milan Malfait <[email protected]>
  • Loading branch information
stefpiatek and milanmlft authored Dec 13, 2023
1 parent 2e8a496 commit 44c9226
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ORTHANC_RAW_USERNAME=
ORTHANC_RAW_PASSWORD=
ORTHANC_RAW_AE_TITLE=
ORTHANC_AUTOROUTE_RAW_TO_ANON=true
ORTHANC_RAW_MAXIMUM_STORAGE_SIZE= // MB

# PIXL Orthanc anon instance
ORTHANC_ANON_USERNAME=
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,14 @@ on the target storage account. The storage account must also allow network acces

#### Ports

Most services need to expose ports that must be mapped to ports on the host. The host port is specified in `.env`
Ports need to be configured such that they don't clash with any other application running on that GAE.
Most services need to expose ports that must be mapped to ports on the host. The host port is specified in `.env`
Ports need to be configured such that they don't clash with any other application running on that GAE.

#### Storage size

The maximum storage size of the `orthanc-raw` instance can be configured through the `ORTHANC_RAW_MAXIMUM_STORAGE_SIZE`
environment variable in `.env`. This limits the storage size to the specified value (in MB). When the storage is full
[Orthanc will automatically recycle older studies in favour of new ones](https://orthanc.uclouvain.be/book/faq/features.html#id8).

## Run

Expand Down Expand Up @@ -199,8 +205,10 @@ select count(*) from emap_data.ehr_anon where xray_report is not null;
## Develop

See each service's README for instructions for individual developing and testing instructions.

For Python development we use [ruff](https://docs.astral.sh/ruff/) alongside [pytest](https://www.pytest.org/).
There is support (sometimes through plugins) for these tools in most IDEs & editors.

Before raising a PR, **run the full test suite** from the _PIXL_ directory with

```bash
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ services:
dockerfile: ./docker/orthanc-raw/Dockerfile
args:
<<: *build-args-common
ORTHANC_RAW_MAXIMUM_STORAGE_SIZE: ${ORTHANC_RAW_MAXIMUM_STORAGE_SIZE}
command: /run/secrets
environment:
<<: [*pixl-db, *proxy-common, *pixl-common-env]
Expand All @@ -165,6 +166,7 @@ services:
ORTHANC_PASSWORD: ${ORTHANC_RAW_PASSWORD}
ORTHANC_RAW_AE_TITLE: ${ORTHANC_RAW_AE_TITLE}
ORTHANC_AUTOROUTE_RAW_TO_ANON: ${ORTHANC_AUTOROUTE_RAW_TO_ANON}
ORTHANC_RAW_MAXIMUM_STORAGE_SIZE: ${ORTHANC_RAW_MAXIMUM_STORAGE_SIZE}
VNA_AE_TITLE : ${VNA_AE_TITLE}
VNA_DICOM_PORT: ${VNA_DICOM_PORT}
VNA_IP_ADDR: ${VNA_IP_ADDR}
Expand All @@ -181,7 +183,6 @@ services:
- type: volume
source: orthanc-raw-data
target: /var/lib/orthanc/db
- ${PWD}/orthanc/orthanc-raw/config:/run/secrets:ro
networks:
- pixl-net
depends_on:
Expand Down
7 changes: 6 additions & 1 deletion docker/orthanc-raw/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
FROM osimis/orthanc:22.9.0-full-stable
SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-x", "-c"]

COPY ./orthanc/orthanc-raw/plugin/pixl.py /etc/orthanc/pixl.py
ARG ORTHANC_RAW_MAXIMUM_STORAGE_SIZE

COPY ./orthanc/orthanc-raw/plugin/pixl.py /etc/orthanc/pixl.py
# Orthanc can't substitute environment veriables as integers so copy and replace before running
COPY ./orthanc/orthanc-raw/config /run/secrets
RUN sed -i "s/\${ORTHANC_RAW_MAXIMUM_STORAGE_SIZE}/${ORTHANC_RAW_MAXIMUM_STORAGE_SIZE:-0}/g" /run/secrets/orthanc.json
7 changes: 5 additions & 2 deletions orthanc/orthanc-raw/config/orthanc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
// doubling them, or replaced by forward slashes "/".
"StorageDirectory" : "/var/lib/orthanc/db",

// Limit the maximum number of instances
"MaximumPatientCount": 20000,
// Limit the maximum storage size
"MaximumPatientCount" : 0, // no limit
"MaximumStorageSize" : ${ORTHANC_RAW_MAXIMUM_STORAGE_SIZE}, // MB, replaced in Dockerfile because its an integer
"MaximumStorageMode" : "Recycle",


// Path to the directory that holds the SQLite index (if unset, the
// value of StorageDirectory is used). This index could be stored on
Expand Down
1 change: 1 addition & 0 deletions test/.env.test.sample
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ORTHANC_RAW_USERNAME=orthanc_raw_username
ORTHANC_RAW_PASSWORD=orthanc_raw_password
ORTHANC_RAW_AE_TITLE=ORTHANCRAW
ORTHANC_AUTOROUTE_RAW_TO_ANON=true
ORTHANC_RAW_MAXIMUM_STORAGE_SIZE=1

# PIXL Orthanc anon instance
ORTHANC_ANON_USERNAME=orthanc_anon_username
Expand Down
1 change: 1 addition & 0 deletions test/run-system-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pixl start
sleep 65 # need to wait until the DICOM image is "stable" = 60s
./scripts/check_entry_in_pixl_anon.sh
./scripts/check_entry_in_orthanc_anon.sh
./scripts/check_max_storage_in_orthanc_raw.sh

cd "${PACKAGE_DIR}"
docker compose -f docker-compose.yml -f ../docker-compose.yml -p test down
Expand Down
21 changes: 21 additions & 0 deletions test/scripts/check_max_storage_in_orthanc_raw.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
# Copyright (c) University College London Hospitals NHS Foundation Trust
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eux pipefail

# This could be much improved by having more realistic test data some of
# which actually was persisted
source ./.env.test
docker logs test-orthanc-raw-1 2>&1 | grep "At most ${ORTHANC_RAW_MAXIMUM_STORAGE_SIZE}MB will be used for the storage area"

0 comments on commit 44c9226

Please sign in to comment.