Skip to content

Commit af396fc

Browse files
authored
Merge pull request #586 from jupyter-naas/568-verify-last-repo-tag-deployment-in-production-api
fix: Check on CICD that the deployed api is at the correct version
2 parents 940d963 + 9b6480d commit af396fc

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

.github/workflows/deploy_api.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,60 @@ jobs:
9292
naas-python space create --name=${{ env.REGISTRY_NAME }} --image=$URI:$TIMESTAMP --port=9879 --cpu=1 --memory=1Gi --env "$ENV_CONFIG" \
9393
|| naas-python space update --name=${{ env.REGISTRY_NAME }} --image=$URI:$TIMESTAMP --port=9879 --cpu=1 --memory=1Gi --env "$ENV_CONFIG"
9494
95+
- name: Verify API deployment and version
96+
run: |
97+
echo "🔍 Verifying API deployment with expected version..."
98+
99+
# Get the expected version from git tag
100+
EXPECTED_VERSION=$(git describe --tags 2>/dev/null || echo "v0.0.1")
101+
echo "Expected version: $EXPECTED_VERSION"
102+
103+
# API URL based on registry name
104+
API_URL="https://${{ env.REGISTRY_NAME }}.default.space.naas.ai"
105+
OPENAPI_URL="$API_URL/openapi.json"
106+
107+
echo "Checking API at: $OPENAPI_URL"
108+
109+
# Wait up to 5 minutes for API to be ready with correct version
110+
TIMEOUT=300 # 5 minutes
111+
INTERVAL=10 # Check every 10 seconds
112+
ELAPSED=0
113+
114+
while [ $ELAPSED -lt $TIMEOUT ]; do
115+
echo "Attempt $((ELAPSED/INTERVAL + 1)): Checking API version..."
116+
117+
# Try to get the version from OpenAPI endpoint
118+
RESPONSE=$(curl -s "$OPENAPI_URL" 2>/dev/null || echo "")
119+
120+
if [ -n "$RESPONSE" ]; then
121+
# Extract version from JSON response
122+
ACTUAL_VERSION=$(echo "$RESPONSE" | grep -o '"version":"[^"]*' | cut -d'"' -f4)
123+
124+
if [ -n "$ACTUAL_VERSION" ]; then
125+
echo "API responded with version: $ACTUAL_VERSION"
126+
127+
if [ "$ACTUAL_VERSION" = "$EXPECTED_VERSION" ]; then
128+
echo "✅ API deployment verified! Version matches: $ACTUAL_VERSION"
129+
exit 0
130+
else
131+
echo "⚠️ Version mismatch. Expected: $EXPECTED_VERSION, Got: $ACTUAL_VERSION"
132+
fi
133+
else
134+
echo "⚠️ Could not extract version from API response"
135+
fi
136+
else
137+
echo "⚠️ API not responding yet..."
138+
fi
139+
140+
sleep $INTERVAL
141+
ELAPSED=$((ELAPSED + INTERVAL))
142+
done
143+
144+
echo "❌ Timeout: API did not respond with expected version after 5 minutes"
145+
echo "Expected: $EXPECTED_VERSION"
146+
echo "Last response: $RESPONSE"
147+
exit 1
148+
95149
streamlit-demo:
96150
runs-on: ubuntu-latest
97151
env:

0 commit comments

Comments
 (0)