Files
Scoring-System/.gitea/workflows/deploy.yaml
爽哒哒 be8a2caf14
Some checks failed
Deploy to Server / deploy (push) Failing after 18s
fix: switch to wget with auth header for archive download
2026-03-21 02:50:42 +08:00

83 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
steps:
- 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: |
TARGET_DIR="/home/quant/data/dev/deploy"
SUDO_PASSWORD="123quant-speed"
# 1. 切换到目标目录
echo "===== 切换到目标目录: $TARGET_DIR ====="
cd $TARGET_DIR || {
echo "错误:目录 $TARGET_DIR 不存在!"
exit 1
}
# 2. 停止并移除 Docker 容器
echo -e "\n===== 停止并清理 Docker ====="
echo $SUDO_PASSWORD | sudo -S docker compose down
# 3. 拉取最新代码(通过 gitea API 下载压缩包)
echo -e "\n===== 拉取最新代码 ====="
ARCHIVE_URL="https://gitea.tangledup-ai.com/quant-speed-AI/Scoring-System/archive/main.tar.gz"
AUTH_HEADER="Authorization: Basic $(echo -n 'sdd:zsj981107' | base64)"
rm -f /tmp/scoring.tar.gz
DOWNLOAD_OK=false
for i in 1 2 3; do
echo "第 $i 次尝试下载代码包..."
wget --header="$AUTH_HEADER" -O /tmp/scoring.tar.gz "$ARCHIVE_URL" 2>&1 || true
FILE_SIZE=$(stat -c%s /tmp/scoring.tar.gz 2>/dev/null || echo 0)
echo "下载文件大小: $FILE_SIZE bytes"
if [ "$FILE_SIZE" -gt 10240 ] && tar -tzf /tmp/scoring.tar.gz > /dev/null 2>&1; then
DOWNLOAD_OK=true
break
fi
echo "文件不完整等待5秒后重试..."
rm -f /tmp/scoring.tar.gz
sleep 5
done
if [ "$DOWNLOAD_OK" != "true" ]; then
echo "错误:代码下载失败,终止部署"
exit 1
fi
echo "解压代码..."
tar -xzf /tmp/scoring.tar.gz -C /tmp/
rsync -av --exclude='.env' --exclude='media/' /tmp/Scoring-System/ $TARGET_DIR/
rm -rf /tmp/scoring.tar.gz /tmp/Scoring-System
echo "代码更新完成"
# 4. 创建/更新 .env 文件
echo -e "\n===== 配置环境变量 ====="
cat > backend/.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
# 5. 重新启动 Docker 容器
echo -e "\n===== 启动 Docker 容器 ====="
echo $SUDO_PASSWORD | sudo -S docker compose up -d --build
echo -e "\n===== 操作完成!====="