From 3a1db5b99129f7716e7ae84764f7797f26e611dc 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 00:52:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=20git=20clone=20=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E5=92=8C=20curl=20HTTP/2=20=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yaml | 88 ++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 24 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 7b7f800..f149d31 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -5,48 +5,88 @@ jobs: deploy: runs-on: ubuntu steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Stop old containers + - name: Deploy using SSH uses: https://gitea.com/actions/appleboy-ssh-action@v1.0.3 with: host: 6.6.6.66 username: quant password: 123quant-speed script: | - cd /home/quant/data/dev/deploy 2>/dev/null && echo "123quant-speed" | sudo -S docker compose down 2>/dev/null || true + TARGET_DIR="/home/quant/data/dev/deploy" + REPO_URL="https://sdd:zsj981107@gitea.tangledup-ai.com/quant-speed-AI/Scoring-System.git" + SUDO_PASSWORD="123quant-speed" - - name: Upload files - uses: https://gitea.com/actions/appleboy-scp-action@v0.1.4 - with: - host: 6.6.6.66 - username: quant - password: 123quant-speed - source: "." - target: "/home/quant/data/dev/deploy" + # sudo 函数 + run_sudo() { + echo "$SUDO_PASSWORD" | sudo -S "$@" + } - - name: Start containers - uses: https://gitea.com/actions/appleboy-ssh-action@v1.0.3 - with: - host: 6.6.6.66 - username: quant - password: 123quant-speed - script: | - cd /home/quant/data/dev/deploy - mkdir -p backend - cat > backend/.env <<'EOF' + # 1. 创建目标目录 + echo "===== 创建目标目录: $TARGET_DIR =====" + run_sudo mkdir -p $TARGET_DIR + run_sudo chown -R quant:quant $TARGET_DIR + + # 2. 检查是否是 git 仓库 + echo "===== 检查 git 仓库 =====" + cd $TARGET_DIR + if [ ! -d ".git" ]; then + echo "目录不是 git 仓库,尝试克隆..." + # 尝试 git clone,失败则使用 curl 下载 + if ! git clone $REPO_URL . 2>/dev/null; then + echo "Git clone 失败,使用 curl 下载代码..." + cd /tmp + curl -L --http1.1 -o scoring-system.tar.gz "https://quant:123quant-speed@gitea.tangledup-ai.com/quant-speed-AI/Scoring-System/archive/refs/heads/main.tar.gz" || exit 1 + run_sudo tar -xzf scoring-system.tar.gz -C $TARGET_DIR + run_sudo mv $TARGET_DIR/Scoring-System-*/* $TARGET_DIR/ 2>/dev/null || run_sudo mv $TARGET_DIR/Scoring-System/* $TARGET_DIR/ + run_sudo rm -rf $TARGET_DIR/Scoring-System-* $TARGET_DIR/Scoring-System + rm scoring-system.tar.gz + run_sudo chown -R quant:quant $TARGET_DIR + fi + fi + + # 3. 拉取 Git 最新代码(如果是 git 仓库) + echo -e "\n===== 拉取 Git 代码 =====" + if [ -d ".git" ]; then + git remote set-url origin $REPO_URL + if ! git pull; then + echo "警告:Git pull 失败,尝试强制同步..." + git fetch --all + CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + git reset --hard origin/$CURRENT_BRANCH + fi + else + echo "不是 git 仓库,跳过 pull" + fi + + # 4. 停止并移除 Docker 容器 + echo -e "\n===== 停止并清理 Docker =====" + echo "$SUDO_PASSWORD" | sudo -S docker compose down 2>/dev/null || true + + # 5. 创建/更新 .env 文件 + echo -e "\n===== 配置环境变量 =====" + run_sudo mkdir -p backend + run_sudo chown -R quant:quant backend + cat > /tmp/.env <<'EOF' + # Database Configuration DB_NAME=scoring DB_USER=quant-speed DB_PASSWORD=123quant-speed DB_HOST=6.6.6.66 DB_PORT=5432 + # Aliyun OSS Configuration ALIYUN_ACCESS_KEY_ID=LTAI5tE62GW8MKyoEaotzxXk ALIYUN_ACCESS_KEY_SECRET=Zdzqo1fgj57DxxioXOotNKhJdSfVQW ALIYUN_OSS_ENDPOINT=https://oss-cn-shanghai.aliyuncs.com ALIYUN_OSS_BUCKET_NAME=tangledup-ai-staging ALIYUN_OSS_INTERNAL_ENDPOINT=https://oss-cn-shanghai-internal.aliyuncs.com + # Aliyun Tingwu Configuration ALIYUN_TINGWU_APP_KEY=6eOX7N3tKE0fDwb DASHSCOPE_API_KEY=sk-84e9eef24a274f568d4fa15c97556c9f EOF - echo "123quant-speed" | sudo -S docker compose up -d --build + run_sudo mv /tmp/.env backend/.env + + # 6. 重新启动 Docker 容器 + echo -e "\n===== 启动 Docker 容器 =====" + echo "$SUDO_PASSWORD" | sudo -S docker compose up -d --build + + echo -e "\n===== 操作完成!====="