From 958b6b48b2cd760ce4ae40b15ce0c8308e03bde0 Mon Sep 17 00:00:00 2001 From: cat-shark <1716967236@qq.com> Date: Sun, 19 Jul 2026 19:10:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20=E4=BF=AE=E5=A4=8D=20Gitea=20Actions?= =?UTF-8?q?=20=E9=83=A8=E7=BD=B2=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复变量名: github.sha → gitea.sha - 添加 Docker Registry 认证步骤 - kubectl 版本修正为 v1.30.0 - 添加部署超时控制(5 分钟) - 添加部署失败自动回滚机制 Co-Authored-By: Claude Opus 4.8 --- .gitea/workflows/deploy.yml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index fd79ccf..dc0388f 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -23,20 +23,23 @@ jobs: - name: Checkout code run: | git clone $REPO_URL . - git checkout ${{ github.sha }} + git checkout ${{ gitea.sha }} + + - name: Login to Docker Registry + run: | + echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login $REGISTRY -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin - name: Build & Push Docker image run: | apk add --no-cache docker-cli - echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login $REGISTRY -u admin --password-stdin - TAG=${{ github.sha }} + TAG=${{ gitea.sha }} docker build -t $REGISTRY/$APP:$TAG -t $REGISTRY/$APP:${{ inputs.environment }} . docker push $REGISTRY/$APP:$TAG docker push $REGISTRY/$APP:${{ inputs.environment }} - name: Setup kubectl run: | - curl -sLO "https://dl.k8s.io/release/v1.36.0/bin/linux/amd64/kubectl" + curl -sLO "https://dl.k8s.io/release/v1.30.0/bin/linux/amd64/kubectl" chmod +x kubectl mv kubectl /usr/local/bin/ mkdir -p ~/.kube @@ -44,6 +47,12 @@ jobs: - name: Deploy to K8s run: | - TAG=${{ github.sha }} - kubectl set image deployment/$APP $APP=$REGISTRY/$APP:$TAG -n lpt-${{ inputs.environment }} + TAG=${{ gitea.sha }} + kubectl set image deployment/$APP $APP=$REGISTRY/$APP:$TAG -n lpt-${{ inputs.environment }} --record + kubectl rollout status deployment/$APP -n lpt-${{ inputs.environment }} --timeout=5m + + - name: Rollback on failure + if: failure() + run: | + kubectl rollout undo deployment/$APP -n lpt-${{ inputs.environment }} kubectl rollout status deployment/$APP -n lpt-${{ inputs.environment }}