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
|
- 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-frontend-deps
|
- name: install-frontend-deps
|
||||||
image: node:24-alpine
|
image: node:24-alpine
|
||||||
environment:
|
environment:
|
||||||
|
|
@ -23,8 +24,7 @@ steps:
|
||||||
|
|
||||||
- name: test-shard-1
|
- name: test-shard-1
|
||||||
image: node:24-alpine
|
image: node:24-alpine
|
||||||
depends_on:
|
depends_on: [install-frontend-deps]
|
||||||
- install-frontend-deps
|
|
||||||
environment:
|
environment:
|
||||||
NODE_OPTIONS: "--max-old-space-size=1024"
|
NODE_OPTIONS: "--max-old-space-size=1024"
|
||||||
commands:
|
commands:
|
||||||
|
|
@ -32,8 +32,7 @@ steps:
|
||||||
|
|
||||||
- name: test-shard-2
|
- name: test-shard-2
|
||||||
image: node:24-alpine
|
image: node:24-alpine
|
||||||
depends_on:
|
depends_on: [install-frontend-deps]
|
||||||
- install-frontend-deps
|
|
||||||
environment:
|
environment:
|
||||||
NODE_OPTIONS: "--max-old-space-size=1024"
|
NODE_OPTIONS: "--max-old-space-size=1024"
|
||||||
commands:
|
commands:
|
||||||
|
|
@ -41,8 +40,7 @@ steps:
|
||||||
|
|
||||||
- name: test-shard-3
|
- name: test-shard-3
|
||||||
image: node:24-alpine
|
image: node:24-alpine
|
||||||
depends_on:
|
depends_on: [install-frontend-deps]
|
||||||
- install-frontend-deps
|
|
||||||
environment:
|
environment:
|
||||||
NODE_OPTIONS: "--max-old-space-size=1024"
|
NODE_OPTIONS: "--max-old-space-size=1024"
|
||||||
commands:
|
commands:
|
||||||
|
|
@ -50,8 +48,7 @@ steps:
|
||||||
|
|
||||||
- name: test-shard-4
|
- name: test-shard-4
|
||||||
image: node:24-alpine
|
image: node:24-alpine
|
||||||
depends_on:
|
depends_on: [install-frontend-deps]
|
||||||
- install-frontend-deps
|
|
||||||
environment:
|
environment:
|
||||||
NODE_OPTIONS: "--max-old-space-size=1024"
|
NODE_OPTIONS: "--max-old-space-size=1024"
|
||||||
commands:
|
commands:
|
||||||
|
|
@ -72,12 +69,7 @@ steps:
|
||||||
|
|
||||||
- name: publish-frontend-image
|
- name: publish-frontend-image
|
||||||
image: alpine
|
image: alpine
|
||||||
depends_on:
|
depends_on: [test-shard-1, test-shard-2, test-shard-3, test-shard-4, build-frontend-image]
|
||||||
- test-shard-1
|
|
||||||
- test-shard-2
|
|
||||||
- test-shard-3
|
|
||||||
- test-shard-4
|
|
||||||
- build-frontend-image
|
|
||||||
environment:
|
environment:
|
||||||
DOCKERHUB_TOKEN:
|
DOCKERHUB_TOKEN:
|
||||||
from_secret: dockerhub-token
|
from_secret: dockerhub-token
|
||||||
|
|
@ -88,8 +80,7 @@ steps:
|
||||||
|
|
||||||
- name: update-deployment
|
- name: update-deployment
|
||||||
image: alpine
|
image: alpine
|
||||||
depends_on:
|
depends_on: [publish-frontend-image]
|
||||||
- publish-frontend-image
|
|
||||||
commands:
|
commands:
|
||||||
- apk add --no-cache curl jq
|
- apk add --no-cache curl jq
|
||||||
- |
|
- |
|
||||||
|
|
@ -98,49 +89,27 @@ steps:
|
||||||
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"
|
||||||
DEPLOY="realestate-crawler-ui"
|
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')
|
||||||
CONTAINER=$(curl -sfk "$API/$DEPLOY" \
|
echo "Patching $DEPLOY (container=$CONTAINER) to image $IMAGE..."
|
||||||
-H "Authorization: Bearer $TOKEN" \
|
curl -sf -X PATCH "$API/$DEPLOY" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/strategic-merge-patch+json" -k \
|
||||||
-H "Accept: application/json" | jq -r '.spec.template.spec.containers[0].name')
|
-d "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"kubectl.kubernetes.io/restartedAt\":\"$RESTART_AT\"}},\"spec\":{\"containers\":[{\"name\":\"$CONTAINER\",\"image\":\"$IMAGE\"}]}}}}" \
|
||||||
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\"}]}}}}" \
|
|
||||||
| 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}'
|
||||||
|
|
||||||
- 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/immoweb:${CI_PIPELINE_NUMBER}"
|
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"
|
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
|
for i in $(seq 1 60); do
|
||||||
RESULT=$(curl -sfk "$PODS_API" \
|
RESULT=$(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))) | {name: .metadata.name, image: .spec.containers[0].image}]')
|
||||||
-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}]')
|
|
||||||
|
|
||||||
COUNT=$(echo "$RESULT" | jq 'length')
|
COUNT=$(echo "$RESULT" | jq 'length')
|
||||||
echo "Attempt $i/60: $COUNT pod(s) ready with image matching $EXPECTED_IMAGE"
|
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
|
||||||
if [ "$COUNT" -gt 0 ]; then
|
|
||||||
echo "$RESULT" | jq -r '.[] | " \(.name) image=\(.image) started=\(.started)"'
|
|
||||||
echo "New pod is live!"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
|
echo "ERROR: No pod with image $EXPECTED_IMAGE appeared within 5 minutes"; exit 1
|
||||||
echo "ERROR: No new ready pod with image $EXPECTED_IMAGE appeared within 5 minutes"
|
|
||||||
exit 1
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue