Auto Deploy

👤 zjm1226 📦 v1.0.0 ⭐ 4.4 ⬇️ 813 下載
🔒 IT運維與安全 免費

📖 技能介紹

自動化部署技能

描述

自動化 Git 專案部署技能。支援從私有 Git 倉庫拉取程式碼、構建打包、SSH 部署到 Linux 伺服器。

適用場景: - 使用者提出開發需求後自動開發並部署 - 程式碼修改後自動構建部署 - 多專案部署管理

前置條件

1. Git 訪問配置

方式 A:HTTP 認證

# 配置 Git 憑據
git config --global credential.helper store

方式 B:SSH Key(推薦)

# 生成 SSH Key
ssh-keygen -t ed25519 -C "openclaw-deploy" -f ~/.ssh/openclaw_deploy

# 將公鑰新增到 Git 伺服器
cat ~/.ssh/openclaw_deploy.pub

2. 伺服器 SSH 配置

# 生成部署 SSH Key(如果複用上面的可以跳過)
ssh-keygen -t ed25519 -C "server-deploy" -f ~/.ssh/server_deploy

# 將公鑰新增到伺服器
ssh-copy-id -i ~/.ssh/server_deploy.pub user@server_ip

3. 驗證連線

# 測試 Git 連線
git ls-remote http://192.168.1.169:8015/peninsula/points

# 測試伺服器連線
ssh -i ~/.ssh/server_deploy user@server_ip "echo connected"

工作流程

標準部署流程

1. 接收需求 → 2. 拉取程式碼 → 3. 開發修改 → 4. Git 提交 
→ 5. 構建打包 → 6. SSH 傳輸 → 7. 伺服器部署 → 8. 服務重啟 → 9. 健康檢查

詳細步驟

步驟 1:拉取最新程式碼

cd /workspace/points
git pull origin main

步驟 2:開發修改

根據使用者需求修改程式碼檔案。

步驟 3:提交程式碼

git add .
git commit -m "feat: [需求描述]"
git push origin main

步驟 4:構建專案

Node.js 部分

cd /workspace/points
npm install
npm run build

Java 部分

cd /workspace/points/java-module
mvn clean package -DskipTests

步驟 5:打包部署產物

# 建立部署包
tar -czf points-deploy.tar.gz dist/ target/*.jar

步驟 6:SSH 傳輸到伺服器

scp -i ~/.ssh/server_deploy points-deploy.tar.gz user@server:/tmp/

步驟 7:伺服器部署

ssh -i ~/.ssh/server_deploy user@server << 'EOF'
  # 備份當前版本
  cp -r /www/wwwroot/points /www/backup/points_$(date +%Y%m%d_%H%M%S)

  # 解壓新程式碼
  tar -xzf /tmp/points-deploy.tar.gz -C /www/wwwroot/points

  # 重啟服務(根據實際服務管理方式)
  # systemd:
  systemctl restart points-service

  # 或寶塔面板:
  /etc/init.d/points restart

  # 或 PM2(Node.js):
  pm2 restart points

  # 清理臨時檔案
  rm /tmp/points-deploy.tar.gz
EOF

步驟 8:健康檢查

ssh -i ~/.ssh/server_deploy user@server "curl -s http://localhost:埠/health || exit 1"

配置項

DEPLOY_CONFIG.md 中配置以下資訊:

配置項 說明 示例
git.url Git 倉庫地址 http://192.168.1.169:8015/peninsula/points
git.branch 預設分支 main
server.host 伺服器 IP 192.168.1.100
server.port SSH 埠 22
server.user SSH 使用者 root
server.deployPath 部署路徑 /www/wwwroot/points
project.type 專案型別 nodejs / java / nodejs+java
project.build.node.buildCmd Node 構建命令 npm run build
project.build.java.buildCmd Java 構建命令 mvn clean package
project.deploy.restartCmd 重啟命令 pm2 restart points

錯誤處理

Git 連線失敗

  • 檢查網路連通性
  • 驗證認證資訊
  • 確認 SSH Key 已新增

SSH 連線失敗

  • 檢查伺服器 SSH 服務狀態
  • 驗證 SSH Key 許可權(chmod 600 ~/.ssh/server_deploy
  • 確認防火牆放行 SSH 埠

構建失敗

  • 檢查 Node.js/Java 版本
  • 確認依賴安裝完整
  • 檢視詳細錯誤日誌

部署失敗

  • 檢查部署目錄許可權
  • 確認磁碟空間充足
  • 回滾到備份版本

安全注意事項

  1. 敏感資訊保護
  2. 不要將密碼、Token 寫入配置檔案
  3. 使用 SSH Key 代替密碼認證
  4. SSH Key 設定許可權 chmod 600

  5. 許可權控制

  6. 部署指令碼需要 elevated 許可權執行
  7. 限制可部署的伺服器列表
  8. 敏感操作需要使用者確認

  9. 備份策略

  10. 每次部署前自動備份
  11. 保留最近 5 個版本
  12. 支援快速回滾

使用示例

簡單需求(直接部署)

使用者:幫我加個積分查詢介面

1. 開發修改程式碼
2. 提交 Git
3. 自動構建部署
4. 回覆使用者:已完成部署 ✅

複雜需求(需要 Review)

使用者:實現一個積分排行榜功能

1. 開發修改程式碼
2. 提交到 feature 分支
3. 回覆使用者:開發完成,請 Review
4. 使用者確認後合併到 main 並部署

回滾流程

小蔥技能7w4.net持續更新中。

# 獲取最新備份版本
BACKUP=$(ssh user@server "ls -t /www/backup/ | head -1")

# 恢復備份
ssh user@server << EOF
  systemctl stop points-service
  rm -rf /www/wwwroot/points/*
  cp -r /www/backup/$BACKUP/* /www/wwwroot/points/
  systemctl start points-service
EOF

版本:1.0.0
最後更新:2026-03-26

🤖 AI 評測

這個 Skill 質量中等偏上,自動化程度較高,能完成從開發到部署的完整流程。但安全性有明顯問題——配置中直接寫死了賬號密碼,存在洩露風險。另外有些功能配置了但沒真正用上,體驗上稍打折扣。文件雖然詳細但有點囉嗦。總體來說功能可用,但建議作者補齊安全漏洞再正式使用。

📊 多維度評分

適應性4.2
規範性4.2
有效性4.7
可靠性4
可信度5

📁 包含檔案 (15 個)

📄 DEPLOY_CONFIG.md 1.7 KB
📄 README.md 5.4 KB
📄 READY.md 5.1 KB
📄 SKILL.md 5 KB
📄 SSH_SETUP.md 1.5 KB
📄 _meta.json 130 B
📄 deploy-config.json 1.1 KB
📄 scripts/configure-ssh-manual.sh 533 B
📄 scripts/configure-ssh.sh 554 B
📄 scripts/deploy.sh 5.7 KB
📄 scripts/install-server-env.sh 3.3 KB
📄 scripts/rollback.sh 1.7 KB
📄 scripts/setup.sh 4.2 KB
📄 scripts/show-ssh-config.js 1.2 KB
📄 scripts/test-connection.sh 1.9 KB