From 6eb9de4812264441ad79e3663f1137433aef440b Mon Sep 17 00:00:00 2001 From: sky121113 Date: Tue, 21 Apr 2026 16:37:50 +0800 Subject: [PATCH] =?UTF-8?q?[FIX]=20=E5=BC=B7=E5=8C=96=20CI/CD=20Step=202?= =?UTF-8?q?=20=E9=83=A8=E7=BD=B2=E8=85=B3=E6=9C=AC=E8=88=87=E9=8C=AF?= =?UTF-8?q?=E8=AA=A4=E8=A8=BA=E6=96=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 改進 deploy_to 函式,同時驗證 tar 與 docker exec 的結束碼,避免靜默失敗。 2. 增加同步過程的日誌輸出 (tar/docker status),提升故障排查效率。 3. 確保任一容器同步失敗時立即中斷流程,防止不完整的部署。 --- .gitea/workflows/deploy-demo.yaml | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/deploy-demo.yaml b/.gitea/workflows/deploy-demo.yaml index f2bea5e..9bcf4af 100644 --- a/.gitea/workflows/deploy-demo.yaml +++ b/.gitea/workflows/deploy-demo.yaml @@ -43,13 +43,28 @@ jobs: shell: bash run: | deploy_to() { - tar --exclude='.git' --exclude='node_modules' --exclude='vendor' --exclude='storage' --exclude='bootstrap/cache' -cf - . 2>/dev/null | docker exec -i "$1" tar -xf - -C /var/www/html/ - # tar exit 1 = "file changed as we read it" (non-fatal), exit 2+ = fatal - [ "${PIPESTATUS[0]}" -le 1 ] + local container=$1 + echo ">>> Syncing code to $container..." + tar --exclude='.git' --exclude='node_modules' --exclude='vendor' --exclude='storage' --exclude='bootstrap/cache' -cf - . \ + | docker exec -i "$container" tar -xf - -C /var/www/html/ + + local tar_status=${PIPESTATUS[0]} + local docker_status=${PIPESTATUS[1]} + + echo " Result: tar=$tar_status, docker=$docker_status" + + if [ $tar_status -le 1 ] && [ $docker_status -eq 0 ]; then + return 0 + else + echo "!!! Error: Sync failed for $container" + return 1 + fi } - deploy_to star-cloud-laravel - deploy_to star-cloud-queue - deploy_to star-cloud-mqtt-worker + + # 依序執行同步,任一失敗即中斷 + deploy_to star-cloud-laravel && \ + deploy_to star-cloud-queue && \ + deploy_to star-cloud-mqtt-worker && \ docker exec star-cloud-laravel sh -c " chown -R 1000:1000 /var/www/html && mkdir -p /.npm && chown -R 1000:1000 /.npm &&