From eeb62af0c61cd5afa55b40b2975224afefd4fae3 Mon Sep 17 00:00:00 2001 From: cruizba Date: Sun, 17 Mar 2024 04:51:22 +0100 Subject: [PATCH] Refactor ready-check --- docker-compose.yaml | 81 ++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 1332869..f3d2f56 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -133,47 +133,46 @@ services: - mongo command: > /bin/sh -c " - until $(curl --silent --head --fail http://openvidu:7880 > /dev/null); do - echo 'Waiting for OpenVidu to start...'; - sleep 1; - done; - until $(curl --silent --head --fail http://ingress:9091 > /dev/null); do - echo 'Waiting for Ingress to start...'; - sleep 1; - done; - until $(curl --silent --head --fail http://egress:9091 > /dev/null); do - echo 'Waiting for Ingress to start...'; - sleep 1; - done; - until $(curl --silent --head --fail http://dashboard:5000 > /dev/null); do - echo 'Waiting for Dashboard to start...'; - sleep 1; - done; - until $(curl --silent --head --fail http://minio:9000/minio/health/live > /dev/null); do - echo 'Waiting for Minio to start...'; - sleep 1; - done; - until $(curl --silent --head --fail http://minio:9001/minio-console > /dev/null); do - echo 'Waiting for Mongo to start...'; - sleep 1; - done; - until $(curl --connect-timeout 10 --silent http://mongo:27017 > /dev/null); do - echo 'Waiting for Mongo to start...'; - sleep 1; - done; - URL=https://$$LOCAL_DOMAIN:4443/ - if [ \"$USE_TLS\" = 'false' ]; then - URL=$(echo $$URL | sed 's/https/http/'); - fi && - sleep 10; - echo ''; - echo ''; - echo '------------------------'; - echo 'OpenVidu is ready!'; - echo \"Open $$URL in your browser\"; - echo '------------------------'; - echo ''; - echo ''; + wait_for_service() { + SERVICE_NAME=\$1 + SERVICE_URL=\$2 + shift 2 + EXTRA=\$@ + if [ -n \"\$$EXTRA\" ]; then + until curl \$$EXTRA \$$SERVICE_URL > /dev/null; do + echo \"Waiting for \$$SERVICE_NAME to start...\"; + sleep 1; + done; + else + until curl --silent --head --fail \$$SERVICE_URL > /dev/null; do + echo \"Waiting for \$$SERVICE_NAME to start...\"; + sleep 1; + done; + fi; + } + + wait_for_service 'OpenVidu' 'http://openvidu:7880' + wait_for_service 'Ingress' 'http://ingress:9091' + wait_for_service 'Egress' 'http://egress:9091' + wait_for_service 'Dashboard' 'http://dashboard:5000' + wait_for_service 'Minio' 'http://minio:9000/minio/health/live' + wait_for_service 'Minio Console' 'http://minio:9001/minio-console' + wait_for_service 'Mongo' 'http://mongo:27017' --connect-timeout 10 --silent + + URL=https://\$$LOCAL_DOMAIN:4443/ + if [ \"\$$USE_TLS\" = 'false' ]; then + URL=\$(echo \$$URL | sed 's/https/http/') + fi + + sleep 10 + echo '' + echo '' + echo '------------------------' + echo 'OpenVidu is ready!' + echo \"Open \$$URL in your browser\" + echo '------------------------' + echo '' + echo '' " setup-volumes: