docs: clarify main vs v1.0.0-user deploy paths and fix deploy.sh git sync

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-30 20:43:56 +08:00
parent ec1c9873b7
commit b6a4f98b86
3 changed files with 145 additions and 54 deletions
+6 -12
View File
@@ -41,21 +41,15 @@
## 快速开始
**服务器(Ubuntu**
**你自己部署(完整版 · 用 `main` 分支**
```bash
git clone https://gitee.com/dekun/qihuo.git /opt/qihuo
cd /opt/qihuo
git fetch --tags
git checkout v1.0.0-user
bash deploy.sh
# 访问 http://<IP>:6600
```
见 [docs/DEPLOY.md](docs/DEPLOY.md) → **A. 你自己部署(完整版 · main)**
**本地开发**
**客户交付 / 个人用户版(`v1.0.0-user`**
```bash
python3 -m venv venv
见 [docs/DEPLOY.md](docs/DEPLOY.md) → **B. 客户交付(个人用户版 · v1.0.0-user**。**本地开发(当前分支为用户版代码)**
```bashpython3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
+37 -14
View File
@@ -13,7 +13,8 @@
set -euo pipefail
APP_DIR="/opt/qihuo"
REPO_URL="https://git.bz121.com/dekun/qihuo.git"
REPO_URL="${QIHUO_REPO_URL:-https://gitee.com/dekun/qihuo.git}"
USER_EDITION_TAG="${QIHUO_USER_TAG:-v1.0.0-user}"
SERVICE_NAME="qihuo"
# SimNow 前置候选(按优先级;部署时自动 nc 探测)
@@ -45,18 +46,6 @@ ensure_locale_gen() {
fi
}
ensure_env_key() {
local file="$1" key="$2" val="$3"
if [ ! -f "$file" ]; then
return
fi
if grep -q "^${key}=" "$file"; then
return
fi
echo "${key}=${val}" >>"$file"
echo " .env 补全: ${key}=${val}"
}
pick_simnow_front() {
local host td_port md_port
for entry in "${SIMNOW_FRONTS[@]}"; do
@@ -89,6 +78,33 @@ update_simnow_front_in_env() {
fi
}
ensure_env_key() {
local file="$1" key="$2" val="$3"
if [ ! -f "$file" ]; then
return
fi
if grep -q "^${key}=" "$file"; then
return
fi
echo "${key}=${val}" >>"$file"
echo " .env 补全: ${key}=${val}"
}
is_user_edition_tree() {
[ -f "$APP_DIR/edition.py" ] && grep -q 'USER_EDITION = True' "$APP_DIR/edition.py" 2>/dev/null
}
sync_git_repo() {
if is_user_edition_tree; then
echo "==> 个人用户版:同步 tag ${USER_EDITION_TAG}(不拉 main"
git fetch origin --tags
git checkout -f "${USER_EDITION_TAG}"
return
fi
echo "==> 完整版:更新 main"
git pull origin main || git pull origin master || true
}
echo "==> 检查系统依赖..."
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq
@@ -141,7 +157,7 @@ mkdir -p "$(dirname "$APP_DIR")"
if [ -d "$APP_DIR/.git" ]; then
echo "==> 更新已有仓库..."
cd "$APP_DIR"
git pull origin main || git pull origin master || true
sync_git_repo
else
if [ -d "$APP_DIR" ] && [ "$(ls -A "$APP_DIR" 2>/dev/null)" ]; then
echo "目录 ${APP_DIR} 已存在且非 git 仓库,请手动处理后重试"
@@ -149,6 +165,13 @@ else
fi
git clone "$REPO_URL" "$APP_DIR"
cd "$APP_DIR"
if [ "${QIHUO_USER_EDITION:-}" = "1" ]; then
echo "==> 首次部署个人用户版:checkout ${USER_EDITION_TAG}"
git fetch origin --tags
git checkout -f "${USER_EDITION_TAG}"
else
git checkout main 2>/dev/null || git checkout master 2>/dev/null || true
fi
fi
echo "==> Python 虚拟环境与依赖..."
+102 -28
View File
@@ -4,19 +4,17 @@
---
## 个人用户版 v1.0.0-user
## 先选部署场景(重要)
客户交付请使用 **tag**,勿部署 `main`
| 场景 | 代码 | 说明 |
|------|------|------|
| **你自己**(完整版) | 分支 **`main`** | 含 K 线、可开仓品种表、复盘自动 K 线等 |
| **客户交付**(个人用户版) | tag **`v1.0.0-user`** | 不含上述三项,见 [RELEASE-v1.0.0-user.md](./RELEASE-v1.0.0-user.md) |
```bash
git clone https://gitee.com/dekun/qihuo.git /opt/qihuo
cd /opt/qihuo
git fetch --tags
git checkout v1.0.0-user
bash deploy.sh
```
**不要混用**:客户服务器 checkout `v1.0.0-user`;你自己的服务器用 `main`
功能范围见 [RELEASE-v1.0.0-user.md](./RELEASE-v1.0.0-user.md)。**你自己**的开发服务器继续用 `main` 即可。
**仓库地址(Gitee**https://gitee.com/dekun/qihuo.git
(私有镜像:`https://git.bz121.com/dekun/qihuo.git`,步骤相同,仅改 clone URL)
---
@@ -29,7 +27,8 @@ bash deploy.sh
| 服务端口 | `6600` |
| 进程管理 | PM2,应用名 `qihuo` |
| 数据库 | SQLite `futures.db` |
| 仓库 | https://git.bz121.com/dekun/qihuo.git |
| 完整版代码 | 分支 `main` |
| 用户版代码 | tag `v1.0.0-user` |
---
@@ -40,9 +39,9 @@ bash deploy.sh
- **Node.js + PM2**:进程守护与开机自启
- **编译工具**(安装 vnpy_ctp 时需要):`build-essential``python3-dev``pkg-config`
- **网络**
- `hq.sinajs.cn`(新浪行情
- `hq.sinajs.cn`(新浪现价,内部逻辑
- 企业微信 API(若启用推送)
- `git.bz121.com`(拉取代码)
- `gitee.com``git.bz121.com`(拉取代码)
- `pypi.org`pip 安装依赖)
- SimNow / 期货公司 **CTP 前置地址**(下单与持仓,见下文)
@@ -50,22 +49,65 @@ bash deploy.sh
## 一键部署(推荐)
**root** 登录服务器后执行
**root** 登录服务器后执行
`deploy.sh` 会装系统依赖、locale、venv、PM2 等;**首次须先 clone 并 checkout 到正确版本**。
### A. 你自己部署(完整版 · `main`)
**首次:**
```bash
git clone https://gitee.com/dekun/qihuo.git /opt/qihuo
cd /opt/qihuo
git checkout main
bash deploy.sh
nano /opt/qihuo/.env # ADMIN_*、SIMNOW_* 等
pm2 restart qihuo
```
**已有目录、日常更新:**
```bash
cd /opt/qihuo
# 若目录不存在,先克隆:
# git clone https://git.bz121.com/dekun/qihuo.git /opt/qihuo
git checkout main
bash deploy.sh
```
`deploy.sh` 会自动完成:
### B. 客户交付(个人用户版 · `v1.0.0-user`
**首次(SSH 帮客户部署):**
```bash
git clone https://gitee.com/dekun/qihuo.git /opt/qihuo
cd /opt/qihuo
git fetch --tags
git checkout v1.0.0-user
bash deploy.sh
nano /opt/qihuo/.env # 客户 ADMIN_*、SIMNOW_* 等
pm2 restart qihuo
```
**已有目录、用户版小版本升级(如 v1.0.1-user):**
```bash
cd /opt/qihuo
git fetch --tags
git checkout v1.0.1-user # 换成新 tag
bash deploy.sh
```
> 用户版再次执行 `deploy.sh` 时,脚本会识别 `edition.py` 并**保持在用户版 tag**,不会误拉到 `main`。
访问:`http://<服务器IP>:6600`
---
### `deploy.sh` 会自动完成
1. 安装系统依赖:`python3``git``build-essential``python3-dev``pkg-config``locales``netcat-openbsd``pm2`
2. **时区**设为 `Asia/Shanghai`(与 SimNow 交易时段一致)
3. **locale**:生成 `zh_CN.GB18030``zh_CN.UTF-8`CTP 登录必需,缺则进程崩溃)
4. `git pull` `git clone``/opt/qihuo`
4. `git pull`(完整版 `main`)或 `git checkout` 用户版 tag`git clone``/opt/qihuo`
5. 创建/保留虚拟环境 `venv``pip install -r requirements.txt`,验证 `vnpy_ctp`
6. 首次生成 `.env`,并补全 `SIMNOW_ENV=实盘``CTP_AUTO_RECONNECT=true` 等缺项
7. **自动探测 SimNow 前置**`nc` 测端口),写入可用的 `SIMNOW_TD/MD_ADDRESS`(优先 `182.254.243.31`,其次 `180.168.146.187`
@@ -74,12 +116,15 @@ bash deploy.sh
部署完成后访问:`http://<服务器IP>:6600`
> 再次部署只需 `cd /opt/qihuo && bash deploy.sh`,无需手工装 locale 或改前置地址。
> 完整版日常更新:`cd /opt/qihuo && git checkout main && bash deploy.sh`
> 用户版:`git checkout v1.0.0-user && bash deploy.sh`(见上文 B
---
## 手动部署
与一键部署相同,请先 **clone + checkout 到 `main` 或 `v1.0.0-user`**,再执行下列步骤。
### 1. 安装系统依赖
```bash
@@ -97,9 +142,21 @@ npm install -g pm2
### 2. 克隆代码
**完整版(自己):**
```bash
git clone https://git.bz121.com/dekun/qihuo.git /opt/qihuo
git clone https://gitee.com/dekun/qihuo.git /opt/qihuo
cd /opt/qihuo
git checkout main
```
**用户版(客户):**
```bash
git clone https://gitee.com/dekun/qihuo.git /opt/qihuo
cd /opt/qihuo
git fetch --tags
git checkout v1.0.0-user
```
### 3. Python 虚拟环境与依赖
@@ -187,18 +244,30 @@ mkdir -p /opt/qihuo/logs /opt/qihuo/uploads
## 更新部署
代码已推送后,在服务器执行:
### 完整版(你自己 · `main`
```bash
cd /opt/qihuo
git fetch origin
git checkout main
git reset --hard origin/main
source venv/bin/activate
pip install -r requirements.txt
pm2 restart qihuo
```
若服务器曾用 SCP 覆盖文件导致 `git pull` 冲突,用 `git reset --hard origin/main` 与远端对齐。
或:`git checkout main && bash deploy.sh`
### 个人用户版(客户 · tag)
```bash
cd /opt/qihuo
git fetch origin --tags
git checkout v1.0.0-user # 或新版本 tag
bash deploy.sh
```
若服务器曾用 SCP 覆盖文件导致冲突:完整版用 `git reset --hard origin/main`;用户版用 `git checkout -f v1.0.0-user`
`vnpy_ctp` 安装失败(常见于缺少编译环境):
@@ -215,7 +284,7 @@ pm2 restart qihuo
1. 浏览器登录 → **系统设置** 确认 **模拟盘 · SimNow**
2. 打开 **下单监控** 页 → 点击 **连接 CTP**
3. 连接成功后:权益来自柜台、显示 CTP 持仓、可报单与可开仓品种筛选
3. 连接成功后:权益来自柜台、显示 CTP 持仓、可报单(用户版含小账户四品种限制)
详见 [TRADING.md](./TRADING.md)。
@@ -242,9 +311,12 @@ pm2 save # 保存进程列表
## 本地开发
**完整版(默认):**
```bash
git clone https://git.bz121.com/dekun/qihuo.git
git clone https://gitee.com/dekun/qihuo.git qihuo
cd qihuo
git checkout main
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
@@ -274,7 +346,7 @@ python app.py
| 路径 | 说明 |
|------|------|
| `/opt/qihuo/futures.db` | 主数据库 |
| `/opt/qihuo/uploads/` | 复盘截图自动 K 线图 |
| `/opt/qihuo/uploads/` | 复盘截图(完整版含自动 K 线图 |
| `/opt/qihuo/data/fee_rates.json` | 默认手续费表(可重载) |
| `/root/qihuo_backup/` | 系统自动备份目录(`.tar.gz` |
@@ -351,7 +423,8 @@ ufw allow 6600/tcp
| **下单监控无持仓** | 未连接 CTP 或确实无仓 | 先点「连接 CTP」 |
| **`Could not resolve host`** | 服务器 DNS 故障 | 配置 systemd-resolved 公共 DNS,见下方 |
| `database is locked` | SQLite 并发 | 更新代码后重启 |
| `git pull` 冲突 | 本地有修改 / SCP 部署 | `git fetch && git reset --hard origin/main` |
| `git pull` 冲突 | 本地有修改 / SCP 部署 | 完整版:`git reset --hard origin/main`;用户版:`git checkout -f v1.0.0-user` |
| 用户版跑完变成完整版 | `deploy.sh` 误拉 `main` | 先 `git checkout v1.0.0-user`,再 `bash deploy.sh`(新版脚本已防误拉) |
查看应用是否在监听:
@@ -374,7 +447,7 @@ systemctl restart systemd-resolved
resolvectl flush-caches
```
验证:`resolvectl query git.bz121.com``curl cip.cc`
验证:`resolvectl query gitee.com``curl cip.cc`
---
@@ -449,6 +522,7 @@ pm2 restart qihuo
## 相关文档
- [个人用户版发行说明](./RELEASE-v1.0.0-user.md)
- [功能说明文档](./FEATURES.md)
- [SimNow 注册与接入说明](./SIMNOW.md)
- [手续费与导航设置](./FEES.md)