diff --git a/.gitignore b/.gitignore index 87194f1..715f96f 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,5 @@ deploy/caddy/conf.d/show.caddy logs .gocache artifacts/ + +frontend/coverage/ \ No newline at end of file diff --git a/deploy/README.md b/deploy/README.md index 5f33128..bfdf64f 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -165,7 +165,7 @@ HFB_SHOW_DIR=../hfb_show - 通过 Caddy 自动申请或续签 HTTPS 证书。 - 等待 MySQL、Redis 就绪。 - 按顺序执行尚未应用的数据库迁移。 -- 重启后端并检查 `https://你的域名/api/health`。 +- 重启后端并在容器内检查 `http://127.0.0.1:8080/api/health`。默认不依赖公网 DNS、TLS 或 Caddy;如需检查公网入口,可设置 `PROD_HEALTH_URL=https://你的域名/api/health`。 如需部署完成后直接跟随查看后端日志: diff --git a/deploy/docker-compose.prod.yml b/deploy/docker-compose.prod.yml index cfa5af2..ad50a6a 100644 --- a/deploy/docker-compose.prod.yml +++ b/deploy/docker-compose.prod.yml @@ -104,6 +104,12 @@ services: condition: service_healthy expose: - "8080" + healthcheck: + test: ["CMD-SHELL", "wget -q -O /dev/null -T 5 http://127.0.0.1:8080/api/health"] + interval: 10s + timeout: 6s + retries: 12 + start_period: 10s beszel: image: henrygd/beszel:0.18.7 diff --git a/scripts/deploy-prod.sh b/scripts/deploy-prod.sh index 0b9388b..5f4d113 100755 --- a/scripts/deploy-prod.sh +++ b/scripts/deploy-prod.sh @@ -69,7 +69,7 @@ show_help() { 环境变量: PROD_HEALTH_URL=https://你的域名/api/health - 部署后健康检查地址,默认使用 CADDY_DOMAIN + 部署后公网健康检查地址;设置后使用外部 curl 检查 PROD_PUBLIC_URL=https://你的域名 输出给用户看的访问地址 PROD_READY_TIMEOUT=120 @@ -591,18 +591,36 @@ run_migrations() { wait_http_ready() { local attempt - local url - url="$(health_url)" - log "等待接口健康检查通过..." + local url="${HEALTH_URL}" + + if [[ -n "${url}" ]]; then + log "等待公网接口健康检查通过..." + for ((attempt = 1; attempt <= READY_TIMEOUT; attempt++)); do + if curl -fsS --max-time 5 "${url}" >/dev/null 2>&1; then + log_success "公网健康检查通过:${url}" + return 0 + fi + sleep 1 + done + + log_error "公网健康检查超时:${url}" + exit 1 + fi + + url="http://127.0.0.1:8080/api/health" + log "等待后端容器内健康检查通过..." for ((attempt = 1; attempt <= READY_TIMEOUT; attempt++)); do - if curl -fsS --max-time 5 "${url}" >/dev/null 2>&1; then - log_success "健康检查通过:${url}" + if compose exec -T backend wget -q -O /dev/null -T 5 "${url}" >/dev/null 2>&1; then + log_success "容器内健康检查通过:${url}" return 0 fi sleep 1 done - log_error "健康检查超时:${url}" + log_error "后端容器内健康检查超时:${url}" + log_warn "最近 backend 日志:" + compose logs --tail=120 backend || true + log_error "可继续执行:$(compose_user_cmd) logs backend" exit 1 }