fix: web API 502 — use Podman-local DNS for gateway proxy

Mount nginx template with NGINX_LOCAL_RESOLVERS and require web→gateway health in deploy checks.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
whm
2026-08-07 01:00:29 +08:00
parent e571e98387
commit cddf95594e
6 changed files with 62 additions and 27 deletions

View File

@@ -136,18 +136,14 @@ install_host_nginx_site_conf() {
}
reload_web_nginx() {
local cid
cid="$(compose_cmd ps -q web 2>/dev/null | head -1)"
if [ -z "$cid" ]; then
echo "web 容器未运行,跳过 reload" >&2
# compose 挂的是 templates改 conf 后需 recreate 才会重新 envsubst
echo "重建 web 容器以应用 nginx 模板 ..."
if compose_cmd up -d --force-recreate web; then
echo "web 容器已 recreatenginx.conf.template"
else
echo "web 重建失败" >&2
return 1
fi
run_sudo docker exec "$cid" nginx -t >/dev/null 2>&1 || {
echo "错误: 容器内 nginx -t 失败" >&2
return 1
}
run_sudo docker exec "$cid" nginx -s reload
echo "web 容器 nginx 已 reloadweb/nginx.conf"
}
restart_service() {
@@ -362,23 +358,24 @@ healthcheck() {
local gw_port web_port
gw_port="$(publish_host_port "${AIJZ_GATEWAY_PUBLISH:-127.0.0.1:8180}")"
web_port="$(publish_host_port "${AIJZ_WEB_PUBLISH:-127.0.0.1:5173}")"
echo "等待 gateway(:$gw_port) / web(:$web_port) ..."
echo "等待 gateway(:$gw_port) / web(:$web_port) 及 web→gateway 代理 ..."
for i in $(seq 1 60); do
if curl -fsS --max-time 2 "http://127.0.0.1:${gw_port}/gateway/health" >/dev/null 2>&1 \
&& curl -fsS --max-time 2 "http://127.0.0.1:${web_port}/" >/dev/null 2>&1; then
&& curl -fsS --max-time 2 "http://127.0.0.1:${web_port}/" >/dev/null 2>&1 \
&& curl -fsS --max-time 2 "http://127.0.0.1:${web_port}/gateway/health" >/dev/null 2>&1; then
ok=1
break
fi
# 中途补拉 web常见nginx 启动时 DNS 未就绪已退出)
if [ $((i % 10)) -eq 0 ]; then
compose_cmd up -d web >/dev/null 2>&1 || true
compose_cmd up -d --force-recreate web >/dev/null 2>&1 || compose_cmd up -d web >/dev/null 2>&1 || true
fi
sleep 2
done
if [ "$ok" -eq 1 ]; then
echo "健康检查通过."
else
echo "警告: 健康检查超时,请查看: docker compose -f $ROOT/docker-compose.yml logs" >&2
echo "警告: 健康检查超时(含 web 反代 /gateway/health,请查看: docker compose -f $ROOT/docker-compose.yml logs web gateway" >&2
fi
compose_cmd exec -T postgres psql -U platform -d platform -c 'ALTER USER platform CREATEDB;' >/dev/null 2>&1 || true
}