Skip to content

Commit 844fadd

Browse files
committed
feat: auto-select plugin registry based on timezone
Auto-detect timezone and select the geographically closest plugin registry for faster plugin downloads. Changes: 1. Add detectPluginRegistry() function to auto-select registry: - Asia/Shanghai & China → Hangzhou mirror - Southeast Asia → Singapore mirror - Americas → North America mirror - Default → Hangzhou mirror 2. Add PLUGIN_REGISTRY to config file generation 3. Update plugin templates to use PLUGIN_REGISTRY variable: - scripts/config-template/ai-gateway.sh (ai-proxy, ai-statistics, model-router) - scripts/config-template/ai-proxy.sh 4. Support manual override via PLUGIN_REGISTRY environment variable Available registries: - higress-registry.cn-hangzhou.cr.aliyuncs.com (default) - higress-registry.ap-southeast-7.cr.aliyuncs.com (Southeast Asia) - higress-registry.us-west-1.cr.aliyuncs.com (North America)
1 parent 25bb17d commit 844fadd

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

all-in-one/get-ai-gateway.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fi
2727

2828
DEFAULT_CONTAINER_NAME=higress-ai-gateway
2929
DEFAULT_IMAGE_REPO=higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/all-in-one
30+
DEFAULT_PLUGIN_REGISTRY=higress-registry.cn-hangzhou.cr.aliyuncs.com
3031
DEFAULT_IMAGE_TAG=latest
3132
DEFAULT_GATEWAY_HTTP_PORT=8080
3233
DEFAULT_GATEWAY_HTTPS_PORT=8443
@@ -86,6 +87,45 @@ initOS() {
8687
esac
8788
}
8889

