deploy: harden compose harness
This commit is contained in:
@@ -222,6 +222,32 @@ grep -rn --include="*.go" "float64\|float32" internal/entity
|
||||
|
||||
---
|
||||
|
||||
## G13. docker compose 部署路径不可裸奔
|
||||
|
||||
**规则**:`docker compose up -d` 的生产/测试路径必须满足:
|
||||
|
||||
- Postgres 密码从 `.env` 注入,`.env.example` 只能留空占位,不能给 `postgres` 这类弱默认值。
|
||||
- `.dockerignore` 必须排除 `.env` 和 `.env.*`,防止 `Dockerfile` 的 `COPY . .` 把 secrets 送进 build context / builder layer。
|
||||
- app 容器内端口固定为 8080;宿主机暴露端口只通过 `APP_HOST_PORT` 调整。不要在 compose 中用 `${APP_PORT}` 同时控制容器内监听和宿主机映射。
|
||||
- app 必须等待 Postgres healthcheck 通过、migration init container 成功退出后再启动。
|
||||
|
||||
**为什么**:这个服务虽然不接 Binance 私钥,但 DB 密码和代理凭据仍可能出现在 `.env`。同时 app 启动前若表不存在,会导致 collector/API 失败;端口变量混用会让健康检查和端口映射分叉。
|
||||
|
||||
**怎么验证**:
|
||||
```bash
|
||||
make guard
|
||||
|
||||
# 部署机额外跑(本地无 docker 时可跳过,但发布前必须跑)
|
||||
docker compose config
|
||||
docker compose up -d
|
||||
docker compose ps
|
||||
curl -s http://localhost:${APP_HOST_PORT:-8080}/v1/health
|
||||
```
|
||||
|
||||
**例外**:无。若改为 Kubernetes / Helm / systemd 部署,也必须保留同等约束:secret 不进镜像、migration 先于 app、readiness 可观测、容器内端口稳定。
|
||||
|
||||
---
|
||||
|
||||
## 升级守护规则的时机
|
||||
|
||||
同一类错误第二次出现 → 写一条新规则进来。修改本文件 = 改动了项目契约,需要在 PR 描述里说明原因并 @ 维护者。
|
||||
|
||||
Reference in New Issue
Block a user