Files
CI-CD/.gitea/workflows/deploy.yml
T
Shuai 36cccb3d12
Deploy Frontend / deploy (push) Failing after 11s
2222
2026-06-19 23:28:13 +08:00

64 lines
2.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.
# ==========================================
# 纯 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: |
# -------------- 1. 声明与解析变量 --------------
SERVER_IP="${{ secrets.SSH_HOST }}"
SERVER_USER="${{ secrets.SSH_USER }}"
TARGET_DIR="${{ secrets.TARGET_DIR }}"
SSH_PORT="${{ secrets.SSH_PORT }}"
# 兜底本地测试变量(优先读取上面 Secrets,没有则走这里)
: ${SERVER_IP:="192.168.31.185"}
: ${SERVER_USER:="root"}
: ${TARGET_DIR:="/data/apps/ci-cd/frontend"}
: ${SSH_PORT:="2222"} # 👈 默认改为了 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
# 🚨 关键修改点 1ssh-keyscan 必须使用 -p 指定非 22 端口
echo "🔍 正在扫描目标服务器主机指纹..."
ssh-keyscan -p "$SSH_PORT" -H "$SERVER_IP" >> ~/.ssh/known_hosts 2>/dev/null
# -------------- 3. 执行 rsync 增量同步 --------------
echo "🚀 开始传输增量文件..."
# 🚨 关键修改点 2rsync 的 -e "ssh" 内部必须使用 -p 指定端口
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