Skip to content

Commit de2849a

Browse files
committed
feat: Add ai-proxy config template support to the AiO image
1 parent 7601765 commit de2849a

File tree

5 files changed

+253
-4
lines changed

5 files changed

+253
-4
lines changed

Diff for: all-in-one/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ COPY ./supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
5151
# Initialize configurations
5252
COPY ./meshConfig /etc/istio/config
5353
COPY ./gateway/podinfo /etc/istio/pod
54-
COPY ./scripts/*.* /usr/local/bin
54+
COPY ./scripts /usr/local/bin
5555
COPY ./apiserver/config /app/kubeconfig
5656
COPY ./config /opt/data/defaultConfig
5757

Diff for: all-in-one/config/mcpbridges/default.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ metadata:
77
resourceVersion: "1"
88
spec:
99
registries:
10-
- domain: 127.0.0.1:8080
10+
- domain: 127.0.0.1:8001
1111
name: higress-console
1212
port: 80
1313
type: static
14+
# INSERTION_POINT
1415
status: {}

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

+238
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
#!/bin/bash
2+
3+
AZ_PROXY_VERSION=${AI_PROXY_VERSION:-0.0.1}
4+
5+
if [ -n "$AZURE_OPENAI_SERVICE_URL" ]; then
6+
AZURE_OPENAI_SERVICE_DOMAIN=$(echo "$AZURE_OPENAI_SERVICE_URL" | awk -F[/:] '{print $4}')
7+
else
8+
AZURE_OPENAI_SERVICE_DOMAIN="YOUR_RESOURCE_NAME.openai.azure.com"
9+
fi
10+
11+
function initializeWasmPlugins() {
12+
mkdir -p /data/wasmplugins
13+
WASM_PLUGIN_CONFIG_FILE="/data/wasmplugins/ai-proxy-$AZ_PROXY_VERSION.yaml"
14+
15+
if [ -f "$WASM_PLUGIN_CONFIG_FILE" ]; then
16+
return
17+
fi
18+
19+
cat <<EOF > "$WASM_PLUGIN_CONFIG_FILE"
20+
apiVersion: extensions.higress.io/v1alpha1
21+
kind: WasmPlugin
22+
metadata:
23+
annotations:
24+
higress.io/wasm-plugin-title: AI Proxy
25+
labels:
26+
higress.io/resource-definer: higress
27+
higress.io/wasm-plugin-built-in: "false"
28+
higress.io/wasm-plugin-category: custom
29+
higress.io/wasm-plugin-name: ai-proxy
30+
higress.io/wasm-plugin-version: $AZ_PROXY_VERSION
31+
name: ai-proxy-$AZ_PROXY_VERSION
32+
namespace: higress-system
33+
spec:
34+
defaultConfig: {}
35+
defaultConfigDisable: true
36+
matchRules:
37+
- config:
38+
provider:
39+
type: qwen
40+
apiToken: "${DASHSCOPE_API_KEY:-YOUR_DASHSCOPE_API_KEY}"
41+
modelMapping:
42+
'*': "qwen-turbo"
43+
'gpt-3': "qwen-turbo"
44+
'gpt-35-turbo': "qwen-plus"
45+
'gpt-4-turbo': "qwen-max"
46+
configDisable: false
47+
ingress:
48+
- qwen
49+
- config:
50+
provider:
51+
type: azure
52+
apiToken: "${AZURE_OPENAI_API_KEY:-YOUR_AZURE_OPENAI_API_KEY}"
53+
azureServiceUrl: "${AZURE_OPENAI_SERVICE_URL:-https://YOUR_RESOURCE_NAME.openai.azure.com/openai/deployments/YOUR_DEPLOYMENT_NAME/chat/completions?api-version=2024-02-01}"
54+
configDisable: false
55+
ingress:
56+
- azure-openai
57+
- config:
58+
provider:
59+
type: openai
60+
apiToken: "${OPENAI_API_KEY:-YOUR_OPENAI_API_KEY}"
61+
configDisable: false
62+
ingress:
63+
- openai
64+
- config:
65+
provider:
66+
type: moonshot
67+
apiToken: "${MOONSHOT_API_KEY:-YOUR_MOONSHOT_API_KEY}"
68+
modelMapping:
69+
'*': "moonshot-v1-8k"
70+
'gpt-3': "moonshot-v1-8k"
71+
'gpt-35-turbo': "moonshot-v1-32k"
72+
'gpt-4-turbo': "moonshot-v1-128k"
73+
configDisable: false
74+
ingress:
75+
- moonshot
76+
phase: UNSPECIFIED_PHASE
77+
priority: "100"
78+
#url: oci://higress-registry.cn-hangzhou.cr.aliyuncs.com/plugins/ai-proxy:$AZ_PROXY_VERSION
79+
url: oci://docker.io/ch3cho/ai-proxy:$AZ_PROXY_VERSION
80+
EOF
81+
}
82+
83+
function initializeMcpBridge() {
84+
read -r -d '' AI_REGISTRIES <<EOF
85+
- domain: api.moonshot.cn
86+
name: moonshot
87+
port: 443
88+
type: dns
89+
- domain: $AZURE_OPENAI_SERVICE_DOMAIN
90+
name: azure-openai
91+
port: 443
92+
type: dns
93+
- domain: dashscope.aliyuncs.com
94+
name: qwen
95+
port: 443
96+
type: dns
97+
- domain: api.openai.com
98+
name: openai
99+
port: 443
100+
type: dns
101+
EOF
102+
cd /data/mcpbridges
103+
awk -v r="$AI_REGISTRIES" '{gsub(/# INSERTION_POINT/,r)}1' default.yaml > default-new.yaml
104+
mv default-new.yaml default.yaml
105+
cd -
106+
}
107+
108+
function initializeIngresses() {
109+
mkdir -p /data/ingresses
110+
111+
if [ ! -f /data/ingresses/qwen.yaml ]; then
112+
cat <<EOF > /data/ingresses/qwen.yaml
113+
apiVersion: networking.k8s.io/v1
114+
kind: Ingress
115+
metadata:
116+
annotations:
117+
higress.io/backend-protocol: HTTPS
118+
higress.io/destination: qwen.dns
119+
higress.io/exact-match-header-Authorization: Bearer qwen
120+
higress.io/ignore-path-case: "false"
121+
higress.io/proxy-ssl-name: dashscope.aliyuncs.com
122+
higress.io/proxy-ssl-server-name: "on"
123+
labels:
124+
higress.io/resource-definer: higress
125+
name: qwen
126+
namespace: higress-system
127+
spec:
128+
ingressClassName: higress
129+
rules:
130+
- http:
131+
paths:
132+
- backend:
133+
resource:
134+
apiGroup: networking.higress.io
135+
kind: McpBridge
136+
name: default
137+
path: /
138+
pathType: Prefix
139+
EOF
140+
fi
141+
142+
if [ ! -f /data/ingresses/moonshot.yaml ]; then
143+
cat <<EOF > /data/ingresses/moonshot.yaml
144+
apiVersion: networking.k8s.io/v1
145+
kind: Ingress
146+
metadata:
147+
annotations:
148+
higress.io/backend-protocol: HTTPS
149+
higress.io/destination: moonshot.dns
150+
higress.io/exact-match-header-Authorization: Bearer moonshot
151+
higress.io/ignore-path-case: "false"
152+
higress.io/proxy-ssl-name: api.moonshot.cn
153+
higress.io/proxy-ssl-server-name: "on"
154+
labels:
155+
higress.io/resource-definer: higress
156+
name: moonshot
157+
namespace: higress-system
158+
spec:
159+
ingressClassName: higress
160+
rules:
161+
- http:
162+
paths:
163+
- backend:
164+
resource:
165+
apiGroup: networking.higress.io
166+
kind: McpBridge
167+
name: default
168+
path: /
169+
pathType: Prefix
170+
EOF
171+
fi
172+
173+
if [ ! -f /data/ingresses/azure-openai.yaml ]; then
174+
cat <<EOF > /data/ingresses/azure-openai.yaml
175+
apiVersion: networking.k8s.io/v1
176+
kind: Ingress
177+
metadata:
178+
annotations:
179+
higress.io/backend-protocol: HTTPS
180+
higress.io/destination: azure-openai.dns
181+
higress.io/exact-match-header-Authorization: Bearer azure-openai
182+
higress.io/ignore-path-case: "false"
183+
higress.io/proxy-ssl-name: $AZURE_OPENAI_SERVICE_DOMAIN
184+
higress.io/proxy-ssl-server-name: "on"
185+
labels:
186+
higress.io/resource-definer: higress
187+
name: azure-openai
188+
namespace: higress-system
189+
spec:
190+
ingressClassName: higress
191+
rules:
192+
- http:
193+
paths:
194+
- backend:
195+
resource:
196+
apiGroup: networking.higress.io
197+
kind: McpBridge
198+
name: default
199+
path: /
200+
pathType: Prefix
201+
EOF
202+
fi
203+
204+
if [ ! -f /data/ingresses/openai.yaml ]; then
205+
cat <<EOF > /data/ingresses/openai.yaml
206+
apiVersion: networking.k8s.io/v1
207+
kind: Ingress
208+
metadata:
209+
annotations:
210+
higress.io/backend-protocol: HTTPS
211+
higress.io/destination: openai.dns
212+
higress.io/exact-match-header-Authorization: Bearer openai
213+
higress.io/ignore-path-case: "false"
214+
higress.io/proxy-ssl-name: api.openai.com
215+
higress.io/proxy-ssl-server-name: "on"
216+
labels:
217+
higress.io/resource-definer: higress
218+
name: openai
219+
namespace: higress-system
220+
spec:
221+
ingressClassName: higress
222+
rules:
223+
- http:
224+
paths:
225+
- backend:
226+
resource:
227+
apiGroup: networking.higress.io
228+
kind: McpBridge
229+
name: default
230+
path: /
231+
pathType: Prefix
232+
EOF
233+
fi
234+
}
235+
236+
initializeWasmPlugins
237+
initializeMcpBridge
238+
initializeIngresses

Diff for: all-in-one/scripts/start-apiserver.sh

+10
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,14 @@ if [ "$ENABLE_CONSOLE_ROUTE" != "1" ]; then
1212
fi
1313
cp -rn /opt/data/defaultConfig/* /data
1414

15+
if [ -n "$CONFIG_TEMPLATE" ]; then
16+
TEMPLATE_SCRIPT="$ROOT/config-template/$CONFIG_TEMPLATE.sh"
17+
if [ -f "$TEMPLATE_SCRIPT" ]; then
18+
/bin/bash "$TEMPLATE_SCRIPT"
19+
else
20+
echo "Unknown config template: $CONFIG_TEMPLATE"
21+
exit 1
22+
fi
23+
fi
24+
1525
apiserver --bind-address 127.0.0.1 --secure-port 18443 --storage file --file-root-dir /data --cert-dir /tmp

Diff for: all-in-one/scripts/start-gateway.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ createDir /var/lib/istio/data
2020

2121
/usr/local/bin/pilot-agent proxy router \
2222
--domain=higress-system.svc.cluster.local \
23-
--proxyLogLevel=warning \
24-
--proxyComponentLogLevel=misc:error \
23+
--proxyLogLevel=${GATEWAY_LOG_LEVEL:-warning} \
24+
--proxyComponentLogLevel=${GATEWAY_COMPONENT_LOG_LEVEL:-misc:error} \
2525
--log_output_level=all:info \
2626
--serviceCluster=higress-gateway

0 commit comments

Comments
 (0)