Skip to content

Commit 67c4bf6

Browse files
chore: harden delivery configuration and runbooks
1 parent 4dc6cd7 commit 67c4bf6

6 files changed

Lines changed: 69 additions & 55 deletions

File tree

.env.example

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Do not put real credentials in this file or commit a populated .env file.
2+
BAZI_PUBLIC=true
3+
BAZI_AI_ENABLED=true
4+
BAZI_FUSION_ENGINE=0
5+
BAZI_LLM_REVIEW=0
6+
7+
# Set these only in the protected production environment.
8+
DEEPSEEK_API_KEY=
9+
DEEPSEEK_MODEL=deepseek-chat
10+
BAZI_ADMIN_KEY=
11+
12+
# Optional service limits.
13+
BAZI_MAX_AI_STREAMS=3
14+
BAZI_FUSION_TEMPERATURE=0.3
15+
BAZI_FUSION_REPAIR=1

.github/workflows/ci.yml

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,6 @@ jobs:
2929
- name: Install dependencies
3030
run: |
3131
pip install -r requirements.txt
32-
- name: Import check
33-
run: |
34-
cd scripts && python -c "
35-
import sys; sys.path.insert(0, '.')
36-
from bazi_engine.enums import Tiangan, Dizhi, Wuxing
37-
from bazi_engine.ten_gods import wuxing_relation, get_ten_god
38-
from bazi_engine.nayin_chain import find_all_nayin_relations
39-
from bazi_engine.day_pillar_db import lookup_day_pillar, verify_known_cases
40-
# Verify day pillar calculation
41-
assert verify_known_cases(), 'Day pillar verification failed'
42-
print('All imports OK')
43-
"
44-
- name: Quick integration test
45-
run: |
46-
cd scripts && python -c "
47-
import sys; sys.path.insert(0, '.')
48-
from bazi_engine.chart import build_chart
49-
c = build_chart('test', '\u7537', 1990, 6, 15, 12)
50-
d = c.to_dict()
51-
assert d.get('four_pillars', {}).get('year'), 'Missing year pillar'
52-
year_pillar = d['four_pillars']['year']
53-
print(f'Chart built: {year_pillar.get(\"stem\")}{year_pillar.get(\"branch\")}')
54-
print('Integration test OK')
55-
"
32+
pip install -r requirements-dev.txt
33+
- name: Full test suite
34+
run: cd scripts && python -m pytest tests/ -q

.github/workflows/test.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
# Bazi Engine — Docker 部署
21
FROM python:3.13-slim
32

4-
WORKDIR /app
5-
6-
# 安装依赖
73
COPY requirements.txt /app/requirements.txt
84
RUN pip install --no-cache-dir -r requirements.txt
95

10-
# 复制代码
11-
COPY scripts/ /app/scripts/
12-
COPY frontend/ /app/frontend/
6+
RUN addgroup --system app && adduser --system --ingroup app --home /app app
7+
8+
WORKDIR /app/scripts
9+
10+
COPY --chown=app:app scripts/ /app/scripts/
11+
COPY --chown=app:app frontend/ /app/frontend/
1312

1413
ENV FRONTEND_DIR=/app/frontend
1514
ENV BAZI_PUBLIC=true
1615

1716
EXPOSE 7860
1817

19-
CMD ["python", "-m", "uvicorn", "scripts.bazi_engine.api:app", "--host", "0.0.0.0", "--port", "7860"]
18+
USER app
19+
20+
CMD ["python", "-m", "uvicorn", "bazi_engine.api:app", "--host", "0.0.0.0", "--port", "7860"]

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@
5353

5454
```bash
5555
git clone https://github.com/jiwenxu025-boop/bazi-engine.git
56-
cd bazi-engine/scripts
57-
pip install -r requirements.txt
56+
cd bazi-engine
57+
python -m venv .venv
58+
# Windows: .venv\Scripts\activate
59+
# macOS/Linux: source .venv/bin/activate
60+
python -m pip install -r requirements.txt
5861
```
5962

6063
## 使用
@@ -81,7 +84,8 @@ python -m uvicorn bazi_engine.api:app --host 0.0.0.0 --port 8000
8184
### 测试
8285

8386
```bash
84-
# 单元测试
87+
python -m pip install -r requirements-dev.txt
88+
cd scripts
8589
python -m pytest tests/ -q
8690

8791
# 校准测试
@@ -171,7 +175,7 @@ bazi-engine/
171175
3. 添加环境变量:
172176
```
173177
BAZI_PUBLIC=true
174-
DEEPSEEK_API_KEY=sk-xxx # 可选,启用 AI 追问
178+
DEEPSEEK_API_KEY= # 可选,启用 AI 追问,不要提交到仓库
175179
DEEPSEEK_MODEL=deepseek-chat
176180
BAZI_LLM_REVIEW=1 # 可选,启用 LLM 推理层
177181
```
@@ -181,6 +185,10 @@ bazi-engine/
181185

182186
浏览器打开 `frontend/index.html`,API 地址填写公网 URL 即可远程排盘。
183187

188+
### 生产运维
189+
190+
生产环境变量请从 `.env.example` 创建,并保存在仓库外或受权限保护的 `.env` 中。部署、回滚、备份和公网 HTTP 风险说明见 [docs/operations.md](docs/operations.md)
191+
184192
## 免责声明
185193

186194
本引擎仅供传统文化学习与娱乐参考,分析结果不构成任何决策依据。命理学属于传统文化范畴,请理性看待。

docs/operations.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 生产运维
2+
3+
本项目的运行数据位于 `/opt/bazi/data/`。该目录包含反馈、配额和生成指标,必须保留在版本控制之外。
4+
5+
## 首次部署
6+
7+
1. 在服务器创建受限权限的环境文件:`/opt/bazi/.env`,并执行 `chmod 600 /opt/bazi/.env`
8+
2.[`.env.example`](../.env.example) 为字段清单填入生产值。不要把密钥写入命令行、仓库或聊天记录。
9+
3. 确认 `bazi.service``EnvironmentFile` 指向 `/opt/bazi/.env`,运行用户拥有 `/opt/bazi/data/` 的读写权限。
10+
4. 启动服务后检查服务器内网和公网的 `/api/health`。健康响应中的 `ai_enabled` 只表示 AI 功能开关,不暴露凭证。
11+
12+
## 常规发布
13+
14+
1. 在本地完成测试、静态检查和提交推送。
15+
2. 在服务器执行 `git pull --ff-only`,不要删除或重建 `/opt/bazi/data/`
16+
3. 重启 `bazi.service`,等待服务就绪后检查 `systemctl is-active bazi.service``/api/health`
17+
4. 对涉及前端的改动,在桌面和移动视口各做一次浏览器验证。
18+
19+
## 回滚
20+
21+
通过 GitHub 对有问题的提交执行 revert,再按常规发布流程部署 `main`。不要在生产机上通过强制重置 Git 历史回滚,以免丢失未同步的运行状态。
22+
23+
## 备份
24+
25+
每日将 `/opt/bazi/data/` 归档到仓库外的受限目录或对象存储,并定期演练还原。备份应加密并设置保留期,因为反馈与运行指标虽然不含报告正文,仍属于运营数据。
26+
27+
## 访问边界
28+
29+
- 管理汇总接口需要 `X-Admin-Key` 或 Bearer 管理密钥;不要为了排查问题临时关闭认证。
30+
- 当前公网服务仅提供 HTTP。POST 可以避免把出生信息放进 URL,但不能提供传输加密。正式 HTTPS 上线应等待域名备案和证书配置完成。

0 commit comments

Comments
 (0)