feat(release): add reversible production cutover gates

This commit is contained in:
chick
2026-07-18 17:24:51 +08:00
parent 3718c91706
commit 4a7e29cf06
18 changed files with 1468 additions and 8 deletions
+4 -1
View File
@@ -18,6 +18,7 @@ export const CANARY_DEFAULT_UPSTREAM_HOST = '127.0.0.1';
export const CANARY_DEFAULT_UPSTREAM_PORT = 8790;
const RESERVED_PORTS = new Set([8788, 8790]);
export const PRODUCTION_GATEWAY_PORT = 8788;
const BASE_HOP_BY_HOP_HEADERS = new Set([
'connection',
'keep-alive',
@@ -62,6 +63,8 @@ export interface CanaryGatewayOptions {
readonly port?: number;
readonly upstreamHost?: string;
readonly upstreamPort?: number;
/** Set only after the production runtime validates its explicit acknowledgement. */
readonly ownsProductionPort?: boolean;
}
export interface CanaryGateway {
@@ -201,7 +204,7 @@ export function createCanaryGateway(options: CanaryGatewayOptions): CanaryGatewa
throw new Error('Canary upstream must use a loopback host');
}
if (!Number.isInteger(port) || port < 0 || port > 65_535) throw new Error('Invalid canary port');
if (RESERVED_PORTS.has(port))
if (RESERVED_PORTS.has(port) && !(port === PRODUCTION_GATEWAY_PORT && options.ownsProductionPort))
throw new Error(`Port ${port} is reserved and cannot run the canary`);
if (!options.distDir) throw new Error('distDir is required');