diff --git a/deploy/chart/authhub/templates/backend/authhub-backend.yaml b/deploy/chart/authhub/templates/backend/authhub-backend.yaml index 4a19b4ad4938610de83801b4aa10d9e5c89b4f1e..54884d24bb57fa480fd2ef438ef81c41da37b073 100644 --- a/deploy/chart/authhub/templates/backend/authhub-backend.yaml +++ b/deploy/chart/authhub/templates/backend/authhub-backend.yaml @@ -37,7 +37,7 @@ spec: automountServiceAccountToken: false containers: - name: authhub-backend - image: {{ if .Values.authhub.backend.image }}{{ .Values.authhub.backend.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/authhub:0.9.3-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.authhub.backend.image | default (printf "%s/neocopilot/authhub:0.9.3-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} ports: - containerPort: 11120 @@ -61,7 +61,7 @@ spec: {{ toYaml .Values.authhub.backend.resourceLimits | nindent 14 }} initContainers: - name: authhub-backend-copy-secret - image: {{ if .Values.authhub.secret_inject.image }}{{ .Values.authhub.secret_inject.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/secret_inject:dev-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.authhub.secret_inject.image | default (printf "%s/neocopilot/secret_inject:dev-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} volumeMounts: - mountPath: /secrets/mysql-password diff --git a/deploy/chart/authhub/templates/mysql/mysql.yaml b/deploy/chart/authhub/templates/mysql/mysql.yaml index 6ff304051297cc27efa39213963a721738609a49..f9fdc318b3f7772499398acc42be914b1f36cdf7 100644 --- a/deploy/chart/authhub/templates/mysql/mysql.yaml +++ b/deploy/chart/authhub/templates/mysql/mysql.yaml @@ -37,7 +37,7 @@ spec: automountServiceAccountToken: false containers: - name: mysql - image: {{ if .Values.authhub.mysql.image }}{{ .Values.authhub.mysql.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/mysql:8-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.authhub.mysql.image | default (printf "%s/neocopilot/mysql:8-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} args: - "--character-set-server=utf8mb4" diff --git a/deploy/chart/authhub/templates/web/authhub-web.yaml b/deploy/chart/authhub/templates/web/authhub-web.yaml index 66d9e689ffbb37a481bec3e0b9de41c49298abf5..05ca0315eff485ae70dfa64bb1347f19913fefce 100644 --- a/deploy/chart/authhub/templates/web/authhub-web.yaml +++ b/deploy/chart/authhub/templates/web/authhub-web.yaml @@ -56,7 +56,7 @@ spec: automountServiceAccountToken: false containers: - name: authhub-web - image: {{ if .Values.authhub.web.image }}{{ .Values.authhub.web.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/authhub-web:0.9.3-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.authhub.web.image | default (printf "%s/neocopilot/authhub-web:0.9.3-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} ports: - containerPort: 8000 diff --git a/deploy/chart/databases/templates/minio/minio.yaml b/deploy/chart/databases/templates/minio/minio.yaml index 767d4daa27aa234519c2b7f7cdab789e085d4098..fd2fdc80db66d253cadc239d0e095f9805014408 100644 --- a/deploy/chart/databases/templates/minio/minio.yaml +++ b/deploy/chart/databases/templates/minio/minio.yaml @@ -59,7 +59,7 @@ spec: automountServiceAccountToken: false containers: - name: minio - image: {{ if .Values.databases.minio.image }}{{ .Values.databases.minio.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/minio:empty-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.databases.minio.image | default (printf "%s/neocopilot/minio:empty-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} args: - "server" diff --git a/deploy/chart/databases/templates/mongo/mongo.yaml b/deploy/chart/databases/templates/mongo/mongo.yaml index 93d2b256222ab07e4d61337cad4bf8ffa17574e9..ec5774b6b7fca848746da47d1ab0e93c93340295 100644 --- a/deploy/chart/databases/templates/mongo/mongo.yaml +++ b/deploy/chart/databases/templates/mongo/mongo.yaml @@ -37,7 +37,7 @@ spec: automountServiceAccountToken: false containers: - name: mongo - image: {{ if .Values.databases.mongo.image }}{{ .Values.databases.mongo.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/mongo:7.0.16-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.databases.mongo.image | default (printf "%s/neocopilot/mongo:7.0.16-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} command: - bash diff --git a/deploy/chart/databases/templates/pgsql/pgsql.yaml b/deploy/chart/databases/templates/pgsql/pgsql.yaml index 791e7975831e405126a36a1b17a19dd31332f966..3fa5eb482aeb0dfadf7af1fbcd1396121a2177b8 100644 --- a/deploy/chart/databases/templates/pgsql/pgsql.yaml +++ b/deploy/chart/databases/templates/pgsql/pgsql.yaml @@ -37,7 +37,7 @@ spec: automountServiceAccountToken: false containers: - name: pgsql - image: {{ if .Values.databases.pgsql.image }}{{ .Values.databases.pgsql.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/pgsql-empty:pg16-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.databases.pgsql.image | default (printf "%s/neocopilot/pgsql-empty:pg16-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} ports: - containerPort: 5432 diff --git a/deploy/chart/databases/templates/redis/redis.yaml b/deploy/chart/databases/templates/redis/redis.yaml index 6b269a6c7ef9991e54000748f8562a15048ac0eb..c9e4d6afca4c93d1bd048397bb2c1fd6a88ed3ea 100644 --- a/deploy/chart/databases/templates/redis/redis.yaml +++ b/deploy/chart/databases/templates/redis/redis.yaml @@ -35,7 +35,7 @@ spec: automountServiceAccountToken: false containers: - name: redis - image: {{ if .Values.databases.redis.image }}{{ .Values.databases.redis.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/redis:7.4-alpine-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.databases.redis.image | default (printf "%s/neocopilot/redis:7.4-alpine-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} command: - redis-server diff --git a/deploy/chart/euler_copilot/templates/framework/framework.yaml b/deploy/chart/euler_copilot/templates/framework/framework.yaml index 33f1862843078ce0945dd55f3ca82826ce69d8de..d5687123df2993963c8415b0e894daece5956e95 100644 --- a/deploy/chart/euler_copilot/templates/framework/framework.yaml +++ b/deploy/chart/euler_copilot/templates/framework/framework.yaml @@ -38,7 +38,7 @@ spec: fsGroup: 1001 containers: - name: framework - image: {{ if .Values.euler_copilot.framework.image }}{{ .Values.euler_copilot.framework.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/euler-copilot-framework:0.9.4-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.euler_copilot.framework.image | default (printf "%s/neocopilot/euler-copilot-framework:0.9.4-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} ports: - containerPort: 8002 @@ -80,7 +80,7 @@ spec: {{ toYaml .Values.euler_copilot.framework.resourceLimits | nindent 14 }} initContainers: - name: framework-copy - image: {{ if .Values.euler_copilot.secret_inject.image }}{{ .Values.euler_copilot.secret_inject.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/secret_inject:dev-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.euler_copilot.secret_inject.image | default (printf "%s/neocopilot/secret_inject:dev-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} volumeMounts: - mountPath: /config/.env diff --git a/deploy/chart/euler_copilot/templates/rag-web/rag-web.yaml b/deploy/chart/euler_copilot/templates/rag-web/rag-web.yaml index a067d48358230224f138a5d175e76e01bbcdad0f..7dcd40c5fa1ddbb678d4254bc7c8c06f8a399688 100644 --- a/deploy/chart/euler_copilot/templates/rag-web/rag-web.yaml +++ b/deploy/chart/euler_copilot/templates/rag-web/rag-web.yaml @@ -56,7 +56,7 @@ spec: automountServiceAccountToken: false containers: - name: rag-web - image: {{ if .Values.euler_copilot.rag_web.image }}{{ .Values.euler_copilot.rag_web.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/data_chain_web:0.9.4-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.euler_copilot.rag_web.image | default (printf "%s/neocopilot/data_chain_web:0.9.4-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} ports: - containerPort: 9888 diff --git a/deploy/chart/euler_copilot/templates/rag/rag.yaml b/deploy/chart/euler_copilot/templates/rag/rag.yaml index 756609215c99f9f313ac9f4c60df6fc6e393c703..75dbd6ada5b925f90ac612db56e42bc8788db283 100644 --- a/deploy/chart/euler_copilot/templates/rag/rag.yaml +++ b/deploy/chart/euler_copilot/templates/rag/rag.yaml @@ -37,7 +37,7 @@ spec: automountServiceAccountToken: false containers: - name: rag - image: {{ if .Values.euler_copilot.rag.image }}{{ .Values.euler_copilot.rag.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/data_chain_back_end:0.9.4-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.euler_copilot.rag.image | default (printf "%s/neocopilot/data_chain_back_end:0.9.4-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} ports: - containerPort: 9988 @@ -64,7 +64,7 @@ spec: {{ toYaml .Values.euler_copilot.rag.resourceLimits | nindent 14 }} initContainers: - name: rag-copy-secret - image: {{ if .Values.euler_copilot.secret_inject.image }}{{ .Values.euler_copilot.secret_inject.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/secret_inject:dev-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.euler_copilot.secret_inject.image | default (printf "%s/neocopilot/secret_inject:dev-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} volumeMounts: - mountPath: /config/.env diff --git a/deploy/chart/euler_copilot/templates/web/web.yaml b/deploy/chart/euler_copilot/templates/web/web.yaml index e02a99d7a762bf9fc8f5e4a80b479d84c0c76c75..d0dacc4fe51671f637ccd763982dcf8a82b8ac42 100644 --- a/deploy/chart/euler_copilot/templates/web/web.yaml +++ b/deploy/chart/euler_copilot/templates/web/web.yaml @@ -57,7 +57,7 @@ spec: fsGroup: 1001 containers: - name: web - image: {{ if .Values.euler_copilot.web.image }}{{ .Values.euler_copilot.web.image }}{{ else }}{{ .Values.globals.imageRegistry | default "hub.oepkgs.net" }}/neocopilot/euler-copilot-web:0.9.4-{{ .Values.globals.arch | default "x86" }}{{ end }} + image: {{ .Values.euler_copilot.web.image | default (printf "%s/neocopilot/euler-copilot-web:0.9.4-%s" (.Values.globals.imageRegistry | default "hub.oepkgs.net") (ternary "arm" "x86" (eq (.Values.globals.arch | default "x86") "arm"))) }} imagePullPolicy: {{ default "IfNotPresent" .Values.globals.imagePullPolicy }} ports: - containerPort: 8080 diff --git a/deploy/scripts/2-install-tools/install_tools.sh b/deploy/scripts/2-install-tools/install_tools.sh old mode 100644 new mode 100755 diff --git a/deploy/scripts/3-install-ollama/install_ollama.sh b/deploy/scripts/3-install-ollama/install_ollama.sh index 368a7adb82042d258580618af5594ed8d5eed661..0e0850d455c6e0c94186dff830dc41579b0ae3cc 100755 --- a/deploy/scripts/3-install-ollama/install_ollama.sh +++ b/deploy/scripts/3-install-ollama/install_ollama.sh @@ -202,7 +202,7 @@ After=network-online.target [Service] Environment="OLLAMA_MODELS=/var/lib/ollama/.ollama/models" -Environment=1"OLLAMA_HOST=0.0.0.0:11434" +Environment="OLLAMA_HOST=0.0.0.0:11434" ExecStart=$OLLAMA_BIN_PATH serve User=ollama Group=ollama diff --git a/deploy/scripts/7-install-authhub/install_authhub.sh b/deploy/scripts/7-install-authhub/install_authhub.sh old mode 100644 new mode 100755 index cc84122471fe445e0cbe3a5fd583c5ee249d6022..168ca64c8dfe00eca15a24df1caabbdcdbcea9b2 --- a/deploy/scripts/7-install-authhub/install_authhub.sh +++ b/deploy/scripts/7-install-authhub/install_authhub.sh @@ -1,6 +1,5 @@ #!/bin/bash - set -eo pipefail RED='\033[31m' @@ -26,7 +25,8 @@ get_architecture() { return 1 ;; esac - echo -e "${GREEN}检测到系统架构:$(uname -m)${NC}" + echo -e "${GREEN}检测到系统架构:$(uname -m)${NC}" >&2 + echo "$arch" } create_namespace() { @@ -61,9 +61,9 @@ delete_pvcs() { local pvc_name pvc_name=$(kubectl get pvc -n euler-copilot | grep 'mysql-pvc' 2>/dev/null || true) - if [ -n "$pvc_list" ]; then + if [ -n "$pvc_name" ]; then echo -e "${YELLOW}找到以下PVC,开始清理...${NC}" - kubectl delete pvc mysql-pvc -n euler-copilot --force --grace-period=0 || echo -e "${RED}PVC删除失败,继续执行...${NC}" + kubectl delete pvc mysql-pvc -n euler-copilot --force --grace-period=0 || echo -e "${RED}PVC删除失败,继续执行...${NC}" else echo -e "${YELLOW}未找到需要清理的PVC${NC}" fi @@ -88,6 +88,7 @@ get_user_input() { } helm_install() { + local arch="$1" echo -e "${BLUE}==> 进入部署目录...${NC}" [ ! -d "${DEPLOY_DIR}/chart" ] && { echo -e "${RED}错误:部署目录不存在 ${DEPLOY_DIR}/chart ${NC}" @@ -140,15 +141,20 @@ check_pods_status() { } main() { - get_architecture - create_namespace - delete_pvcs - get_user_input - helm_install - check_pods_status + local arch + arch=$(get_architecture) || exit 1 + create_namespace || exit 1 + delete_pvcs || exit 1 + get_user_input || exit 1 + helm_install "$arch" || exit 1 + check_pods_status || { + echo -e "${RED}部署失败:Pod状态检查未通过!${NC}" + exit 1 + } echo -e "\n${GREEN}=========================" - echo "Authhub 部署完成!" + echo -e "Authhub 部署完成!" + echo -e "查看pod状态:kubectl get pod -n euler-copilot" echo -e "Authhub登录地址为: https://${authhub_domain}" echo -e "默认账号密码: administrator/changeme" echo -e "=========================${NC}" @@ -156,4 +162,3 @@ main() { trap 'echo -e "${RED}操作被中断!${NC}"; exit 1' INT main "$@" - diff --git a/deploy/scripts/9-other-script/get_client_id_and_secret.py b/deploy/scripts/9-other-script/get_client_id_and_secret.py index 49644f86c9111782950e3a904c3549a9620b1513..834f5a254b66645a599d3b14f3975dcfb591bcfa 100755 --- a/deploy/scripts/9-other-script/get_client_id_and_secret.py +++ b/deploy/scripts/9-other-script/get_client_id_and_secret.py @@ -31,11 +31,8 @@ def get_service_cluster_ip(namespace, service_name): # 从解析后的JSON中获取Cluster IP cluster_ip = service_info['spec'].get('clusterIP', 'No Cluster IP found') - return cluster_ip - - def get_user_token(auth_hub_url, username="administrator", password="changeme"): url = auth_hub_url + "/oauth2/manager-login" payload = { @@ -45,10 +42,31 @@ def get_user_token(auth_hub_url, username="administrator", password="changeme"): headers = { "Content-Type": "application/json", } - response = requests.post(url, data=json.dumps(payload), headers=headers, verify=False) - if response.status_code == 200: - user_token = response.json()["data"]["user_token"] - return user_token + try: + response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10) + response.raise_for_status() # 触发HTTPError异常如果状态码不是2xx + response_data = response.json() + + # 检查响应结构是否包含data.user_token + if "data" in response_data and "user_token" in response_data["data"]: + return response_data["data"]["user_token"] + else: + print("错误:响应中缺少预期的数据结构") + print("完整响应内容:", json.dumps(response_data, indent=2)) + sys.exit(1) + + except requests.exceptions.HTTPError as e: + print(f"登录请求失败,HTTP状态码:{response.status_code}") + print("响应内容:", response.text) + sys.exit(1) + except json.JSONDecodeError: + print("错误:无法解析响应为JSON") + print("原始响应:", response.text) + sys.exit(1) + except Exception as e: + print(f"发生未知错误:{str(e)}") + sys.exit(1) + def register_app(auth_hub_url, user_token, client_name, client_url, redierct_urls): url = auth_hub_url + "/oauth2/applications/register" @@ -71,21 +89,34 @@ def register_app(auth_hub_url, user_token, client_name, client_url, redierct_url response = requests.post(url, json=payload, headers=headers) return response.json() - -def get_client_secret(auth_hub_url, user_token): # 修改参数列表 +def get_client_secret(auth_hub_url, user_token): url = auth_hub_url + "/oauth2/applications" headers = { "Authorization": user_token, "Content-Type": "application/json" } - response = requests.get(url, headers=headers) - for app in response.json()['data']["applications"]: - if app["client_metadata"]["client_name"] == "EulerCopilot": - return { - "client_id": app["client_info"]["client_id"], - "client_secret": app["client_info"]["client_secret"] - } - return {"error": "Application not found"} + try: + response = requests.get(url, headers=headers, timeout=10) + response.raise_for_status() + apps_data = response.json() + + # 确保响应结构正确 + if "data" in apps_data and "applications" in apps_data["data"]: + for app in apps_data["data"]["applications"]: + if app.get("client_metadata", {}).get("client_name") == "EulerCopilot": + return { + "client_id": app["client_info"]["client_id"], + "client_secret": app["client_info"]["client_secret"] + } + return {"error": "Application not found"} + else: + print("错误:应用列表响应结构异常") + print("完整响应:", json.dumps(apps_data, indent=2)) + sys.exit(1) + + except requests.exceptions.RequestException as e: + print(f"获取客户端凭证失败:{str(e)}") + sys.exit(1) if __name__ == "__main__": namespace = "euler-copilot" @@ -101,13 +132,23 @@ if __name__ == "__main__": print("2. 服务尚未分配IP(查看状态: kubectl get svc/{service_name} -n {namespace} -w)") sys.exit(1) + print("\n请填写应用注册信息(直接回车使用默认值)") + # 注册应用 + client_name = input(f"请输入 client_name (默认:EulerCopilot):").strip() or "EulerCopilot" + client_url = input(f"请输入 client_url (默认:https://www.eulercopilot.local):").strip() or "https://www.eulercopilot.local" + + redirect_input = input( + f"请输入 redirect_urls (逗号分隔,默认:https://www.eulercopilot.local/api/auth/login):" +).strip() + if redirect_input: + redirect_urls = [url.strip() for url in redirect_input.split(",")] + else: + redirect_urls = ["https://www.eulercopilot.local/api/auth/login"] + auth_hub_url = f"http://{cluster_ip}:8000" user_token = get_user_token(auth_hub_url) # 注册应用 - client_name = "EulerCopilot" - client_url = "https://www.eulercopilot.local" - redirect_urls = ["https://www.eulercopilot.local/api/auth/login"] register_app(auth_hub_url, user_token, client_name, client_url, redirect_urls) # 获取客户端凭证 diff --git a/deploy/scripts/9-other-script/modify_eulercopilot_yaml.py b/deploy/scripts/9-other-script/modify_eulercopilot_yaml.py index 0f474a578e04ef366989a7a4c82af18075038610..d8e70eba9f9b03e553308649d7c892b373afa53d 100755 --- a/deploy/scripts/9-other-script/modify_eulercopilot_yaml.py +++ b/deploy/scripts/9-other-script/modify_eulercopilot_yaml.py @@ -1,13 +1,36 @@ -import argparse import sys +import argparse +import subprocess +# 尝试导入 YAML 库 try: from ruamel.yaml import YAML from ruamel.yaml.comments import CommentedMap USING_RUAMEL = True except ImportError: - import yaml # PyYAML - USING_RUAMEL = False + try: + import yaml # 回退到 PyYAML + USING_RUAMEL = False + except ImportError: + print("未检测到 YAML 处理库,正在自动安装 ruamel.yaml...") + try: + # 优先尝试安装 ruamel.yaml + subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'ruamel.yaml']) + from ruamel.yaml import YAML + from ruamel.yaml.comments import CommentedMap + USING_RUAMEL = True + print("ruamel.yaml 安装成功") + except Exception as e: + print(f"安装 ruamel.yaml 失败: {e}, 改为尝试安装 PyYAML") + try: + # 回退安装 PyYAML + subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'PyYAML']) + import yaml + USING_RUAMEL = False + print("PyYAML 安装成功") + except Exception as e: + print(f"安装 PyYAML 也失败: {e}") + sys.exit(1) def parse_value(value): """智能转换值的类型"""