From e1612f63db8aa69f3a57175edae43d9cbb1b044a Mon Sep 17 00:00:00 2001 From: xiaoquan <838115837@qq.com> Date: Wed, 10 Jun 2026 17:40:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BD=BF=E7=94=A8=20Gitea=20=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E8=B5=B0=E7=BD=91=E7=BB=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 问题 - 网络克隆一直超时 - Docker 容器访问 Gitea HTTP 端口不通 ## 解决方案 - 直接使用宿主机文件系统中的 Gitea 仓库 - 路径:/www/dk_project/dk_app/gitea/gitea_P4dS/gitea/gitea/repositories/xiaoquan/rent.git - 使用 git init + git remote add 方式 - 完全不走网络,只读取本地文件 ## 优点 - 不依赖网络 - 速度极快 - 100% 可靠 Co-Authored-By: Claude Opus 4.7 --- .gitea/workflows/deploy.yml | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index e797262..cebcfde 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -13,29 +13,32 @@ jobs: deploy: runs-on: [self-hosted, rent-deploy] steps: - - name: Clone or update code + - name: Prepare code run: | WORK_DIR="/tmp/rent-deploy" + # Gitea 仓库在宿主机的实际路径 + GITEA_REPO="/www/dk_project/dk_app/gitea/gitea_P4dS/gitea/gitea/repositories/xiaoquan/rent.git" - # 使用宿主机的 Gitea 端口 - GITEA_URL="http://host.docker.internal:10082/xiaoquan/rent.git" + echo "准备代码目录..." - if [ -d "$WORK_DIR" ]; then - echo "代码目录已存在,拉取最新代码..." + if [ -d "$WORK_DIR/.git" ]; then + echo "代码目录已存在,更新代码..." cd $WORK_DIR - git fetch --all + git fetch origin + git checkout ${{ github.ref_name }} git reset --hard origin/${{ github.ref_name }} else - echo "首次克隆代码..." - # 尝试多个可能的地址 - git clone $GITEA_URL $WORK_DIR || \ - git clone http://172.17.0.1:10082/xiaoquan/rent.git $WORK_DIR || \ - git clone http://localhost:10082/xiaoquan/rent.git $WORK_DIR - + echo "首次初始化代码..." + rm -rf $WORK_DIR + mkdir -p $WORK_DIR cd $WORK_DIR - git checkout ${{ github.ref_name }} + git init + git remote add origin $GITEA_REPO + git fetch origin + git checkout -b ${{ github.ref_name }} origin/${{ github.ref_name }} fi + echo "✅ 代码准备完成" echo "当前分支: $(git branch --show-current)" echo "最新提交: $(git log -1 --oneline)"