From 3018263c254329484ca6eae877e1176450e74547 Mon Sep 17 00:00:00 2001 From: DavidCroftDKFZ <46788708+DavidCroftDKFZ@users.noreply.github.com> Date: Thu, 27 Jun 2024 15:49:09 +0200 Subject: [PATCH] Added extra environment variables to make this image more Bridgehead-compatible. Also updated used package versions where possible. --- Dockerfile | 10 ++++++---- README.md | 9 +++++++++ docker-compose.yml | 4 ++-- run.sh | 32 +++++++++++++++++++++++++++++--- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8687eda..7925377 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,17 +5,19 @@ RUN apt-get -y update && apt-get -y install curl WORKDIR /app # Get bbmri-fhir-gen, for generating test data -RUN curl -LO https://github.com/samply/bbmri-fhir-gen/releases/download/v0.3.0/bbmri-fhir-gen-0.3.0-linux-amd64.tar.gz -RUN tar xzf bbmri-fhir-gen-0.3.0-linux-amd64.tar.gz +RUN curl -LO https://github.com/samply/bbmri-fhir-gen/releases/download/v0.4.0/bbmri-fhir-gen-0.4.0-linux-amd64.tar.gz +RUN tar xzf bbmri-fhir-gen-*-linux-amd64.tar.gz RUN mv ./bbmri-fhir-gen /usr/local/bin/bbmri-fhir-gen RUN bbmri-fhir-gen --version # Get blazectl, for uploading data to a FHIR store -RUN curl -LO https://github.com/samply/blazectl/releases/download/v0.3.0/blazectl-0.3.0-linux-amd64.tar.gz -RUN tar xzf blazectl-0.3.0-linux-amd64.tar.gz +RUN curl -LO https://github.com/samply/blazectl/releases/download/v0.15.1/blazectl-0.15.1-linux-amd64.tar.gz +RUN tar xzf blazectl-*-linux-amd64.tar.gz RUN mv ./blazectl /usr/local/bin/blazectl RUN blazectl --version +RUN apt-get -y update && apt-get -y purge curl + RUN mkdir -p /app/sample COPY run.sh /app/run.sh RUN chmod a+rx /app/run.sh diff --git a/README.md b/README.md index 4b3f1ee..27559e7 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,15 @@ The test data loader is configured using environment variables: |-------------------------------------------|--------------------------------------------------------------------------------------------------------------------|----------------------------------| | `FHIR_STORE_URL` | HTTP Address of the FHIR store | http://store:8080/fhir | | `PATIENT_COUNT` | Number of patients to be generated. | 100 | +| `START_DELAY` | Time in seconds before starting upload. | 0 | +| `USE_BRIDGEHEAD_AUTH` | Use Bridgehead-specific authorization credentials to access Blaze. | false | +| `KEEP_ALIVE` | Keep the script alive once it has done its work. | false | + +You can use the START_DELAY variable if you want to wait for something (typically Blaze) to start before running the data load. + +If you set USE_BRIDGEHEAD_AUTH to true, then the script will look in /etc/bridgehead, to see if there is a file called ccp.local.conf or similar, and try to extract the authorization credentials for Blaze from there. + +If you set KEEP_ALIVE to true, the script will never terminate. This can be useful if you are working in a Bridgehead environemnt, where terminating containers cause the Bridgehead to shut down. ## Building diff --git a/docker-compose.yml b/docker-compose.yml index 3514223..7716fa6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: "3.7" services: store: container_name: store - image: samply/blaze:develop + image: samply/blaze:latest environment: BASE_URL: "http://store:8080" ports: @@ -14,4 +14,4 @@ services: environment: FHIR_STORE_URL: "http://store:8080/fhir" PATIENT_COUNT: "2000" - command: sh -c "sleep 60 && /app/run.sh" # wait for Blaze to start + START_DELAY: 90 diff --git a/run.sh b/run.sh index c539d83..da13854 100644 --- a/run.sh +++ b/run.sh @@ -1,13 +1,39 @@ #!/usr/bin/env bash -#cd /app +if [ -n "$START_DELAY" ]; then + echo "Waiting for $START_DELAY seconds..." + sleep "$START_DELAY" +fi echo Generating fake data bbmri-fhir-gen /app/sample -n ${PATIENT_COUNT:-100} +AUTH="" +if [ -n "$USE_BRIDGEHEAD_AUTH" ] && [ "$USE_BRIDGEHEAD_AUTH" = true ]; then + FILE="/etc/bridgehead/ccp.local.conf" + if [ ! -e "$FILE" ]; then + FILE="/etc/bridgehead/bbmri.local.conf" + fi + if [ ! -e "$FILE" ]; then + # Use a glob pattern to find any matching file + FILE=$(ls /etc/bridgehead/*.local.conf 2>/dev/null | head -n 1) + fi + if [ -e "$FILE" ]; then + USER=$(grep -m 1 User "$FILE" | sed 's/# User: //') + PASSWORD=$(grep -m 1 Password "$FILE" | sed 's/# Password: //') + fi + if [ -n "$USER" ] && [ -n "$PASSWORD" ]; then + AUTH="--user $USER --password $PASSWORD" + fi +fi + echo Uploading data to Blaze Store -blazectl --server ${FHIR_STORE_URL:-http://store:8080/fhir} upload /app/sample/ -blazectl --server ${FHIR_STORE_URL:-http://store:8080/fhir} count-resources +blazectl $AUTH --server ${FHIR_STORE_URL:-http://store:8080/fhir} upload /app/sample/ +blazectl $AUTH --server ${FHIR_STORE_URL:-http://store:8080/fhir} count-resources echo Done +if [ -n "$KEEP_ALIVE" ] && [ "$KEEP_ALIVE" = true ]; then + tail -f /dev/null +fi +