# 拉取式部署配置(一次性) > 安全原则:CI 只构建、不部署;任何 AI 与流水线都不允许 SSH 到服务器执行命令。 > 部署由服务器本地的 watcher 监听 CI 产物目录自动完成。本文档的所有命令由**管理员本人**在服务器上执行一次。 ## 工作原理 ``` push main → Gitea Actions 构建 → 产物写入 /ci-artifacts(runner 与宿主同机) ↓ 服务器本地 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。