From b37155f65793ee7749365dacb1cadd55a1749542 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 01:45:44 +0800 Subject: [PATCH] update gitea deploy workflow --- .gitea/workflows/deploy.yaml | 71 +++++++++++------------------------- docker-compose.dev.yml | 42 --------------------- 2 files changed, 21 insertions(+), 92 deletions(-) delete mode 100644 docker-compose.dev.yml diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index f149d31..093b987 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -13,60 +13,32 @@ jobs: password: 123quant-speed script: | 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" - # sudo 函数 - run_sudo() { - echo "$SUDO_PASSWORD" | sudo -S "$@" + # 1. 切换到目标目录 + echo "===== 切换到目标目录: $TARGET_DIR =====" + cd $TARGET_DIR || { + echo "错误:目录 $TARGET_DIR 不存在!" + exit 1 } - # 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 容器 + # 2. 停止并移除 Docker 容器 echo -e "\n===== 停止并清理 Docker =====" - echo "$SUDO_PASSWORD" | sudo -S docker compose down 2>/dev/null || true + echo $SUDO_PASSWORD | sudo -S docker compose down - # 5. 创建/更新 .env 文件 + # 3. 拉取 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 + + # 4. 创建/更新 .env 文件 echo -e "\n===== 配置环境变量 =====" - run_sudo mkdir -p backend - run_sudo chown -R quant:quant backend - cat > /tmp/.env <<'EOF' + cat > backend/.env < - sh -c "pip install -r requirements.txt && - python manage.py migrate && - python manage.py runserver 0.0.0.0:8876" - extra_hosts: - - "host.docker.internal:host-gateway" - - # 前端服务 - 使用本地 Node - scoring-frontend: - image: node:20-alpine - container_name: cywl-scoring-frontend - working_dir: /app - volumes: - - ./frontend:/app - ports: - - "5173:5173" - environment: - - VITE_API_URL=http://localhost:8876/api - command: > - sh -c "npm install && - npm run dev -- --host 0.0.0.0"