forked from torrust/torrust-index
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge torrust#393: Refactor: extract duplicate function `wait_for_con…
…tainer_to_be_healthy` 1e0e416 refactor: [torrust#389] extract duplicate function wait_for_container_to_be_healthy (Jose Celano) Pull request description: Extract duplicate function `wait_for_container_to_be_healthy` in E2E test scripts. ACKs for top commit: josecelano: ACK 1e0e416 Tree-SHA512: 6199ac75d6e3bdb2007369ecf9c8a13ee6b4c5129b356c5c016f2ee2a38e814cf7ef5d7560dc7a64f9e37f027d94c74a757c443a43537e0d22a7abf3f28d8e46
- Loading branch information
Showing
3 changed files
with
30 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
wait_for_container_to_be_healthy() { | ||
local container_name="$1" | ||
local max_retries="$2" | ||
local retry_interval="$3" | ||
local retry_count=0 | ||
|
||
while [ $retry_count -lt "$max_retries" ]; do | ||
container_health="$(docker inspect --format='{{json .State.Health}}' "$container_name")" | ||
if [ "$container_health" != "{}" ]; then | ||
container_status="$(echo "$container_health" | jq -r '.Status')" | ||
if [ "$container_status" == "healthy" ]; then | ||
echo "Container $container_name is healthy" | ||
return 0 | ||
fi | ||
fi | ||
|
||
retry_count=$((retry_count + 1)) | ||
echo "Waiting for container $container_name to become healthy (attempt $retry_count of $max_retries)..." | ||
sleep "$retry_interval" | ||
done | ||
|
||
echo "Timeout reached, container $container_name is not healthy" | ||
return 1 | ||
} |