fix(cicd): capture actual build/deploy logs in failure report
All checks were successful
Build and Deploy Web / build-and-deploy (push) Successful in 3m0s
All checks were successful
Build and Deploy Web / build-and-deploy (push) Successful in 3m0s
Replace docker/build-push-action with shell command + tee to capture build logs. Failure step now includes actual error output in Log Center report. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
784ca17072
commit
b72b376fcd
@ -28,12 +28,13 @@ jobs:
|
|||||||
password: ${{ secrets.SWR_PASSWORD }}
|
password: ${{ secrets.SWR_PASSWORD }}
|
||||||
|
|
||||||
- name: Build and Push Web
|
- name: Build and Push Web
|
||||||
uses: docker/build-push-action@v4
|
run: |
|
||||||
with:
|
docker buildx build \
|
||||||
context: .
|
--push \
|
||||||
push: true
|
--provenance=false \
|
||||||
provenance: false
|
--tag ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-web:latest \
|
||||||
tags: ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-web:latest
|
. 2>&1 | tee /tmp/build.log
|
||||||
|
exit ${PIPESTATUS[0]}
|
||||||
|
|
||||||
- name: Setup Kubectl
|
- name: Setup Kubectl
|
||||||
run: |
|
run: |
|
||||||
@ -54,29 +55,49 @@ jobs:
|
|||||||
echo "Environment: Production"
|
echo "Environment: Production"
|
||||||
DEPLOY_FILE="k8s/web-deployment-prod.yaml"
|
DEPLOY_FILE="k8s/web-deployment-prod.yaml"
|
||||||
INGRESS_FILE="k8s/ingress.yaml"
|
INGRESS_FILE="k8s/ingress.yaml"
|
||||||
|
RESTART_NAME="rtc-web"
|
||||||
else
|
else
|
||||||
echo "Environment: Development"
|
echo "Environment: Development"
|
||||||
DEPLOY_FILE="k8s/web-deployment-dev.yaml"
|
DEPLOY_FILE="k8s/web-deployment-dev.yaml"
|
||||||
INGRESS_FILE="k8s/ingress-dev.yaml"
|
INGRESS_FILE="k8s/ingress-dev.yaml"
|
||||||
|
RESTART_NAME="rtc-web-dev"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 2. 替换镜像地址
|
# 2. 替换镜像地址
|
||||||
sed -i "s|\${CI_REGISTRY_IMAGE}/web:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-web:latest|g" $DEPLOY_FILE
|
sed -i "s|\${CI_REGISTRY_IMAGE}/web:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/rtc-web:latest|g" $DEPLOY_FILE
|
||||||
|
|
||||||
# 3. 应用配置
|
# 3. 应用配置并捕获输出
|
||||||
kubectl apply -f $DEPLOY_FILE
|
{
|
||||||
kubectl apply -f $INGRESS_FILE
|
kubectl apply -f $DEPLOY_FILE
|
||||||
|
kubectl apply -f $INGRESS_FILE
|
||||||
# 4. 根据分支重启对应服务
|
kubectl rollout restart deployment/$RESTART_NAME
|
||||||
if [[ "${{ github.ref_name }}" == "main" || "${{ github.ref_name }}" == "master" ]]; then
|
} 2>&1 | tee /tmp/deploy.log
|
||||||
kubectl rollout restart deployment/rtc-web
|
|
||||||
else
|
|
||||||
kubectl rollout restart deployment/rtc-web-dev
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Report failure to Log Center
|
- name: Report failure to Log Center
|
||||||
if: failure()
|
if: failure()
|
||||||
run: |
|
run: |
|
||||||
|
BUILD_LOG=""
|
||||||
|
DEPLOY_LOG=""
|
||||||
|
FAILED_STEP="unknown"
|
||||||
|
|
||||||
|
if [ -f /tmp/build.log ]; then
|
||||||
|
BUILD_LOG=$(tail -50 /tmp/build.log | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
|
||||||
|
FAILED_STEP="build"
|
||||||
|
fi
|
||||||
|
if [ -f /tmp/deploy.log ]; then
|
||||||
|
DEPLOY_LOG=$(tail -50 /tmp/deploy.log | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
|
||||||
|
if [ -n "$DEPLOY_LOG" ]; then
|
||||||
|
FAILED_STEP="deploy"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$BUILD_LOG" ] && [ -z "$DEPLOY_LOG" ]; then
|
||||||
|
BUILD_LOG="No captured output. Check Gitea Actions UI for details."
|
||||||
|
FAILED_STEP="pre-build"
|
||||||
|
fi
|
||||||
|
|
||||||
|
ERROR_LOG="${BUILD_LOG}${DEPLOY_LOG}"
|
||||||
|
|
||||||
curl -s -X POST "https://qiyuan-log-center-api.airlabs.art/api/v1/logs/report" \
|
curl -s -X POST "https://qiyuan-log-center-api.airlabs.art/api/v1/logs/report" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{
|
-d "{
|
||||||
@ -88,19 +109,15 @@ jobs:
|
|||||||
\"repo_url\": \"https://gitea.airlabs.art/zyc/rtc_web.git\",
|
\"repo_url\": \"https://gitea.airlabs.art/zyc/rtc_web.git\",
|
||||||
\"error\": {
|
\"error\": {
|
||||||
\"type\": \"CICDFailure\",
|
\"type\": \"CICDFailure\",
|
||||||
\"message\": \"Build and Deploy failed on branch ${{ github.ref_name }}\",
|
\"message\": \"[${FAILED_STEP}] Build and Deploy failed on branch ${{ github.ref_name }}\",
|
||||||
\"stack_trace\": [
|
\"stack_trace\": [\"${ERROR_LOG}\"]
|
||||||
\"Repository: ${{ github.repository }}\",
|
|
||||||
\"Branch: ${{ github.ref_name }}\",
|
|
||||||
\"Commit: ${{ github.sha }}\",
|
|
||||||
\"Run ID: ${{ github.run_id }}\",
|
|
||||||
\"Actor: ${{ github.actor }}\"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
\"context\": {
|
\"context\": {
|
||||||
\"workflow\": \"${{ github.workflow }}\",
|
\"workflow\": \"${{ github.workflow }}\",
|
||||||
\"run_id\": \"${{ github.run_id }}\",
|
\"run_id\": \"${{ github.run_id }}\",
|
||||||
\"branch\": \"${{ github.ref_name }}\",
|
\"branch\": \"${{ github.ref_name }}\",
|
||||||
\"actor\": \"${{ github.actor }}\"
|
\"actor\": \"${{ github.actor }}\",
|
||||||
|
\"failed_step\": \"${FAILED_STEP}\",
|
||||||
|
\"commit\": \"${{ github.sha }}\"
|
||||||
}
|
}
|
||||||
}" || true
|
}" || true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user