This commit is contained in:
dekun
2026-05-22 13:15:12 +08:00
parent 3f0f77d450
commit 5ccf39022a
5 changed files with 166 additions and 117 deletions
+3
View File
@@ -0,0 +1,3 @@
* text=auto
*.sh text eol=lf
deploy/* text eol=lf
+4
View File
@@ -67,6 +67,7 @@ sudo usermod -aG docker $USER
```bash ```bash
cd /opt/Binance_Altcoin_Monitor cd /opt/Binance_Altcoin_Monitor
sed -i 's/\r$//' deploy/*.sh
chmod +x deploy/docker-deploy.sh chmod +x deploy/docker-deploy.sh
./deploy/docker-deploy.sh ./deploy/docker-deploy.sh
``` ```
@@ -120,6 +121,7 @@ sudo npm install -g pm2
```bash ```bash
cd /opt/Binance_Altcoin_Monitor cd /opt/Binance_Altcoin_Monitor
sed -i 's/\r$//' deploy/*.sh # 若从 Windows 克隆,先去掉 CRLF
chmod +x deploy/pm2-deploy.sh chmod +x deploy/pm2-deploy.sh
./deploy/pm2-deploy.sh ./deploy/pm2-deploy.sh
``` ```
@@ -280,6 +282,8 @@ pm2 restart binance-altcoin-monitor
| 现象 | 处理 | | 现象 | 处理 |
|------|------| |------|------|
| `bash\r: No such file or directory` | 脚本为 Windows 换行,执行:`sed -i 's/\r$//' deploy/*.sh && chmod +x deploy/*.sh` |
| `cannot pull with rebase: unstaged changes` | 执行 `git stash` 后重试;或 `DEPLOY_SKIP_GIT_PULL=1 ./deploy/pm2-deploy.sh` 跳过拉取 |
| Web 无数据 | 检查能否访问币安;国内服务器尝试 `PROXY_ENABLED=true` | | Web 无数据 | 检查能否访问币安;国内服务器尝试 `PROXY_ENABLED=true` |
| 企微收不到 | 检查 `WECOM_WEBHOOK_URL``curl -X POST .../api/push/test` | | 企微收不到 | 检查 `WECOM_WEBHOOK_URL``curl -X POST .../api/push/test` |
| 08:10 未推送 | 确认容器/PM2 在 08:10 前已运行;查日志 | | 08:10 未推送 | 确认容器/PM2 在 08:10 前已运行;查日志 |
+4 -2
View File
@@ -4,6 +4,9 @@ set -euo pipefail
INSTALL_DIR="/opt/Binance_Altcoin_Monitor" INSTALL_DIR="/opt/Binance_Altcoin_Monitor"
REPO_URL="${REPO_URL:-https://git.bz121.com/dekun/Binance_Altcoin_Monitor.git}" REPO_URL="${REPO_URL:-https://git.bz121.com/dekun/Binance_Altcoin_Monitor.git}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=lib.sh
source "${SCRIPT_DIR}/lib.sh"
echo "==> Docker 部署 Binance Altcoin Monitor" echo "==> Docker 部署 Binance Altcoin Monitor"
echo " 目录: ${INSTALL_DIR}" echo " 目录: ${INSTALL_DIR}"
@@ -20,8 +23,7 @@ if [ ! -d "${INSTALL_DIR}/.git" ]; then
sudo chown -R "$(whoami):$(whoami)" "${INSTALL_DIR}" 2>/dev/null || true sudo chown -R "$(whoami):$(whoami)" "${INSTALL_DIR}" 2>/dev/null || true
else else
echo "==> 更新代码..." echo "==> 更新代码..."
cd "${INSTALL_DIR}" git_update_safe "${INSTALL_DIR}"
git pull --rebase
fi fi
cd "${INSTALL_DIR}" cd "${INSTALL_DIR}"
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# 部署脚本公共函数(LF 换行)
# 安全拉取远程代码:有本地修改时先 stash,pull 失败不中断部署
git_update_safe() {
local repo_dir="${1:?}"
cd "$repo_dir"
if [ ! -d .git ]; then
return 0
fi
if [ "${DEPLOY_SKIP_GIT_PULL:-}" = "1" ]; then
echo " 已跳过 git pull (DEPLOY_SKIP_GIT_PULL=1)"
return 0
fi
local stashed=0
if ! git diff --quiet 2>/dev/null || ! git diff --cached --quiet 2>/dev/null; then
echo " 检测到未提交修改,暂存到 git stash..."
if git stash push -m "deploy-auto-$(date +%Y%m%d%H%M%S)"; then
stashed=1
else
echo " 警告: stash 失败,将尝试直接 pull"
fi
fi
if git pull --rebase; then
echo " 代码已更新"
else
echo " 警告: git pull 失败,使用当前目录代码继续部署"
fi
if [ "$stashed" = 1 ]; then
echo " 恢复本地修改 (git stash pop)..."
git stash pop || echo " 提示: stash 恢复冲突时可手动处理: git stash list"
fi
}
+4 -2
View File
@@ -4,6 +4,9 @@ set -euo pipefail
INSTALL_DIR="/opt/Binance_Altcoin_Monitor" INSTALL_DIR="/opt/Binance_Altcoin_Monitor"
REPO_URL="${REPO_URL:-https://git.bz121.com/dekun/Binance_Altcoin_Monitor.git}" REPO_URL="${REPO_URL:-https://git.bz121.com/dekun/Binance_Altcoin_Monitor.git}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=lib.sh
source "${SCRIPT_DIR}/lib.sh"
echo "==> PM2 部署 Binance Altcoin Monitor" echo "==> PM2 部署 Binance Altcoin Monitor"
echo " 目录: ${INSTALL_DIR}" echo " 目录: ${INSTALL_DIR}"
@@ -30,8 +33,7 @@ if [ ! -d "${INSTALL_DIR}/.git" ]; then
sudo chown -R "$(whoami):$(whoami)" "${INSTALL_DIR}" 2>/dev/null || true sudo chown -R "$(whoami):$(whoami)" "${INSTALL_DIR}" 2>/dev/null || true
else else
echo "==> 更新代码..." echo "==> 更新代码..."
cd "${INSTALL_DIR}" git_update_safe "${INSTALL_DIR}"
git pull --rebase
fi fi
cd "${INSTALL_DIR}" cd "${INSTALL_DIR}"