Files
CI-CD/.gitea/workflows/deploy.yml
T
Shuai 27b4ad6307
Deploy Frontend / deploy (push) Failing after 10s
rsync网络问题
2026-06-19 23:39:16 +08:00

76 lines
2.9 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.
# ==========================================
# 纯 Bash 命令行部署工作流(适配自定义 SSH 端口)
# ==========================================
name: Deploy Frontend
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Execute Bash Deployment
run: |
# 🚨 [核心加速点]:免去 apt-get update3秒内直接下载绿色版 rsync
if ! command -v rsync &> /dev/null; then
echo "📦 正在极速拉取静态编译版 rsync..."
mkdir -p ~/.local/bin
# 从针对 Linux x86_64 静态编译的成品库直接下载单个文件
curl -sSL https://repo.malkas.club/pub/rsync/rsync-3.2.7-x86_64 -o ~/.local/bin/rsync
# 如果上面的小众源由于网络波动慢,这里提供一个极速国内加速镜像(Gitee 镜像)作为备用:
# curl -sSL https://gitee.com/quick-build-tools/rsync-static/raw/main/rsync-3.2.7-x86_64 -o ~/.local/bin/rsync
chmod +x ~/.local/bin/rsync
export PATH="$HOME/.local/bin:$PATH"
fi
# -------------- 1. 声明与解析变量 --------------
SERVER_IP="${{ secrets.SSH_HOST }}"
SERVER_USER="${{ secrets.SSH_USER }}"
TARGET_DIR="${{ secrets.TARGET_DIR }}"
SSH_PORT="${{ secrets.SSH_PORT }}"
: ${SERVER_IP:="192.168.31.185"}
: ${SERVER_USER:="root"}
: ${TARGET_DIR:="/data/apps/ci-cd/frontend"}
: ${SSH_PORT:="2222"}
echo "🌐 准备部署至目标服务器: ${SERVER_USER}@${SERVER_IP}:${TARGET_DIR} (端口: ${SSH_PORT})"
# -------------- 2. 初始化本地 SSH 环境 --------------
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
echo "🔍 正在扫描目标服务器主机指纹..."
ssh-keyscan -p "$SSH_PORT" -H "$SERVER_IP" >> ~/.ssh/known_hosts 2>/dev/null
# -------------- 3. 执行 rsync 增量同步 --------------
echo "🚀 开始传输增量文件..."
# 🚨 这里显式指定了我们刚刚下载的绿色版 rsync 路径
~/.local/bin/rsync -avz --delete \
-e "ssh -i ~/.ssh/id_ed25519 -p $SSH_PORT" \
--exclude=".git/" \
--exclude=".gitea/" \
--exclude=".github/" \
./ \
"${SERVER_USER}@${SERVER_IP}:${TARGET_DIR}"
# -------------- 4. 状态检查 --------------
if [ $? -eq 0 ]; then
echo "✨ 部署成功!"
else
echo "❌ 部署失败,请检查密钥权限或局域网连通性。"
exit 1
fi