fix: harden blue-green routing and gateway migration

This commit is contained in:
2026-09-20 21:49:30 +08:00
parent b50d59a058
commit b4824ddf71
2 changed files with 18 additions and 10 deletions
+16 -10
View File
@@ -219,10 +219,15 @@ bootstrap_legacy_routes() {
switch_gateway_proxy() {
[ "$SERVICE" = "gateway" ] || [ "$SERVICE" = "gateway-overseas" ] || return 0
if [ "$SERVICE" = "gateway" ]; then required_alias=gateway-active; else required_alias=gateway-overseas-active; fi
for frontend in firstleg-prod-admin-web-blue firstleg-prod-admin-web-green \
firstleg-prod-client-web-blue firstleg-prod-client-web-green; do
if docker inspect "$frontend" >/dev/null 2>&1 \
&& ! docker exec "$frontend" nginx -T 2>&1 | grep -q "$required_alias"; then
for frontend_service in admin-web client-web; do
frontend_state="$STATE_ROOT/frontend-$frontend_service.active"
if [ ! -s "$frontend_state" ]; then
echo "$frontend_service 尚未完成首次蓝绿迁移,拒绝切换 Gateway" >&2
return 1
fi
IFS='|' read -r frontend_slot frontend frontend_port frontend_image < "$frontend_state"
if ! docker inspect "$frontend" >/dev/null 2>&1 \
|| ! docker exec "$frontend" nginx -T 2>&1 | grep -q "$required_alias"; then
echo "$frontend 尚未使用稳定上游 $required_alias,拒绝切换 Gateway" >&2
return 1
fi
@@ -256,12 +261,13 @@ switch_gateway_proxy() {
reload_frontend_proxies() {
[ "$SERVICE" = "gateway" ] || [ "$SERVICE" = "gateway-overseas" ] || return 0
for frontend in firstleg-prod-admin-web-blue firstleg-prod-admin-web-green \
firstleg-prod-client-web-blue firstleg-prod-client-web-green; do
if docker inspect "$frontend" >/dev/null 2>&1; then
docker exec "$frontend" nginx -t
docker exec "$frontend" nginx -s reload
fi
for frontend_service in admin-web client-web; do
frontend_state="$STATE_ROOT/frontend-$frontend_service.active"
[ -s "$frontend_state" ] || return 1
IFS='|' read -r frontend_slot frontend frontend_port frontend_image < "$frontend_state"
docker inspect "$frontend" >/dev/null 2>&1 || return 1
docker exec "$frontend" nginx -t
docker exec "$frontend" nginx -s reload
done
}
@@ -43,6 +43,8 @@ test('gateway cutover is atomic and restores nginx config on validation failure'
const script = await read('deploy/scripts/deploy-blue-green-service.sh')
assert.match(script, /api-cn\.buggoglobal\.com\.conf/)
assert.match(script, /api-global\.buggoglobal\.com\.conf/)
assert.match(script, /尚未完成首次蓝绿迁移,拒绝切换 Gateway/)
assert.match(script, /frontend-\$frontend_service\.active/)
assert.match(script, /尚未使用稳定上游 \$required_alias,拒绝切换 Gateway/)
assert.match(script, /reload_frontend_proxies/)
assert.match(script, /cp -f "\$config" "\$backup"/)