- Dockerfile:alpine 安装 wget;加 HEALTHCHECK(/v1/health 探测,
interval 15s、start_period 20s、retries 3)
- docker-compose.yml app:
· stop_grace_period 30s(配合 fiber ShutdownWithContext 10s
+ cron 任务收尾,避免 SIGKILL 截断在途请求)
· restart unless-stopped
· json-file logging:单文件 50MB、保留 5 个滚动文件
· 业务日志卷 ./logs:/app/logs
- docker-compose.yml postgres:同样配 restart + logging
- logs/ 目录用 .gitkeep 保留;.gitignore 加 logs/* + !logs/.gitkeep
- README 新增'一键部署(docker compose)'整章:3 步上线、启动顺序图、
healthcheck 说明、优雅停机、日志、回填历史、生产 checklist
所有 12 条守卫保持无输出;build / vet 干净。
80 lines
2.5 KiB
YAML
80 lines
2.5 KiB
YAML
services:
|
||
postgres:
|
||
image: timescale/timescaledb:latest-pg16
|
||
container_name: crypto-hermes-postgres
|
||
environment:
|
||
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set, see .env.example}
|
||
POSTGRES_DB: ${POSTGRES_DB:-hermes_market}
|
||
ports:
|
||
- "${POSTGRES_PORT:-5432}:5432"
|
||
volumes:
|
||
- hermes_pg_data:/var/lib/postgresql/data
|
||
healthcheck:
|
||
# 用 pg_isready 探测,避免 init 期 race
|
||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres} -d ${POSTGRES_DB:-hermes_market}"]
|
||
interval: 5s
|
||
timeout: 3s
|
||
retries: 10
|
||
start_period: 10s
|
||
restart: unless-stopped
|
||
logging:
|
||
driver: json-file
|
||
options:
|
||
max-size: "50m"
|
||
max-file: "5"
|
||
|
||
# init container:跑完 migration 立即退出。
|
||
# 由 app 依赖它 service_completed_successfully,保证表存在再启动 app。
|
||
migrate:
|
||
image: migrate/migrate:v4.18.1
|
||
container_name: crypto-hermes-migrate
|
||
depends_on:
|
||
postgres:
|
||
condition: service_healthy
|
||
volumes:
|
||
- ./migrations:/migrations:ro
|
||
command:
|
||
- -path=/migrations
|
||
- -database=postgres://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-hermes_market}?sslmode=disable
|
||
- up
|
||
restart: "no"
|
||
|
||
app:
|
||
build:
|
||
context: .
|
||
dockerfile: Dockerfile
|
||
container_name: crypto-hermes-market-gateway
|
||
depends_on:
|
||
postgres:
|
||
condition: service_healthy
|
||
migrate:
|
||
condition: service_completed_successfully
|
||
ports:
|
||
- "${APP_PORT:-8080}:8080"
|
||
environment:
|
||
CONFIG_PATH: /app/config/config.yml
|
||
APP_ENV: ${APP_ENV:-production}
|
||
APP_PORT: ${APP_PORT:-8080}
|
||
POSTGRES_DSN: postgres://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-hermes_market}?sslmode=disable
|
||
BINANCE_BASE_URL: ${BINANCE_BASE_URL:-https://fapi.binance.com}
|
||
# 透传代理:国内直连 fapi.binance.com 不稳,详见 AGENTS.md §7.5
|
||
HTTP_PROXY: ${HTTP_PROXY:-}
|
||
HTTPS_PROXY: ${HTTPS_PROXY:-}
|
||
NO_PROXY: ${NO_PROXY:-}
|
||
volumes:
|
||
- ./config:/app/config:ro
|
||
- ./logs:/app/logs
|
||
# SIGTERM → 等 app 内置 10s graceful shutdown(fiber.ShutdownWithContext)
|
||
# + cron 任务结束的缓冲 = 30s。超时后 docker 发 SIGKILL。
|
||
stop_grace_period: 30s
|
||
restart: unless-stopped
|
||
logging:
|
||
driver: json-file
|
||
options:
|
||
max-size: "50m"
|
||
max-file: "5"
|
||
|
||
volumes:
|
||
hermes_pg_data:
|