deploy(compose): 修 4 个上生产前的阻断项
为什么:v2.0 代码侧已 ready,但 docker compose up 起来会立刻 panic
(表不存在),且密码硬编码、Binance 直连超时、无 healthcheck。
修复:
1. migrate init container(migrate/migrate:v4.18.1)
- depends_on postgres service_healthy 后执行
- 跑完 up 退出;app depends_on migrate service_completed_successfully
- 表不存在的 race 彻底消除
2. postgres healthcheck(pg_isready)
- interval 5s、retries 10、start_period 10s
- app 不再在 init 期连接失败
3. .env + .env.example(守卫 G9)
- 密码、端口、Binance URL 全部从环境变量读
- POSTGRES_PASSWORD 未设置时 docker-compose 直接报错退出(${VAR:?...} 语法)
- .env 已在 .gitignore,.env.example 留作模板
4. HTTP_PROXY/HTTPS_PROXY/NO_PROXY 透传
- 国内直连 fapi.binance.com 不稳(AGENTS.md §7.5)
- NO_PROXY 默认包含 postgres 容器名,避免本地代理误走
附加:config 卷只读挂载(防容器内意外写入);ports 端口可由
.env 覆盖;postgres 容器名走 docker DNS(替换之前硬编码的
crypto-hermes-postgres)。
验证:python yaml lint 通过;依赖链 postgres healthy →
migrate completed → app start 已确认。docker 在本机不可用,
线上验证留给 commit 9 之后的人工 smoke。
This commit is contained in:
23
.env.example
Normal file
23
.env.example
Normal file
@@ -0,0 +1,23 @@
|
||||
# cryptoHermes 部署变量
|
||||
# 复制本文件到 .env 然后按需修改
|
||||
# .env 不入库(.gitignore 已忽略);.env.example 入库给团队作模板
|
||||
|
||||
# ---- Postgres ----
|
||||
# 强密码必须在生产环境覆盖
|
||||
POSTGRES_USER=postgres
|
||||
POSTGRES_PASSWORD=postgres
|
||||
POSTGRES_DB=hermes_market
|
||||
POSTGRES_PORT=5432
|
||||
|
||||
# ---- App ----
|
||||
APP_PORT=8080
|
||||
APP_ENV=production
|
||||
|
||||
# ---- Binance ----
|
||||
BINANCE_BASE_URL=https://fapi.binance.com
|
||||
|
||||
# ---- 国内网络代理(如不需要可留空)----
|
||||
# 例如 http://host.docker.internal:7890
|
||||
HTTP_PROXY=
|
||||
HTTPS_PROXY=
|
||||
NO_PROXY=localhost,127.0.0.1,postgres,crypto-hermes-postgres
|
||||
Reference in New Issue
Block a user