fix: keep BaoTa reverse proxies on stable ports

This commit is contained in:
2026-09-20 23:39:39 +08:00
parent c1983d47a5
commit 2f0b421131
2 changed files with 11 additions and 11 deletions
+7 -9
View File
@@ -96,7 +96,7 @@ else
fi fi
if [ "$target_slot" = "blue" ]; then if [ "$target_slot" = "blue" ]; then
target_port="$BASE_PORT" target_port=$((BASE_PORT + 20000))
else else
target_port=$((BASE_PORT + 10000)) target_port=$((BASE_PORT + 10000))
fi fi
@@ -242,12 +242,11 @@ switch_gateway_proxy() {
return 1 return 1
fi fi
done done
route_root="${BLUE_GREEN_ROUTE_CONFIG_ROOT:-/www/server/panel/vhost/nginx}"
if [ "$SERVICE" = "gateway" ]; then if [ "$SERVICE" = "gateway" ]; then
config="$(env_value GATEWAY_BLUE_GREEN_NGINX_CONFIG)" config="$route_root/00-blue-green-gateway.conf"
config="${config:-/www/server/panel/vhost/nginx/api-cn.buggoglobal.com.conf}"
else else
config="$(env_value GATEWAY_OVERSEAS_BLUE_GREEN_NGINX_CONFIG)" config="$route_root/00-blue-green-gateway-overseas.conf"
config="${config:-/www/server/panel/vhost/nginx/api-global.buggoglobal.com.conf}"
fi fi
if [ -z "$config" ] || [ ! -f "$config" ]; then if [ -z "$config" ] || [ ! -f "$config" ]; then
echo "$SERVICE 蓝绿切换要求环境文件配置有效的 Nginx 配置路径" >&2 echo "$SERVICE 蓝绿切换要求环境文件配置有效的 Nginx 配置路径" >&2
@@ -285,12 +284,11 @@ reload_frontend_proxies() {
rollback_gateway_proxy() { rollback_gateway_proxy() {
[ "$SERVICE" = "gateway" ] || [ "$SERVICE" = "gateway-overseas" ] || return 0 [ "$SERVICE" = "gateway" ] || [ "$SERVICE" = "gateway-overseas" ] || return 0
[ "$DEPLOY_ENV" = production ] || return 0 [ "$DEPLOY_ENV" = production ] || return 0
route_root="${BLUE_GREEN_ROUTE_CONFIG_ROOT:-/www/server/panel/vhost/nginx}"
if [ "$SERVICE" = "gateway" ]; then if [ "$SERVICE" = "gateway" ]; then
config="$(env_value GATEWAY_BLUE_GREEN_NGINX_CONFIG)" config="$route_root/00-blue-green-gateway.conf"
config="${config:-/www/server/panel/vhost/nginx/api-cn.buggoglobal.com.conf}"
else else
config="$(env_value GATEWAY_OVERSEAS_BLUE_GREEN_NGINX_CONFIG)" config="$route_root/00-blue-green-gateway-overseas.conf"
config="${config:-/www/server/panel/vhost/nginx/api-global.buggoglobal.com.conf}"
fi fi
old_port="${active_port:-$BASE_PORT}" old_port="${active_port:-$BASE_PORT}"
sed -i "s#127\.0\.0\.1:$target_port#127.0.0.1:$old_port#g" "$config" sed -i "s#127\.0\.0\.1:$target_port#127.0.0.1:$old_port#g" "$config"
@@ -14,6 +14,7 @@ test('all backend business services have blue-green runtime contracts', async ()
]) assert.match(script, new RegExp(`${service.replaceAll('-', '\\-')}:`)) ]) assert.match(script, new RegExp(`${service.replaceAll('-', '\\-')}:`))
assert.match(script, /target_slot="green"/) assert.match(script, /target_slot="green"/)
assert.match(script, /target_port=\$\(\(BASE_PORT \+ 20000\)\)/)
assert.match(script, /target_port=\$\(\(BASE_PORT \+ 10000\)\)/) assert.match(script, /target_port=\$\(\(BASE_PORT \+ 10000\)\)/)
assert.match(script, /compose run -d --no-deps --name "\$candidate"/) assert.match(script, /compose run -d --no-deps --name "\$candidate"/)
assert.match(script, /wait_for_container "\$candidate"/) assert.match(script, /wait_for_container "\$candidate"/)
@@ -43,8 +44,9 @@ test('candidate failure keeps the active container and successful cutover stops
test('gateway cutover is atomic and restores nginx config on validation failure', async () => { test('gateway cutover is atomic and restores nginx config on validation failure', async () => {
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, /00-blue-green-gateway\.conf/)
assert.match(script, /api-global\.buggoglobal\.com\.conf/) assert.match(script, /00-blue-green-gateway-overseas\.conf/)
assert.doesNotMatch(script, /api-cn\.buggoglobal\.com\.conf|api-global\.buggoglobal\.com\.conf/)
assert.match(script, /尚未完成首次蓝绿迁移,拒绝切换 Gateway/) assert.match(script, /尚未完成首次蓝绿迁移,拒绝切换 Gateway/)
assert.match(script, /frontend-\$frontend_service\.active/) assert.match(script, /frontend-\$frontend_service\.active/)
assert.match(script, /尚未使用稳定上游 \$required_alias,拒绝切换 Gateway/) assert.match(script, /尚未使用稳定上游 \$required_alias,拒绝切换 Gateway/)