diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index f408c57..701fcb5 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -49,45 +49,55 @@ jobs: id: build_backend run: | set -o pipefail + ok=0 for attempt in 1 2 3; do echo "Build backend attempt $attempt/3..." DOCKER_BUILDKIT=0 docker build \ --tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-backend:${{ env.IMAGE_TAG }} \ --tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-backend:latest \ - ./backend 2>&1 | tee /tmp/build.log && break + ./backend 2>&1 | tee /tmp/build.log && { ok=1; break; } echo "Attempt $attempt failed, retrying in 10s..." && sleep 10 done + [ $ok -eq 1 ] || { echo "ERROR: backend build failed after 3 attempts"; exit 1; } + ok=0 for attempt in 1 2 3; do docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-backend:${{ env.IMAGE_TAG }} && \ - docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-backend:latest && break + docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-backend:latest && { ok=1; break; } echo "Push attempt $attempt failed, retrying in 10s..." && sleep 10 done + [ $ok -eq 1 ] || { echo "ERROR: backend push failed after 3 attempts"; exit 1; } - name: Build and Push Web id: build_web run: | set -o pipefail + ok=0 for attempt in 1 2 3; do echo "Build web attempt $attempt/3..." DOCKER_BUILDKIT=0 docker build \ --tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-web:${{ env.IMAGE_TAG }} \ --tag ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-web:latest \ - ./web 2>&1 | tee -a /tmp/build.log && break + ./web 2>&1 | tee -a /tmp/build.log && { ok=1; break; } echo "Attempt $attempt failed, retrying in 10s..." && sleep 10 done + [ $ok -eq 1 ] || { echo "ERROR: web build failed after 3 attempts"; exit 1; } + ok=0 for attempt in 1 2 3; do docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-web:${{ env.IMAGE_TAG }} && \ - docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-web:latest && break + docker push ${{ env.CR_SERVER_ACTIVE }}/${{ env.CR_ORG }}/video-web:latest && { ok=1; break; } echo "Push attempt $attempt failed, retrying in 10s..." && sleep 10 done + [ $ok -eq 1 ] || { echo "ERROR: web push failed after 3 attempts"; exit 1; } - name: Setup Kubectl run: | if ! command -v kubectl &>/dev/null; then + ok=0 for attempt in 1 2 3; do - curl -LO "https://files.m.daocloud.io/dl.k8s.io/release/v1.28.0/bin/linux/amd64/kubectl" && break + curl -LO "https://files.m.daocloud.io/dl.k8s.io/release/v1.28.0/bin/linux/amd64/kubectl" && { ok=1; break; } echo "Download attempt $attempt failed, retrying in 5s..." && sleep 5 done + [ $ok -eq 1 ] || { echo "ERROR: kubectl download failed after 3 attempts"; exit 1; } chmod +x kubectl && mv kubectl /usr/bin/kubectl fi kubectl version --client @@ -135,6 +145,7 @@ jobs: # All kubectl operations with retry (K3s 内网连接可能抖动) export KUBECTL_TIMEOUT="--request-timeout=4s" + ok=0 for attempt in 1 2 3 4 5; do echo "Deploy attempt $attempt/5..." { @@ -169,10 +180,11 @@ jobs: kubectl $KUBECTL_TIMEOUT rollout restart deployment/video-backend kubectl $KUBECTL_TIMEOUT rollout restart deployment/celery-worker kubectl $KUBECTL_TIMEOUT rollout restart deployment/video-web - } 2>&1 | tee /tmp/deploy.log && break + } 2>&1 | tee /tmp/deploy.log && { ok=1; break; } echo "Attempt $attempt failed, retrying in 30s..." sleep 30 done + [ $ok -eq 1 ] || { echo "ERROR: deploy to K3s failed after 5 attempts — check /tmp/deploy.log"; exit 1; } # ===== Log Center: failure reporting ===== - name: Report failure to Log Center