From 64db5ad5b7522bacd5cbd54293da772429bf8860 Mon Sep 17 00:00:00 2001 From: Yannick Marcon Date: Wed, 8 May 2024 20:51:19 +0200 Subject: [PATCH] fix: apply the mongo settings properly #10 --- bin/first_run.sh | 23 +++++++++++++++++++++++ bin/start.sh | 20 +++++++------------- docker-compose.yml | 17 +++++++++++------ 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/bin/first_run.sh b/bin/first_run.sh index 1cfcfa3..e145b89 100644 --- a/bin/first_run.sh +++ b/bin/first_run.sh @@ -36,6 +36,29 @@ anonympw=$(echo -n $MICA_ANONYMOUS_PASSWORD | xargs java -jar /usr/share/mica2/t cat $MICA_HOME/conf/shiro.ini | sed -e "s/^anonymous\s*=.*/anonymous=$anonympw/" > /tmp/shiro.ini && \ mv /tmp/shiro.ini $MICA_HOME/conf/shiro.ini +# Configure MongoDB +if [ -n "$MONGODB_URI" ] +then + sed s,localhost:27017/mica,$MONGODB_URI,g $MICA_HOME/conf/application.yml > /tmp/application.yml + mv -f /tmp/application.yml $MICA_HOME/conf/application.yml +elif [ -n "$MONGO_HOST" ] + then + MGP=27017 + if [ -n "$MONGO_PORT" ] + then + MGP=$MONGO_PORT + fi + MGURI="$MONGO_HOST:$MGP" + if [ -n "$MONGO_USER" ] && [ -n "$MONGO_PASSWORD" ] + then + MGURI="$MONGO_USER:$MONGO_PASSWORD@$MGURI/$MONGO_DB?authSource=admin" + else + MGURI="$MGURI/$MONGO_DB" + fi + sed s,localhost:27017/mica,$MGURI,g $MICA_HOME/conf/application.yml > /tmp/application.yml + mv -f /tmp/application.yml $MICA_HOME/conf/application.yml +fi + # Configure Opal if [ -n "$OPAL_HOST" ] then diff --git a/bin/start.sh b/bin/start.sh index 170a64b..07ed413 100644 --- a/bin/start.sh +++ b/bin/start.sh @@ -27,19 +27,13 @@ if [ -e /opt/mica/bin/first_run.sh ] mv /opt/mica/bin/first_run.sh /opt/mica/bin/first_run.sh.done fi -if [ -z $MONGODB_URI ] -then - #https://docs.spring.io/spring-boot/docs/1.5.6.RELEASE/reference/html/boot-features-external-config.html#boot-features-external-config - # According to spring documentation ENV vars have precede before application.yaml properties, so we just set the value instead of fiddling with the yml file - if [ -n "$MONGO_USERNAME" ] && [ -n "$MONGO_PASSWORD" ] - then - export SPRING_DATA_MONGODB_URI=mongodb://$MONGO_USERNAME:$MONGO_PASSWORD@${MONGO_HOST:-mongo}:${MONGO_PORT:-27017}/${MONGO_DB:-mica}?authSource=admin - else - export SPRING_DATA_MONGODB_URI=mongodb://${MONGO_HOST:-mongo}:${MONGO_PORT:-27017}/${MONGO_DB:-mica} - fi -else -export SPRING_DATA_MONGODB_URI=$MONGODB_URI -fi +# Wait for MongoDB to be ready +if [ -n "$MONGO_HOST" ] + then + until curl -i http://$MONGO_HOST:$MONGO_PORT/mica &> /dev/null + do + sleep 1 + done # Start mica /usr/share/mica2/bin/mica2 diff --git a/docker-compose.yml b/docker-compose.yml index 012246b..1c34bce 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3' services: mica: image: obiba/mica @@ -13,17 +12,17 @@ services: - MONGO_HOST=mongo - MONGO_PORT=27017 - MONGO_DB=mica -# - MONGO_USERNAME=mica -# - MONGO_PASSWORD=${MICA_ADMINISTRATOR_PASSWORD} + - MONGO_USER=${MONGO_USER:-obiba} + - MONGO_PASSWORD=${MONGO_PASSWORD:-password} - OPAL_URL=http://opal:8080 - AGATE_URL=http://agate:8081 volumes: - /tmp/mica:/srv mongo: image: mongo:6.0 -# environment: -# - MONGO_INITDB_ROOT_USERNAME=mica -# - MONGO_INITDB_ROOT_PASSWORD=${MICA_ADMINISTRATOR_PASSWORD} + environment: + - MONGO_INITDB_ROOT_USERNAME=${MONGO_USER:-obiba} + - MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD:-password} opal: image: obiba/opal ports: @@ -34,6 +33,9 @@ services: - OPAL_ADMINISTRATOR_PASSWORD=password - MONGO_HOST=mongo - MONGO_PORT=27017 + - MONGO_USER=${MONGO_USER:-obiba} + - MONGO_PASSWORD=${MONGO_PASSWORD:-password} + - MONGODATA_DATABASE=opal - AGATE_URL=http://agate:8081 volumes: - /tmp/opal:/srv @@ -47,6 +49,9 @@ services: - AGATE_ADMINISTRATOR_PASSWORD=password - MONGO_HOST=mongo - MONGO_PORT=27017 + - MONGO_DB=agate + - MONGO_USER=${MONGO_USER:-obiba} + - MONGO_PASSWORD=${MONGO_PASSWORD:-password} - RECAPTCHA_SITE_KEY=6Lfo7gYTAAAAAOyl8_MHuH-AVBzRDtpIuJrjL3Pb - RECAPTCHA_SECRET_KEY=6Lfo7gYTAAAAADym-vSDvPBeBCXaxIprA0QXLk_b volumes: