fix: harden blue-green routing and gateway migration
This commit is contained in:
@@ -219,10 +219,15 @@ bootstrap_legacy_routes() {
|
|||||||
switch_gateway_proxy() {
|
switch_gateway_proxy() {
|
||||||
[ "$SERVICE" = "gateway" ] || [ "$SERVICE" = "gateway-overseas" ] || return 0
|
[ "$SERVICE" = "gateway" ] || [ "$SERVICE" = "gateway-overseas" ] || return 0
|
||||||
if [ "$SERVICE" = "gateway" ]; then required_alias=gateway-active; else required_alias=gateway-overseas-active; fi
|
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 \
|
for frontend_service in admin-web client-web; do
|
||||||
firstleg-prod-client-web-blue firstleg-prod-client-web-green; do
|
frontend_state="$STATE_ROOT/frontend-$frontend_service.active"
|
||||||
if docker inspect "$frontend" >/dev/null 2>&1 \
|
if [ ! -s "$frontend_state" ]; then
|
||||||
&& ! docker exec "$frontend" nginx -T 2>&1 | grep -q "$required_alias"; 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
|
echo "$frontend 尚未使用稳定上游 $required_alias,拒绝切换 Gateway" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -256,12 +261,13 @@ switch_gateway_proxy() {
|
|||||||
|
|
||||||
reload_frontend_proxies() {
|
reload_frontend_proxies() {
|
||||||
[ "$SERVICE" = "gateway" ] || [ "$SERVICE" = "gateway-overseas" ] || return 0
|
[ "$SERVICE" = "gateway" ] || [ "$SERVICE" = "gateway-overseas" ] || return 0
|
||||||
for frontend in firstleg-prod-admin-web-blue firstleg-prod-admin-web-green \
|
for frontend_service in admin-web client-web; do
|
||||||
firstleg-prod-client-web-blue firstleg-prod-client-web-green; do
|
frontend_state="$STATE_ROOT/frontend-$frontend_service.active"
|
||||||
if docker inspect "$frontend" >/dev/null 2>&1; then
|
[ -s "$frontend_state" ] || return 1
|
||||||
docker exec "$frontend" nginx -t
|
IFS='|' read -r frontend_slot frontend frontend_port frontend_image < "$frontend_state"
|
||||||
docker exec "$frontend" nginx -s reload
|
docker inspect "$frontend" >/dev/null 2>&1 || return 1
|
||||||
fi
|
docker exec "$frontend" nginx -t
|
||||||
|
docker exec "$frontend" nginx -s reload
|
||||||
done
|
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')
|
const script = await read('deploy/scripts/deploy-blue-green-service.sh')
|
||||||
assert.match(script, /api-cn\.buggoglobal\.com\.conf/)
|
assert.match(script, /api-cn\.buggoglobal\.com\.conf/)
|
||||||
assert.match(script, /api-global\.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, /尚未使用稳定上游 \$required_alias,拒绝切换 Gateway/)
|
||||||
assert.match(script, /reload_frontend_proxies/)
|
assert.match(script, /reload_frontend_proxies/)
|
||||||
assert.match(script, /cp -f "\$config" "\$backup"/)
|
assert.match(script, /cp -f "\$config" "\$backup"/)
|
||||||
|
|||||||
Reference in New Issue
Block a user