Standardize clone: skip_clone + step-level retry
This commit is contained in:
parent
9e702a3f5f
commit
d3b8cb1f84
1 changed files with 17 additions and 50 deletions
|
|
@ -2,8 +2,10 @@ when:
|
||||||
- event: push
|
- event: push
|
||||||
branch: master
|
branch: master
|
||||||
|
|
||||||
clone:
|
skip_clone: true
|
||||||
git:
|
|
||||||
|
steps:
|
||||||
|
- name: clone
|
||||||
image: alpine
|
image: alpine
|
||||||
environment:
|
environment:
|
||||||
GITHUB_TOKEN:
|
GITHUB_TOKEN:
|
||||||
|
|
@ -13,7 +15,6 @@ clone:
|
||||||
- 'for i in 1 2 3 4 5; do git clone https://x-access-token:${GITHUB_TOKEN}@github.com/${CI_REPO} . && break || echo "Clone attempt $i failed, retrying in 10s..." && rm -rf .git && sleep 10; done'
|
- 'for i in 1 2 3 4 5; do git clone https://x-access-token:${GITHUB_TOKEN}@github.com/${CI_REPO} . && break || echo "Clone attempt $i failed, retrying in 10s..." && rm -rf .git && sleep 10; done'
|
||||||
- "git checkout $CI_COMMIT_SHA"
|
- "git checkout $CI_COMMIT_SHA"
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: install-api-deps
|
- name: install-api-deps
|
||||||
image: python:3.13-slim
|
image: python:3.13-slim
|
||||||
commands:
|
commands:
|
||||||
|
|
@ -32,16 +33,14 @@ steps:
|
||||||
|
|
||||||
- name: test-unit
|
- name: test-unit
|
||||||
image: python:3.13-slim
|
image: python:3.13-slim
|
||||||
depends_on:
|
depends_on: [install-api-deps]
|
||||||
- install-api-deps
|
|
||||||
commands:
|
commands:
|
||||||
- apt-get update && apt-get install -y --no-install-recommends libglib2.0-0
|
- apt-get update && apt-get install -y --no-install-recommends libglib2.0-0
|
||||||
- .venv/bin/pytest tests/unit/ -v --tb=short
|
- .venv/bin/pytest tests/unit/ -v --tb=short
|
||||||
|
|
||||||
- name: test-integration
|
- name: test-integration
|
||||||
image: python:3.13-slim
|
image: python:3.13-slim
|
||||||
depends_on:
|
depends_on: [install-api-deps]
|
||||||
- install-api-deps
|
|
||||||
commands:
|
commands:
|
||||||
- apt-get update && apt-get install -y --no-install-recommends libglib2.0-0
|
- apt-get update && apt-get install -y --no-install-recommends libglib2.0-0
|
||||||
- .venv/bin/pytest tests/integration/ tests/regression/ tests/e2e/ tests/test_listing_geojson.py -v --tb=short
|
- .venv/bin/pytest tests/integration/ tests/regression/ tests/e2e/ tests/test_listing_geojson.py -v --tb=short
|
||||||
|
|
@ -61,10 +60,7 @@ steps:
|
||||||
|
|
||||||
- name: publish-api-image
|
- name: publish-api-image
|
||||||
image: alpine
|
image: alpine
|
||||||
depends_on:
|
depends_on: [test-unit, test-integration, build-api-image]
|
||||||
- test-unit
|
|
||||||
- test-integration
|
|
||||||
- build-api-image
|
|
||||||
environment:
|
environment:
|
||||||
DOCKERHUB_TOKEN:
|
DOCKERHUB_TOKEN:
|
||||||
from_secret: dockerhub-token
|
from_secret: dockerhub-token
|
||||||
|
|
@ -76,8 +72,7 @@ steps:
|
||||||
|
|
||||||
- name: update-deployment
|
- name: update-deployment
|
||||||
image: alpine
|
image: alpine
|
||||||
depends_on:
|
depends_on: [publish-api-image]
|
||||||
- publish-api-image
|
|
||||||
commands:
|
commands:
|
||||||
- apk add --no-cache curl jq
|
- apk add --no-cache curl jq
|
||||||
- |
|
- |
|
||||||
|
|
@ -85,61 +80,33 @@ steps:
|
||||||
IMAGE="viktorbarzin/realestatecrawler:${CI_PIPELINE_NUMBER}"
|
IMAGE="viktorbarzin/realestatecrawler:${CI_PIPELINE_NUMBER}"
|
||||||
RESTART_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
RESTART_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||||
API="https://10.0.20.100:6443/apis/apps/v1/namespaces/realestate-crawler/deployments"
|
API="https://10.0.20.100:6443/apis/apps/v1/namespaces/realestate-crawler/deployments"
|
||||||
|
|
||||||
for DEPLOY in realestate-crawler-api realestate-crawler-celery realestate-crawler-celery-beat; do
|
for DEPLOY in realestate-crawler-api realestate-crawler-celery realestate-crawler-celery-beat; do
|
||||||
STATUS=$(curl -sfk "$API/$DEPLOY" \
|
CONTAINER=$(curl -sfk "$API/$DEPLOY" -H "Authorization: Bearer $TOKEN" -H "Accept: application/json" | jq -r '.spec.template.spec.containers[0].name')
|
||||||
-H "Authorization: Bearer $TOKEN" \
|
|
||||||
-H "Accept: application/json")
|
|
||||||
CONTAINER=$(echo "$STATUS" | jq -r '.spec.template.spec.containers[0].name')
|
|
||||||
echo "Patching $DEPLOY (container=$CONTAINER) to image $IMAGE..."
|
echo "Patching $DEPLOY (container=$CONTAINER) to image $IMAGE..."
|
||||||
|
curl -sf -X PATCH "$API/$DEPLOY" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/strategic-merge-patch+json" -k \
|
||||||
curl -sf -X PATCH "$API/$DEPLOY" \
|
-d "{\"spec\":{\"paused\":null,\"template\":{\"metadata\":{\"annotations\":{\"kubectl.kubernetes.io/restartedAt\":\"$RESTART_AT\"}},\"spec\":{\"containers\":[{\"name\":\"$CONTAINER\",\"image\":\"$IMAGE\"}]}}}}" \
|
||||||
-H "Authorization: Bearer $TOKEN" \
|
|
||||||
-H "Content-Type: application/strategic-merge-patch+json" \
|
|
||||||
-k -d "{\"spec\":{\"paused\":null,\"template\":{\"metadata\":{\"annotations\":{\"kubectl.kubernetes.io/restartedAt\":\"$RESTART_AT\"}},\"spec\":{\"containers\":[{\"name\":\"$CONTAINER\",\"image\":\"$IMAGE\"}]}}}}" \
|
|
||||||
| jq '{name: .metadata.name, generation: .metadata.generation, image: .spec.template.spec.containers[0].image}'
|
| jq '{name: .metadata.name, generation: .metadata.generation, image: .spec.template.spec.containers[0].image}'
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: verify-deploy
|
- name: verify-deploy
|
||||||
image: alpine
|
image: alpine
|
||||||
depends_on:
|
depends_on: [update-deployment]
|
||||||
- update-deployment
|
|
||||||
commands:
|
commands:
|
||||||
- apk add --no-cache curl jq
|
- apk add --no-cache curl jq
|
||||||
- |
|
- |
|
||||||
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
|
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
|
||||||
EXPECTED_IMAGE="viktorbarzin/realestatecrawler:${CI_PIPELINE_NUMBER}"
|
EXPECTED_IMAGE="viktorbarzin/realestatecrawler:${CI_PIPELINE_NUMBER}"
|
||||||
BASE_API="https://10.0.20.100:6443/api/v1/namespaces/realestate-crawler/pods"
|
BASE_API="https://10.0.20.100:6443/api/v1/namespaces/realestate-crawler/pods"
|
||||||
|
|
||||||
for DEPLOY in realestate-crawler-api realestate-crawler-celery realestate-crawler-celery-beat; do
|
for DEPLOY in realestate-crawler-api realestate-crawler-celery realestate-crawler-celery-beat; do
|
||||||
echo "Verifying $DEPLOY..."
|
echo "Verifying $DEPLOY..."
|
||||||
PODS_API="$BASE_API?labelSelector=app%3D$DEPLOY"
|
PODS_API="$BASE_API?labelSelector=app%3D$DEPLOY"
|
||||||
|
|
||||||
FOUND=0
|
FOUND=0
|
||||||
for i in $(seq 1 60); do
|
for i in $(seq 1 60); do
|
||||||
RESULT=$(curl -sfk "$PODS_API" \
|
COUNT=$(curl -sfk "$PODS_API" -H "Authorization: Bearer $TOKEN" -H "Accept: application/json" | \
|
||||||
-H "Authorization: Bearer $TOKEN" \
|
jq --arg img "$EXPECTED_IMAGE" '[.items[] | select((.status.containerStatuses[]? | .ready == true) and (.spec.containers[]? | .image | endswith($img)))] | length')
|
||||||
-H "Accept: application/json" | \
|
echo " Attempt $i/60: $COUNT pod(s) ready"
|
||||||
jq --arg img "$EXPECTED_IMAGE" '[.items[] | select(
|
if [ "$COUNT" -gt 0 ]; then echo "$DEPLOY is live!"; FOUND=1; break; fi
|
||||||
(.status.containerStatuses[]? | .ready == true) and
|
|
||||||
(.spec.containers[]? | .image | endswith($img))
|
|
||||||
) | {name: .metadata.name, image: .spec.containers[0].image, started: .status.startTime}]')
|
|
||||||
|
|
||||||
COUNT=$(echo "$RESULT" | jq 'length')
|
|
||||||
echo " Attempt $i/60: $COUNT pod(s) ready with image matching $EXPECTED_IMAGE"
|
|
||||||
|
|
||||||
if [ "$COUNT" -gt 0 ]; then
|
|
||||||
echo "$RESULT" | jq -r '.[] | " \(.name) image=\(.image) started=\(.started)"'
|
|
||||||
echo "$DEPLOY is live!"
|
|
||||||
FOUND=1
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
|
if [ "$FOUND" -ne 1 ]; then echo "ERROR: $DEPLOY not ready within 5 minutes"; exit 1; fi
|
||||||
if [ "$FOUND" -ne 1 ]; then
|
|
||||||
echo "ERROR: No new ready pod for $DEPLOY with image $EXPECTED_IMAGE appeared within 5 minutes"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue