Skip to content

Commit

Permalink
Fix looping problem
Browse files Browse the repository at this point in the history
  • Loading branch information
digimangos committed Sep 9, 2024
1 parent beb1646 commit 276918c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions bootstrap/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

max_curl_attempts=10

wait_for_docker() {
TIMEOUT=30
while [ $TIMEOUT -gt 0 ]; do
Expand All @@ -24,7 +26,7 @@ IMAGE_NAME="ghcr.io/digimangos-gateixeira-testing/shopping-list-api:main"
echo "Running ${IMAGE_NAME} instance!"

# Get the container ID of the running container for the specified image
CONTAINER_ID=$(docker ps --filter "ancestor=$IMAGE_NAME" --format "{{.ID}}")
CONTAINER_ID=$(docker ps -a --filter "ancestor=$IMAGE_NAME" --format "{{.ID}}")

echo "Container ID: ${CONTAINER_ID}"

Expand All @@ -42,5 +44,16 @@ while ! curl -s "http://localhost:3001/items/" > /dev/null; do
sleep 1
done

attempt=0
while ! curl -s "http://localhost:3001/items/" > /dev/null && [ $attempt -lt $max_curl_attempts ]; do
printf "."
sleep 2
attempt=$((attempt + 1))
done

if [ $attempt -eq $max_curl_attempts ]; then
echo "Error: Unable to reach http://localhost:3001/items/ after $max_curl_attempts attempts."
fi

echo -e 'API is up and running!'
exit 0
exit 0

0 comments on commit 276918c

Please sign in to comment.