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_PASSWORD must be set, see .env.example}@postgres:5432/${POSTGRES_DB:-hermes_market}?sslmode=disable - up restart: "no" app: build: context: . dockerfile: Dockerfile args: GOPROXY: ${GOPROXY:-https://goproxy.cn,direct} HTTP_PROXY: ${HTTP_PROXY:-} HTTPS_PROXY: ${HTTPS_PROXY:-} NO_PROXY: ${NO_PROXY:-} http_proxy: ${HTTP_PROXY:-} https_proxy: ${HTTPS_PROXY:-} no_proxy: ${NO_PROXY:-} container_name: crypto-hermes-market-gateway depends_on: postgres: condition: service_healthy migrate: condition: service_completed_successfully ports: - "${APP_HOST_PORT:-8080}:8080" environment: CONFIG_PATH: /app/config/config.yml APP_ENV: ${APP_ENV:-production} APP_PORT: "8080" POSTGRES_DSN: postgres://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set, see .env.example}@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: