Document Git-only deploy workflow and reduce positions page IPC blocking.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-01 14:05:37 +08:00
parent 7748a88219
commit b354d6c701
6 changed files with 247 additions and 65 deletions
+100 -1
View File
@@ -4,6 +4,52 @@
---
## 代码发布铁律(强制,不容置疑)
**所有代码变更必须且只能按以下三步执行,不得跳过、不得变通:**
| 步骤 | 在哪里 | 做什么 |
|------|--------|--------|
| **1. 本地修改** | 开发机 / 本仓库工作区 | 改代码、自测 |
| **2. 提交仓库** | `git.bz121.com` | `git add``git commit``git push origin main`(或约定分支) |
| **3. 更新服务器** | `/opt/qihuo` | **仅** `git fetch` + `git reset --hard origin/main`(或 `git pull`)→ 依赖/迁移 → `pm2 restart` |
### 严禁事项
- **禁止** 用 `scp``rsync`、SFTP、手工复制等方式把 `.py` / `.js` / `.html` / 模板 / 静态资源 **直接覆盖** 到服务器。
- **禁止** 在服务器上 `vim` 改业务代码后长期不提交仓库(`.env`、日志、上传文件除外)。
- **禁止** 「服务器上先改一版、本地以后再补提交」——服务器代码必须与远端 Git **完全一致**
违反上述规则会导致:`git pull` 冲突、Web 与 Worker 版本不一致、问题无法复现、回滚困难。**一律视为部署事故。**
### 服务器唯一合法更新命令
代码已推送到远端后,在服务器执行:
```bash
cd /opt/qihuo
git fetch origin
git reset --hard origin/main
source venv/bin/activate
pip install -r requirements.txt
python scripts/run_schema_migrate.py
pm2 restart ecosystem.config.cjs --update-env
pm2 save
```
或使用 `bash deploy.sh`(内部同样通过 Git 拉取,见下文)。
### 数据与配置(不受 Git 管理)
以下文件 **不**`git pull` 更新,卸载/重装时须 **单独备份与恢复**
- `/opt/qihuo/.env`
- `/opt/qihuo/futures.db`SQLite)或 PostgreSQL 数据
- `/opt/qihuo/uploads/`
- `/opt/qihuo/backups/`(若有)
---
## 部署概要
| 项目 | 默认值 |
@@ -87,6 +133,56 @@ MIGRATE_SQLITE=1 sudo bash scripts/deploy_postgres.sh
---
## 服务器卸载与全新部署(Git 唯一来源)
当服务器代码被 SCP 弄乱、版本不可信、或需要与仓库 **完全对齐** 时,按本节 **卸载后重装**。全程 **只** 通过 Git 获取代码,**不得** SCP 复制业务文件。
### 1. 备份(必做)
```bash
# 在服务器上
cp /opt/qihuo/.env /root/qihuo.env.bak
# SQLite
cp /opt/qihuo/futures.db /root/futures.db.bak 2>/dev/null || true
# PostgreSQL 见 POSTGRES.md 备份命令
tar czf /root/qihuo_uploads.bak.tar.gz -C /opt/qihuo uploads 2>/dev/null || true
```
### 2. 卸载 PM2 与代码目录
```bash
pm2 stop qihuo qihuo-ctp 2>/dev/null || true
pm2 delete qihuo qihuo-ctp 2>/dev/null || true
pm2 save
rm -rf /opt/qihuo
```
> **不删除** `/root/qihuo.env.bak`、`/root/futures.db.bak` 等备份。
### 3. 从 Git 全新克隆并部署
```bash
git clone https://git.bz121.com/dekun/qihuo.git /opt/qihuo
cd /opt/qihuo
cp /root/qihuo.env.bak .env
# SQLite 恢复(若使用)
cp /root/futures.db.bak futures.db 2>/dev/null || true
bash deploy.sh
```
### 4. 验收
```bash
cd /opt/qihuo && git log -1 --oneline # 须与远端 main 最新提交一致
pm2 status # qihuo、qihuo-ctp 均为 online
```
浏览器访问 `http://<服务器IP>:6600` 登录验证。
此后所有更新 **只** 走上文「代码发布铁律」三步,**禁止** 再使用 SCP 更新代码。
---
## 手动部署
### 1. 安装系统依赖
@@ -206,6 +302,9 @@ mkdir -p /opt/qihuo/logs /opt/qihuo/uploads
## 更新部署
> **强制流程**:本地修改 → `git push` → 服务器 `git fetch && git reset --hard origin/main` → 迁移 → `pm2 restart`。
> **禁止 SCP 复制代码。** 详见上文 [代码发布铁律](#代码发布铁律强制不容置疑)。
代码已推送后,在服务器执行:
```bash
@@ -383,7 +482,7 @@ ufw allow 6600/tcp
| **下单监控无持仓** | 未连接 CTP 或确实无仓 | 先点「连接 CTP」 |
| **`Could not resolve host`** | 服务器 DNS 故障 | 配置 systemd-resolved 公共 DNS,见下方 |
| `database is locked` | SQLite 并发 | **推荐改 PostgreSQL**`MIGRATE_SQLITE=1 bash scripts/deploy_postgres.sh`,见 [POSTGRES.md](./POSTGRES.md) |
| `git pull` 冲突 | 本地有修改 / SCP 部署 | `git fetch && git reset --hard origin/main` |
| `git pull` 冲突 | 曾用 SCP 覆盖文件(**禁止**) | 按 [服务器卸载与全新部署](#服务器卸载与全新部署git-唯一来源) 或 `git reset --hard origin/main` 与远端对齐 |
查看应用是否在监听:
+1 -1
View File
@@ -41,7 +41,7 @@
| [TRADING.md](./TRADING.md) | 可开仓品种、计仓、SimNow/实盘 |
| [SIMNOW.md](./SIMNOW.md) | SimNow 仿真注册与接入 |
| [CTP_LIVE.md](./CTP_LIVE.md) | **期货公司实盘 CTP** 与开平仓对比 |
| [DEPLOY.md](./DEPLOY.md) | 部署说明 |
| [DEPLOY.md](./DEPLOY.md) | 部署说明(含 **代码发布铁律**:仅 Git 三步,禁止 SCP |
| [POSTGRES.md](./POSTGRES.md) | **PostgreSQL 生产库**(一键部署、迁移、备份恢复) |
| [BACKUP.md](./BACKUP.md) | 数据备份与恢复 |