From b7c388db3e0314bf4ce4f1906433215ed5b0e3f7 Mon Sep 17 00:00:00 2001 From: 170-carry Date: Wed, 29 Apr 2026 14:47:49 +0800 Subject: [PATCH] force prod profiles in compose templates --- monitors/yumi/compose_templates.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/monitors/yumi/compose_templates.py b/monitors/yumi/compose_templates.py index 5d8e36f..7f1f020 100644 --- a/monitors/yumi/compose_templates.py +++ b/monitors/yumi/compose_templates.py @@ -148,6 +148,24 @@ def normalize_command(raw_value: Any) -> list[str] | str | None: return [str(item) for item in raw_value] +def normalize_prod_profile_command(raw_value: list[str] | str | None) -> list[str] | str | None: + # 线上 compose 模板强制使用 prod,避免从运行态刷新模板时把 local 启动参数带回来。 + if raw_value is None: + return None + if isinstance(raw_value, list): + return [normalize_prod_profile_text(item) for item in raw_value] + return normalize_prod_profile_text(raw_value) + + +def normalize_prod_profile_text(raw_value: str) -> str: + text = str(raw_value) + for property_name in ("spring.profiles.active", "spring-profile.active"): + escaped = re.escape(property_name) + text = re.sub(rf"(--{escaped}=)[^\s]+", rf"\1prod", text) + text = re.sub(rf"(--{escaped})(\s+)[^\s]+", rf"\1\2prod", text) + return text + + def healthcheck_block(config: dict[str, Any]) -> dict[str, Any] | None: # 把 inspect 里的健康检查结构翻回 compose 可接受格式。 healthcheck = config.get("Healthcheck") or {} @@ -315,6 +333,7 @@ def build_service_definition( command = normalize_command(config.get("Cmd")) if command is not None: + command = normalize_prod_profile_command(command) service_definition["command"] = command healthcheck = healthcheck_block(config)