ci: Fix race condition while checking container IP

Be resilient and recheck the container's status if its IP address
couldn't be determined on the first attempt.
This commit is contained in:
Antoine Cotten 2021-12-28 20:16:54 +01:00
parent 691ffd8764
commit 3ce7fc0ae3
No known key found for this signature in database
GPG Key ID: 94637E68D4A79DD0
1 changed files with 20 additions and 1 deletions

View File

@ -74,7 +74,26 @@ function service_ip {
local cid
cid="$(container_id "$svc")"
ip="$(docker container inspect "$cid" --format '{{ (index .NetworkSettings.Networks "docker-elk_elk").IPAddress }}')"
local ip
local -i was_retried=0
# retry for max 10s (5*2s)
for _ in $(seq 1 5); do
ip="$(docker container inspect "$cid" --format '{{ (index .NetworkSettings.Networks "docker-elk_elk").IPAddress }}')"
if [ -n "$ip" ]; then
break
fi
was_retried=1
echo -n '.' >&2
sleep 2
done
if ((was_retried)); then
# flush stderr, important in non-interactive environments (CI)
echo >&2
fi
if [ -z "${ip:-}" ]; then
err "Container ${cid} has no IP address"
return 1