From b66859498f29768b1b58aeac1c8fc4ee7ac7481e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=BD=E5=93=92=E5=93=92?= Date: Thu, 19 Mar 2026 01:43:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4=E5=88=B060=E5=88=86?= =?UTF-8?q?=E9=92=9F=EF=BC=8C=E5=90=AF=E7=94=A8=20BuildKit=20=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=8A=A0=E9=80=9F=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yaml | 86 ++++++++++++++++++++++++++++++++++++ frontend/Dockerfile | 5 ++- 2 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 .gitea/workflows/deploy.yaml diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml new file mode 100644 index 0000000..d0b24be --- /dev/null +++ b/.gitea/workflows/deploy.yaml @@ -0,0 +1,86 @@ +name: Deploy to Server +on: [push] + +jobs: + deploy: + runs-on: ubuntu + timeout-minutes: 60 + steps: + - name: Deploy using SSH + # 使用 Gitea 官方镜像源,加速国内访问 + uses: https://gitea.com/actions/appleboy-ssh-action@v1.0.3 + with: + host: 6.6.6.66 + username: quant + password: 123quant-speed + command_timeout: 50m + script: | + TARGET_DIR="/home/quant/data/dev/sign-up" + SUDO_PASSWORD="123quant-speed" + REPO_URL="https://gitea.tangledup-ai.com/quant-speed-AI/Scoring-System.git" + + # 1. 检查目录是否存在,不存在则创建并克隆 + echo "===== 检查目标目录: $TARGET_DIR =====" + if [ ! -d "$TARGET_DIR" ]; then + echo "目录不存在,创建目录并克隆仓库..." + mkdir -p $TARGET_DIR + git clone $REPO_URL $TARGET_DIR + fi + + # 2. 切换到目标目录 + echo "===== 切换到目标目录: $TARGET_DIR =====" + cd $TARGET_DIR || { + echo "错误:目录 $TARGET_DIR 不存在!" + exit 1 + } + + # 3. 停止并移除 Docker 容器及镜像 + echo -e "\n===== 停止并清理 Docker =====" + # 强制停止并删除容器,忽略错误 + echo $SUDO_PASSWORD | sudo -S docker compose down --remove-orphans 2>/dev/null || true + # 等待容器完全停止 + sleep 5 + # 清理本项目残留容器(避免影响其他项目) + echo $SUDO_PASSWORD | sudo -S docker ps -aq --filter "name=cywl-scoring" | xargs -r docker rm -f 2>/dev/null || true + + # 4. 拉取 Git 最新代码 + echo -e "\n===== 拉取 Git 代码 =====" + # 尝试拉取,如果失败则强制重置,增强鲁棒性 + if ! git pull; then + echo "警告:Git pull 失败,尝试强制同步远程代码..." + git fetch --all + # 获取当前分支名并重置 + CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + git reset --hard origin/$CURRENT_BRANCH + git pull + fi + + # 5. 创建/更新 .env 文件 (从本地环境变量注入) + echo -e "\n===== 配置环境变量 =====" + cat > backend/.env <