Skip to content

Commit

Permalink
Added retry for ngrok tunnel detection
Browse files Browse the repository at this point in the history
Signed-off-by: Emiliano Suñé <emiliano.sune@gmail.com>
  • Loading branch information
esune committed Aug 4, 2023
1 parent d568647 commit 25a2067
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions docker/manage
Original file line number Diff line number Diff line change
Expand Up @@ -367,15 +367,29 @@ function getNgrokUrl() {
_output_file=$2
_target_variable=$3

docker run --rm curlimages/curl -L -s $_url > $_output_file

NGROK_URL=$(docker run --rm -i ghcr.io/jqlang/jq:1.7rc1 < $_output_file --raw-output '.tunnels | map(select(.name=="command_line")) | .[0] | .public_url')
function extractUrl() {
docker run --rm curlimages/curl -L -s $_url > $_output_file
NGROK_URL=$(docker run --rm -i ghcr.io/jqlang/jq:1.7rc1 < $_output_file --raw-output '.tunnels | map(select(.name=="command_line")) | .[0] | .public_url')

if [ -z "${NGROK_URL}" ] || [ "null" = "${NGROK_URL}" ]; then
return 1
else
return 0
fi
}

local startTime=${SECONDS}
while ! extractUrl; do
printf "."
local duration=$(($SECONDS - $startTime))
if (( ${duration} >= 60 )); then
echoError "It was not possible to establish a connection with ngrok, please check ${_output_file} and the ngrok container logs for errors."
rtnCd=1
break
fi
sleep 1
done

if [ -z "${NGROK_URL}" ] || [ "null" = "${NGROK_URL}" ]; then
echoError "It was not possible to establish a connection with ngrok, please check the ngrok container logs for errors."
exit 1
fi

rm $_output_file

# assign value to target variable
Expand Down

0 comments on commit 25a2067

Please sign in to comment.