84 lines
3.0 KiB
YAML
84 lines
3.0 KiB
YAML
name: Deploy to Server
|
|
on: [push]
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu
|
|
steps:
|
|
- name: Download and deploy code
|
|
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"
|
|
API_BASE="https://gitea.tangledup-ai.com/api/v1"
|
|
REPO="quant-speed-AI/Scoring-System"
|
|
AUTH="sdd:zsj981107"
|
|
BRANCH="main"
|
|
|
|
echo "===== 停止并清理 Docker ====="
|
|
cd $TARGET_DIR
|
|
echo $SUDO_PASSWORD | sudo -S docker compose down
|
|
|
|
echo "===== 通过 API 下载代码 ====="
|
|
|
|
# 递归下载目录函数
|
|
download_dir() {
|
|
local dir_path="$1"
|
|
local api_path="${dir_path:+$dir_path}"
|
|
local url="$API_BASE/repos/$REPO/contents/${api_path}?ref=$BRANCH&token="
|
|
local items
|
|
items=$(curl -sk -u "$AUTH" "$API_BASE/repos/$REPO/contents/${api_path}?ref=$BRANCH")
|
|
echo "$items" | python3 -c "
|
|
import json,sys
|
|
try:
|
|
data = json.load(sys.stdin)
|
|
for item in data:
|
|
print(item['type'] + '|' + item['path'])
|
|
except: pass
|
|
" | while IFS='|' read -r type path; do
|
|
case "$path" in
|
|
backend/.env|.git/*) continue ;;
|
|
esac
|
|
if [ "$type" = "dir" ]; then
|
|
mkdir -p "$TARGET_DIR/$path"
|
|
download_dir "$path"
|
|
elif [ "$type" = "file" ]; then
|
|
mkdir -p "$TARGET_DIR/$(dirname "$path")"
|
|
curl -sk -u "$AUTH" -o "$TARGET_DIR/$path" \
|
|
"$API_BASE/repos/$REPO/raw/$path?ref=$BRANCH"
|
|
fi
|
|
done
|
|
}
|
|
|
|
download_dir ""
|
|
echo "代码更新完成"
|
|
|
|
echo "===== 配置环境变量 ====="
|
|
cat > $TARGET_DIR/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
|
|
|
|
echo "===== 启动 Docker 容器 ====="
|
|
cd $TARGET_DIR
|
|
echo $SUDO_PASSWORD | sudo -S docker compose up -d --build
|
|
|
|
echo "===== 操作完成!====="
|