Skip to content

Commit 0e7ab05

Browse files
committed
feat: add smoke tests to CI workflow for service health verification
1 parent 2ee9638 commit 0e7ab05

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ jobs:
8585
vuln-type: 'os,library'
8686
severity: 'CRITICAL,HIGH' # Only fail on Critical and High issues
8787

88+
# --- NEW STEP: Run Smoke Tests ---
89+
- name: Run Smoke Tests
90+
run: |
91+
docker run -d --name app -p 8089:8089 local-image-scan:latest
92+
sleep 10
93+
chmod +x ./scripts/smoke-test.sh
94+
./scripts/smoke-test.sh http://localhost:8089
95+
docker stop app && docker rm app
96+
8897
- name: Log in to GHCR
8998
uses: docker/login-action@v3
9099
with:

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8089"]
1313

1414

1515

16+

scripts/smoke-test.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Configuration
4+
SERVICE_URL=${1:-"http://localhost:8089"}
5+
MAX_RETRIES=30
6+
SLEEP_INTERVAL=5
7+
8+
echo "Starting smoke tests against $SERVICE_URL..."
9+
10+
# Function to check health
11+
check_health() {
12+
local url="$1/health"
13+
local response=$(curl -s -w "\n%{http_code}" "$url")
14+
local http_code=$(echo "$response" | tail -n1)
15+
16+
if [ "$http_code" == "200" ]; then
17+
return 0
18+
else
19+
echo "Health check returned HTTP $http_code"
20+
return 1
21+
fi
22+
}
23+
24+
# Wait for service to be ready
25+
echo "Waiting for service to be up..."
26+
for ((i=1; i<=MAX_RETRIES; i++)); do
27+
if check_health "$SERVICE_URL"; then
28+
echo "✅ AI Service is UP and healthy!"
29+
30+
# Print health details
31+
echo "Health endpoint response:"
32+
curl -s "$SERVICE_URL/health"
33+
echo ""
34+
35+
exit 0
36+
fi
37+
echo "Attempt $i/$MAX_RETRIES: Service not ready yet... waiting ${SLEEP_INTERVAL}s"
38+
sleep $SLEEP_INTERVAL
39+
done
40+
41+
echo "❌ Service failed to start within timeout."
42+
exit 1

0 commit comments

Comments
 (0)