Files
cryptoHermes/docker-compose.yml
dela ea22d06dab deploy(compose): app healthcheck + 优雅停 + 日志策略 + README 部署章节
- 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 干净。
2026-05-24 21:01:45 +08:00

80 lines
2.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 shutdownfiber.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: