Standardize clone: skip_clone + step-level retry
This commit is contained in:
parent
4e881780d9
commit
9e702a3f5f
1 changed files with 20 additions and 51 deletions
|
|
@ -2,8 +2,10 @@ when:
|
|||
- event: push
|
||||
branch: master
|
||||
|
||||
clone:
|
||||
git:
|
||||
skip_clone: true
|
||||
|
||||
steps:
|
||||
- name: clone
|
||||
image: alpine
|
||||
environment:
|
||||
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'
|
||||
- "git checkout $CI_COMMIT_SHA"
|
||||
|
||||
steps:
|
||||
- name: install-frontend-deps
|
||||
image: node:24-alpine
|
||||
environment:
|
||||
|
|
@ -23,8 +24,7 @@ steps:
|
|||
|
||||
- name: test-shard-1
|
||||
image: node:24-alpine
|
||||
depends_on:
|
||||
- install-frontend-deps
|
||||
depends_on: [install-frontend-deps]
|
||||
environment:
|
||||
NODE_OPTIONS: "--max-old-space-size=1024"
|
||||
commands:
|
||||
|
|
@ -32,8 +32,7 @@ steps:
|
|||
|
||||
- name: test-shard-2
|
||||
image: node:24-alpine
|
||||
depends_on:
|
||||
- install-frontend-deps
|
||||
depends_on: [install-frontend-deps]
|
||||
environment:
|
||||
NODE_OPTIONS: "--max-old-space-size=1024"
|
||||
commands:
|
||||
|
|
@ -41,8 +40,7 @@ steps:
|
|||
|
||||
- name: test-shard-3
|
||||
image: node:24-alpine
|
||||
depends_on:
|
||||
- install-frontend-deps
|
||||
depends_on: [install-frontend-deps]
|
||||
environment:
|
||||
NODE_OPTIONS: "--max-old-space-size=1024"
|
||||
commands:
|
||||
|
|
@ -50,8 +48,7 @@ steps:
|
|||
|
||||
- name: test-shard-4
|
||||
image: node:24-alpine
|
||||
depends_on:
|
||||
- install-frontend-deps
|
||||
depends_on: [install-frontend-deps]
|
||||
environment:
|
||||
NODE_OPTIONS: "--max-old-space-size=1024"
|
||||
commands:
|
||||
|
|
@ -72,12 +69,7 @@ steps:
|
|||
|
||||
- name: publish-frontend-image
|
||||
image: alpine
|
||||
depends_on:
|
||||
- test-shard-1
|
||||
- test-shard-2
|
||||
- test-shard-3
|
||||
- test-shard-4
|
||||
- build-frontend-image
|
||||
depends_on: [test-shard-1, test-shard-2, test-shard-3, test-shard-4, build-frontend-image]
|
||||
environment:
|
||||
DOCKERHUB_TOKEN:
|
||||
from_secret: dockerhub-token
|
||||
|
|
@ -88,8 +80,7 @@ steps:
|
|||
|
||||
- name: update-deployment
|
||||
image: alpine
|
||||
depends_on:
|
||||
- publish-frontend-image
|
||||
depends_on: [publish-frontend-image]
|
||||
commands:
|
||||
- apk add --no-cache curl jq
|
||||
- |
|
||||
|
|
@ -98,49 +89,27 @@ steps:
|
|||
RESTART_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
API="https://10.0.20.100:6443/apis/apps/v1/namespaces/realestate-crawler/deployments"
|
||||
DEPLOY="realestate-crawler-ui"
|
||||
|
||||
CONTAINER=$(curl -sfk "$API/$DEPLOY" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Accept: application/json" | jq -r '.spec.template.spec.containers[0].name')
|
||||
echo "Patching $DEPLOY (container=$CONTAINER) to image $IMAGE with restartedAt=$RESTART_AT..."
|
||||
|
||||
curl -sf -X PATCH "$API/$DEPLOY" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Content-Type: application/strategic-merge-patch+json" \
|
||||
-k -d "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"kubectl.kubernetes.io/restartedAt\":\"$RESTART_AT\"}},\"spec\":{\"containers\":[{\"name\":\"$CONTAINER\",\"image\":\"$IMAGE\"}]}}}}" \
|
||||
CONTAINER=$(curl -sfk "$API/$DEPLOY" -H "Authorization: Bearer $TOKEN" -H "Accept: application/json" | jq -r '.spec.template.spec.containers[0].name')
|
||||
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 \
|
||||
-d "{\"spec\":{\"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}'
|
||||
|
||||
- name: verify-deploy
|
||||
image: alpine
|
||||
depends_on:
|
||||
- update-deployment
|
||||
depends_on: [update-deployment]
|
||||
commands:
|
||||
- apk add --no-cache curl jq
|
||||
- |
|
||||
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
|
||||
EXPECTED_IMAGE="viktorbarzin/immoweb:${CI_PIPELINE_NUMBER}"
|
||||
PODS_API="https://10.0.20.100:6443/api/v1/namespaces/realestate-crawler/pods?labelSelector=app%3Drealestate-crawler-ui"
|
||||
|
||||
for i in $(seq 1 60); do
|
||||
RESULT=$(curl -sfk "$PODS_API" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Accept: application/json" | \
|
||||
jq --arg img "$EXPECTED_IMAGE" '[.items[] | select(
|
||||
(.status.containerStatuses[]? | .ready == true) and
|
||||
(.spec.containers[]? | .image | endswith($img))
|
||||
) | {name: .metadata.name, image: .spec.containers[0].image, started: .status.startTime}]')
|
||||
|
||||
RESULT=$(curl -sfk "$PODS_API" -H "Authorization: Bearer $TOKEN" -H "Accept: application/json" | \
|
||||
jq --arg img "$EXPECTED_IMAGE" '[.items[] | select((.status.containerStatuses[]? | .ready == true) and (.spec.containers[]? | .image | endswith($img))) | {name: .metadata.name, image: .spec.containers[0].image}]')
|
||||
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 "New pod is live!"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Attempt $i/60: $COUNT pod(s) ready with image $EXPECTED_IMAGE"
|
||||
if [ "$COUNT" -gt 0 ]; then echo "New pod is live!"; exit 0; fi
|
||||
sleep 5
|
||||
done
|
||||
|
||||
echo "ERROR: No new ready pod with image $EXPECTED_IMAGE appeared within 5 minutes"
|
||||
exit 1
|
||||
echo "ERROR: No pod with image $EXPECTED_IMAGE appeared within 5 minutes"; exit 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue