Files
Scoring-System/.gitea/workflows/deploy.yaml
爽哒哒 c71ea29f54
Some checks failed
Deploy to Server / deploy (push) Has been cancelled
fix: 优化部署脚本,添加超时设置和强制删除容器
2026-03-18 23:21:49 +08:00

84 lines
3.3 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Deploy to Server
on: [push]
jobs:
deploy:
runs-on: ubuntu
timeout-minutes: 30
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
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=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 <<EOF
# 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
# 6. 重新启动 Docker 容器
echo -e "\n===== 启动 Docker 容器 ====="
echo $SUDO_PASSWORD | sudo -S docker compose up -d --build --quiet-pull
# 7. 等待服务启动
echo -e "\n===== 等待服务启动 ====="
sleep 15
# 8. 检查服务状态
echo -e "\n===== 检查服务状态 ====="
echo $SUDO_PASSWORD | sudo -S docker compose ps
echo -e "\n===== 操作完成!====="