From 1e1a339917131bbe47d96e4d2f5a0220b3bfe9e9 Mon Sep 17 00:00:00 2001 From: pedro Date: Mon, 18 Mar 2024 10:05:16 +0100 Subject: [PATCH] idhub.entrypoint: refactor oidc waiting interval instead of sleep, waits that all idhubs have wrote its content in /sharedsecret/ dir --- docker/idhub.entrypoint.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/docker/idhub.entrypoint.sh b/docker/idhub.entrypoint.sh index 10b9328..a42dc9c 100755 --- a/docker/idhub.entrypoint.sh +++ b/docker/idhub.entrypoint.sh @@ -35,6 +35,10 @@ deployment_strategy() { # warn admin that it should re-enter password to keep the service working ./manage.py send_mail_admins else + # this file helps all docker containers to guess number of hosts involved + # right now is only needed by new deployment for oidc + touch /sharedsecret/${DOMAIN} + # move the migrate thing in docker entrypoint # inspired by https://medium.com/analytics-vidhya/django-with-docker-and-docker-compose-python-part-2-8415976470cc echo "INFO detected NEW deployment" @@ -60,14 +64,24 @@ _get() { sqlite3 -json db.sqlite3 "select * from oidc4vp_organization;" } +_lines () { + local myfile="${1}" + cat "${myfile}" | wc -l +} + config_oidc4vp() { # populate your config - local file="${DOMAIN}" data="$(_get)" - echo "${data}" | jq --arg domain "${DOMAIN}" '{ ($domain): .}' > /sharedsecret/${file} + echo "${data}" | jq --arg domain "${DOMAIN}" '{ ($domain): .}' > /sharedsecret/${DOMAIN} - echo wait the other idhubs to write, this is the only oportunity to sync with other idhubs in the docker compose - sleep 2 + while true; do + echo wait the other idhubs to write, this is the only oportunity to sync with other idhubs in the docker compose + ## break when no empty files left + if ! wc -l /sharedsecret/* | awk '{print $1;}' | grep -qE '^0$'; then + break + fi + sleep 1 + done # get other configs for host in /sharedsecret/*; do # we are flexible on querying for DOMAIN: the first one based on regex