Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.

Commit 935f083

Browse files
committed
ci: ♻️ update log fetching logic
1 parent 6cbc3d6 commit 935f083

File tree

1 file changed

+40
-26
lines changed

1 file changed

+40
-26
lines changed

scripts/ci/api-healthcheck.sh

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,70 @@
44
KOYEB_SERVICE_ID=$1
55
end=$((SECONDS+360))
66
attempts=0
7-
max_attempts=20
7+
max_attempts=40
8+
LOGS_STARTED=false
89

910
# Wait for the new deployment to start
10-
echo "Waiting for the new deployment to start..."
11-
#sleep 15
12-
13-
LATEST_DEPLOYMENT_JSON=$(koyeb deployments list -o json | jq '.deployments | sort_by(.created_at) | last')
14-
15-
# Get deployment ID
16-
DEPLOYMENT_ID=$(echo $LATEST_DEPLOYMENT_JSON | jq -r '.id')
17-
18-
echo "Waiting for deployment: ${DEPLOYMENT_ID}"
19-
20-
# Start logging deployment and get its PID
21-
koyeb deployments logs $DEPLOYMENT_ID &
22-
LOGS_PID=$!
11+
echo "Monitoring health of latest deployment on ${KOYEB_SERVICE_ID}..."
2312

2413
# Check deployment health
2514
while [ $SECONDS -lt $end ] && [ $attempts -lt $max_attempts ]; do
26-
LATEST_DEPLOYMENT_JSON=$(koyeb deployments list -o json | jq '.deployments | sort_by(.created_at) | last')
15+
LATEST_DEPLOYMENT_JSON=$(koyeb deployments list -o json | jq '.deployments | sort_by(.created_at) | last')
16+
DEPLOYMENT_ID=$(echo $LATEST_DEPLOYMENT_JSON | jq -r '.id')
2717
DEPLOYMENT_STATUS=$(echo $LATEST_DEPLOYMENT_JSON | jq -r '.status | select(.!=null)')
2818

2919
if [ "$DEPLOYMENT_STATUS" = "HEALTHY" ]; then
3020
echo "Deployment ${DEPLOYMENT_ID} is healthy."
31-
kill $LOGS_PID
21+
22+
if [ "$LOGS_STARTED" = true ]; then
23+
kill $LOGS_PID
24+
fi
25+
3226
exit 0
3327
fi
3428

29+
if [ "$DEPLOYMENT_STATUS" = "STARTING" ]; then
30+
echo "Deployment ${DEPLOYMENT_ID} is starting."
31+
32+
if [ "$LOGS_STARTED" = false ]; then
33+
# Start logging deployment and get its PID
34+
koyeb deployments logs $DEPLOYMENT_ID &
35+
LOGS_PID=$!
36+
LOGS_STARTED=true
37+
fi
38+
39+
sleep 10;
40+
continue
41+
fi
42+
3543
if [ "$DEPLOYMENT_STATUS" = "PENDING" ]; then
36-
echo "Deployment ${DEPLOYMENT_ID} is pending."
37-
sleep 1;
38-
continue
44+
echo "Deployment ${DEPLOYMENT_ID} is pending."
45+
sleep 10;
46+
continue
3947
fi
4048

4149
if [ "$DEPLOYMENT_STATUS" = "ERROR" ]; then
42-
echo "Deployment ${DEPLOYMENT_ID} failed."
43-
koyeb deployments logs $DEPLOYMENT_ID
44-
kill $LOGS_PID
45-
exit 1
50+
echo "Deployment ${DEPLOYMENT_ID} failed."
51+
52+
if [ "$LOGS_STARTED" = true ]; then
53+
kill $LOGS_PID
54+
fi
55+
56+
exit 1
4657
fi
4758

59+
echo "Deployment is not healthy. Waiting 5 seconds before retrying."
4860
echo $DEPLOYMENT_STATUS
49-
echo "Deployment is not healthy. Waiting 10 seconds before retrying."
50-
sleep 10
61+
sleep 5
5162
attempts=$((attempts+1))
5263
done
5364

5465
echo "Deployment did not become healthy within the expected time or maximum attempts reached. Aborting redeployment."
5566

5667
koyeb deployments cancel $DEPLOYMENT_ID
5768

58-
kill $LOGS_PID
69+
if [ "$LOGS_STARTED" = true ]; then
70+
kill $LOGS_PID
71+
fi
72+
5973
exit 1

0 commit comments

Comments
 (0)