Files
Edu/infra/apollo-router/dev-apps-entrypoint.sh
SpecialX 682f323bad chore(infra): docker dev-apps stack + apollo-router v1.45 compat
- 新增 docker-compose.dev-apps.yml:7 个应用服务容器化
  (iam/classes/core-edu/content/msg/push-gateway/api-gateway)
  + apollo-router override
- 新增 apollo-router dev-apps-entrypoint.sh / dev-apps-supergraph.yaml
  仅等待 5 个子图(iam/core-edu/content/msg/config-service)
  避免等待未启动的 ai/data-ana
- router.yaml:移除 v1.45 不兼容键
  (require_manifest/manifest_path/max_cost/max_batch_size)
  移除 ELv2 受限特性(persisted_queries/limits.max_depth)
  自托管无 GraphOS license
- docker-compose.yml:config-service 添加 NODE_ENV=production
  修复 pino-pretty devDep 误用
  apollo-router 添加 APOLLO_PERSISTED_QUERIES env
- services/{classes,core-edu,content,config-service}/Dockerfile
  重写为 repo 根 context + shared-ts/shared-proto 工作区依赖
  + --ignore-scripts
  修复 ERR_PNPM_WORKSPACE_PKG_NOT_FOUND 与 ERR_PNPM_IGNORED_BUILDS
- api-gateway healthcheck:wget --spider 改为 wget -O /dev/null
  修复 busybox 对 200+body 误报 exit 8
2026-07-22 11:35:02 +08:00

93 lines
3.0 KiB
Bash
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.
#!/bin/bash
# Apollo Router 启动脚本dev-apps 模式:仅 5 个 TS 子图)
#
# 与 entrypoint.sh 的差异:
# - SUBGRAPHS 仅包含 iam/core-edu/content/msg/config-service排除 ai/data-ana
# - 依赖 docker compose depends_on 已确保子图健康,等待重试次数减少到 30
#
# 使用:通过 docker-compose.dev-apps.yml 卷挂载覆盖 /dist/entrypoint.sh
set -e
SUBGRAPHS=(
"iam:iam:3002"
"core-edu:core-edu:3004"
"content:content:3005"
"msg:msg:3007"
"config-service:config-service:3011"
)
echo "[apollo-router:dev-apps] Waiting for subgraphs to be ready..."
wait_for_subgraph() {
local name="$1"
local host="$2"
local port="$3"
local max_retries=30
local retry=0
while [ $retry -lt $max_retries ]; do
if curl -sf -o /dev/null "http://${host}:${port}/healthz" 2>/dev/null; then
echo "[apollo-router:dev-apps] ${name} is ready (http://${host}:${port})"
return 0
fi
retry=$((retry + 1))
echo "[apollo-router:dev-apps] Waiting for ${name} at ${host}:${port} (attempt ${retry}/${max_retries})"
sleep 3
done
echo "[apollo-router:dev-apps] WARNING: ${name} not ready after ${max_retries} attempts, continuing anyway..."
return 0
}
for entry in "${SUBGRAPHS[@]}"; do
name="${entry%%:*}"
hostport="${entry#*:}"
host="${hostport%%:*}"
port="${hostport##*:}"
wait_for_subgraph "$name" "$host" "$port"
done
# 组合 supergraph SDL
echo "[apollo-router:dev-apps] Composing supergraph SDL..."
export APOLLO_ELV2_LICENSE=accept
max_compose_retries=5
compose_retry=0
while [ $compose_retry -lt $max_compose_retries ]; do
compose_retry=$((compose_retry + 1))
if rover supergraph compose --config /dist/supergraph.yaml --output /tmp/supergraph.graphql 2>&1; then
echo "[apollo-router:dev-apps] Supergraph composed successfully"
break
fi
echo "[apollo-router:dev-apps] Compose attempt ${compose_retry}/${max_compose_retries} failed, retrying in 5s..."
sleep 5
done
if [ ! -f /tmp/supergraph.graphql ]; then
echo "[apollo-router:dev-apps] ERROR: Failed to compose supergraph after ${max_compose_retries} attempts"
exit 1
fi
# PQ manifest 检查dev 模式 require_manifest=false仅警告
MANIFEST_PATH="/etc/apollo-router/pq-manifest.json"
REQUIRE_MANIFEST="${APOLLO_REQUIRE_PQ_MANIFEST:-false}"
if [ "${REQUIRE_MANIFEST}" = "true" ]; then
if [ ! -f "${MANIFEST_PATH}" ]; then
echo "[apollo-router:dev-apps] ERROR: APOLLO_REQUIRE_PQ_MANIFEST=true but manifest not found at ${MANIFEST_PATH}"
exit 1
fi
echo "[apollo-router:dev-apps] PQ manifest loaded (require_manifest=true): ${MANIFEST_PATH}"
else
if [ ! -f "${MANIFEST_PATH}" ]; then
echo "[apollo-router:dev-apps] WARNING: PQ manifest not found at ${MANIFEST_PATH} (require_manifest=false, continuing)"
else
echo "[apollo-router:dev-apps] PQ manifest loaded (require_manifest=false): ${MANIFEST_PATH}"
fi
fi
# 启动 router
echo "[apollo-router:dev-apps] Starting Apollo Router on port 3000..."
exec /dist/router --config /dist/configuration.yaml --supergraph /tmp/supergraph.graphql --hot-reload