Skip to content

Commit

Permalink
Wait for docker server to be available after starting it
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth committed Nov 29, 2024
1 parent 9334d70 commit 47e1a78
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .github/scripts/wait_for_docker_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

docker network inspect backend

url="http://localhost:8420"
timeout_in_seconds=3600 # 60 minutes in seconds

start_time=$(date +%s)

while true; do
response_code=$(curl -s -o /dev/null -w "%{http_code}" "$url")

if [ "$response_code" -eq 200 ]; then
echo "Success! Received 200 OK response."
break
else
echo "Failed, got $response_code as response code. Retrying..."
sleep 5

current_time=$(date +%s)
elapsed_time=$((current_time - start_time))

if [ "$elapsed_time" -ge "$timeout_in_seconds" ]; then
echo "Timeout reached. Exiting."
exit 1
fi
fi
done
4 changes: 3 additions & 1 deletion .github/workflows/ci_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,15 @@ jobs:
run: |
docker compose -f ".github/docker/simple-server.compose.yml" up -d
- name: Wait for Docker server to be available
run: .github/scripts/wait_for_docker_server.sh

- name: Get Docker server IP address
run: |
IP_ADDRESS=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' simple-server)
echo "Docker container IP address is: $IP_ADDRESS"
echo "DOCKER_IP=$IP_ADDRESS" >> $GITHUB_ENV
- name: Replace IP address in network security config
run: |
sed -i "s/localhost/$DOCKER_IP/g" app/src/main/res/xml/network_config.xml
Expand Down

0 comments on commit 47e1a78

Please sign in to comment.