Files
lunar-mini/.gitea/docs/PULL_DEPLOY.md
T
gouki ec55a1d536
Publish Mini Program Dev Version / publish (push) Canceled after 0s
Build and Deploy Server / build (push) Canceled after 0s
fix(ci): 部署链路重构为拉取式,修复工作流问题
- deploy.sh: 目录级原子切换(current.new/current.old)替代 rm -rf 空窗式替换;
  健康检查改为轮询 /api/version HTTP 接口;失败自动回滚上一版本
- 新增 deploy-watch.sh: 服务器本地 systemd timer 轮询 /ci-artifacts 产物指纹,
  发现新版本自动部署——CI 与 AI 不再需要 SSH 到服务器执行任何命令
- server-deploy.yml: 部署包补入 web/ 后台静态资源;移除永不生效的前端构建死代码;
  通知文案如实改为'构建成功'(部署由服务器侧 watcher 完成)
- miniapp-preview.yml: 移除无意义的 --runInBand 测试参数
- 新增 PULL_DEPLOY.md 一次性安装文档(管理员手工执行)
2026-08-09 00:10:45 +00:00

69 lines
2.2 KiB
Markdown
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.
# 拉取式部署配置(一次性)
> 安全原则:CI 只构建、不部署;任何 AI 与流水线都不允许 SSH 到服务器执行命令。
> 部署由服务器本地的 watcher 监听 CI 产物目录自动完成。本文档的所有命令由**管理员本人**在服务器上执行一次。
## 工作原理
```
push main → Gitea Actions 构建 → 产物写入 /ci-artifactsrunner 与宿主同机)
服务器本地 systemd timer 每分钟运行 deploy-watch.sh → 发现新 sha256 → 执行 deploy.sh
目录级原子切换 → docker restart → HTTP 健康检查 → 失败自动回滚
```
## 一次性安装(管理员手工执行)
```bash
# 1. 放置脚本
sudo mkdir -p /opt/lunar/scripts
sudo cp deploy.sh deploy-watch.sh /opt/lunar/scripts/ # 从仓库 .gitea/scripts/ 复制
sudo chmod +x /opt/lunar/scripts/*.sh
# 2. systemd timer(每分钟轮询)
sudo tee /etc/systemd/system/lunar-deploy-watch.service > /dev/null <<'EOF'
[Unit]
Description=Lunar pull-based deploy watcher
[Service]
Type=oneshot
ExecStart=/bin/bash /opt/lunar/scripts/deploy-watch.sh
EOF
sudo tee /etc/systemd/system/lunar-deploy-watch.timer > /dev/null <<'EOF'
[Unit]
Description=Run lunar deploy watcher every minute
[Timer]
OnBootSec=1min
OnUnitActiveSec=1min
[Install]
WantedBy=timers.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now lunar-deploy-watch.timer
```
## 验证
```bash
systemctl list-timers | grep lunar
tail -f /opt/lunar/deploy-watch.log
curl -s http://localhost:8080/api/version
```
## 生产容器必备环境变量
在 1Panel 容器配置中设置(切勿写入仓库):
- `DB_HOST` / `DB_PORT` / `DB_USER` / `DB_PASSWORD` / `DB_NAME`
- `JWT_SECRET`(必须为强随机值,禁止使用默认值)
- `SERVER_ENV=production`
- `MINI_APP_ID` / `MINI_APP_SECRET`(微信登录)
- `WECHAT_PAY_APIKEY`(支付回调验签,未配置时回调接口直接返回 503)
- `ADMIN_PASSWORD`(管理后台登录,未配置时后台登录禁用)
## 回滚
deploy.sh 健康检查失败会自动回滚;手工回滚使用 `/opt/lunar/backups/` 下的备份包重新执行 deploy.sh。