From dd1fdc868f5870968b4892f9e178f5396fc4bdfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=BD=E5=93=92=E5=93=92?= Date: Sat, 21 Mar 2026 03:05:50 +0800 Subject: [PATCH] fix: use gitea API to download files one by one, bypass git pack --- .gitea/workflows/deploy.yaml | 57 +++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 0893371..9a346af 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -5,24 +5,7 @@ jobs: deploy: runs-on: ubuntu steps: - - name: Checkout code - run: | - git config --global http.version HTTP/1.1 - git clone --depth=1 https://sdd:zsj981107@gitea.tangledup-ai.com/quant-speed-AI/Scoring-System.git /tmp/scoring-deploy - - - name: Install sshpass - run: apt-get install -y sshpass rsync - - - name: Copy code to server - run: | - sshpass -p "123quant-speed" rsync -avz --delete \ - --exclude='.git' \ - --exclude='backend/.env' \ - --exclude='backend/media/' \ - -e "ssh -o StrictHostKeyChecking=no" \ - /tmp/scoring-deploy/ quant@6.6.6.66:/home/quant/data/dev/deploy/ - - - name: Deploy on server via SSH + - name: Download and deploy code uses: https://gitea.com/actions/appleboy-ssh-action@v1.0.3 with: host: 6.6.6.66 @@ -31,16 +14,42 @@ jobs: script: | TARGET_DIR="/home/quant/data/dev/deploy" SUDO_PASSWORD="123quant-speed" + API_BASE="https://gitea.tangledup-ai.com/api/v1" + REPO="quant-speed-AI/Scoring-System" + AUTH="sdd:zsj981107" + BRANCH="main" - cd $TARGET_DIR - - # 1. 停止并移除 Docker 容器 echo "===== 停止并清理 Docker =====" + cd $TARGET_DIR echo $SUDO_PASSWORD | sudo -S docker compose down - # 2. 创建/更新 .env 文件 + echo "===== 通过 API 下载代码 =====" + # 获取文件树 + FILE_LIST=$(curl -sk -u "$AUTH" "$API_BASE/repos/$REPO/git/trees/$BRANCH?recursive=true" | python3 -c " + import json,sys + data = json.load(sys.stdin) + for item in data.get('tree', []): + if item['type'] == 'blob': + print(item['path']) + ") + + echo "共发现 $(echo "$FILE_LIST" | wc -l) 个文件" + + # 逐个下载文件 + echo "$FILE_LIST" | while read -r filepath; do + # 跳过不需要的文件 + case "$filepath" in + backend/.env|backend/media/*|.git/*) continue ;; + esac + mkdir -p "$TARGET_DIR/$(dirname "$filepath")" + curl -sk -u "$AUTH" -o "$TARGET_DIR/$filepath" \ + "$API_BASE/repos/$REPO/raw/$filepath?ref=$BRANCH" + done + + echo "代码更新完成" + echo "===== 配置环境变量 =====" - cat > backend/.env < $TARGET_DIR/backend/.env <