90+
# Auto-detect timezone and select optimal plugin registry
91+
detectPluginRegistry() {
92+
if [ -n "$PLUGIN_REGISTRY" ]; then
93+
# User explicitly set PLUGIN_REGISTRY, use it
94+
return
95+
fi
96+
97+
# Try to detect timezone
98+
local TZ=""
99+
if command -v timedatectl &>/dev/null; then
100+
TZ=$(timedatectl show --property=Timezone --value 2>/dev/null)
101+
elif [ -f /etc/timezone ]; then
102+
TZ=$(cat /etc/timezone 2>/dev/null)
103+
fi
104+
105+
# Select registry based on timezone
106+
case "$TZ" in
107+
Asia/Shanghai|Asia/Hong_Kong|Asia/Taipei|Asia/Chongqing|Asia/Urumqi|Asia/Harbin)
108+
# China and nearby regions
109+
PLUGIN_REGISTRY="higress-registry.cn-hangzhou.cr.aliyuncs.com"
110+
;;
111+
Asia/Singapore|Asia/Jakarta|Asia/Bangkok|Asia/Kuala_Lumpur|Asia/Manila|Asia/Ho_Chi_Minh)
112+
# Southeast Asia
113+
PLUGIN_REGISTRY="higress-registry.ap-southeast-7.cr.aliyuncs.com"
114+
;;
115+
America/*|US/*|Canada/*)
116+
# North America
117+
PLUGIN_REGISTRY="higress-registry.us-west-1.cr.aliyuncs.com"
118+
;;
119+
*)
120+
# Default to Hangzhou for other regions
121+
PLUGIN_REGISTRY="$DEFAULT_PLUGIN_REGISTRY"
122+
;;
123+
esac
124+
125+
echo "Auto-detected timezone: $TZ"
126+
echo "Selected plugin registry: $PLUGIN_REGISTRY"
127+
}
128+
89129
normalizePath() {
90130
if [ "$OS" != "windows" ]; then
91131
echo "$1"
@@ -524,6 +564,10 @@ resetEnv() {
524564

525565
IMAGE_REPO="${IMAGE_REPO:-$DEFAULT_IMAGE_REPO}"
526566
IMAGE_TAG="${IMAGE_TAG:-$DEFAULT_IMAGE_TAG}"
567+
568+
# Detect and set plugin registry if not already set
569+
detectPluginRegistry
570+
PLUGIN_REGISTRY="${PLUGIN_REGISTRY:-$DEFAULT_PLUGIN_REGISTRY}"
527571

528572
GATEWAY_HTTP_PORT="${GATEWAY_HTTP_PORT:-$DEFAULT_GATEWAY_HTTP_PORT}"
529573
GATEWAY_HTTPS_PORT="${GATEWAY_HTTPS_PORT:-$DEFAULT_GATEWAY_HTTPS_PORT}"
@@ -1318,6 +1362,7 @@ CONFIG_TEMPLATE=ai-gateway
13181362
GATEWAY_HTTP_PORT=${GATEWAY_HTTP_PORT}
13191363
GATEWAY_HTTPS_PORT=${GATEWAY_HTTPS_PORT}
13201364
CONSOLE_PORT=${CONSOLE_PORT}
1365+
PLUGIN_REGISTRY=${PLUGIN_REGISTRY}
13211366
${LLM_CONFIGS}${AUTO_ROUTING_CONFIG}
13221367
EOF
13231368
}

all-in-one/scripts/config-template/ai-gateway.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ spec:
385385
failStrategy: FAIL_OPEN
386386
phase: UNSPECIFIED_PHASE
387387
priority: 100
388-
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-proxy:2.0.0" >"$WASM_PLUGIN_CONFIG_FOLDER/ai-proxy.internal.yaml"
388+
url: oci://${PLUGIN_REGISTRY:-higress-registry.cn-hangzhou.cr.aliyuncs.com}/plugins/ai-proxy:2.0.0" >"$WASM_PLUGIN_CONFIG_FOLDER/ai-proxy.internal.yaml"
389389

390390
echo -e "\
391391
apiVersion: extensions.higress.io/v1alpha1
@@ -409,7 +409,7 @@ spec:
409409
failStrategy: FAIL_OPEN
410410
phase: UNSPECIFIED_PHASE
411411
priority: 900
412-
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-statistics:2.0.0" >"$WASM_PLUGIN_CONFIG_FOLDER/ai-statistics-1.0.0.yaml"
412+
url: oci://${PLUGIN_REGISTRY:-higress-registry.cn-hangzhou.cr.aliyuncs.com}/plugins/ai-statistics:2.0.0" >"$WASM_PLUGIN_CONFIG_FOLDER/ai-statistics-1.0.0.yaml"
413413

414414
echo -e "\
415415
apiVersion: extensions.higress.io/v1alpha1
@@ -433,7 +433,7 @@ spec:
433433
failStrategy: FAIL_OPEN
434434
phase: AUTHN
435435
priority: 900
436-
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/model-router:2.0.0" >"$WASM_PLUGIN_CONFIG_FOLDER/model-router.internal.yaml"
436+
url: oci://${PLUGIN_REGISTRY:-higress-registry.cn-hangzhou.cr.aliyuncs.com}/plugins/model-router:2.0.0" >"$WASM_PLUGIN_CONFIG_FOLDER/model-router.internal.yaml"
437437
}
438438

439439
function appendAiProxyConfigs() {

all-in-one/scripts/config-template/ai-proxy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ spec:
125125
failStrategy: FAIL_OPEN
126126
phase: UNSPECIFIED_PHASE
127127
priority: \"100\"
128-
url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-proxy:2.0.0" > "$WASM_PLUGIN_CONFIG_FILE"
128+
url: oci://${PLUGIN_REGISTRY:-higress-registry.cn-hangzhou.cr.aliyuncs.com}/plugins/ai-proxy:2.0.0" > "$WASM_PLUGIN_CONFIG_FILE"
129129
}
130130

131131
function initializeMcpBridge() {

0 commit comments

Comments
 (0)