force prod profiles in compose templates
This commit is contained in:
parent
649f348540
commit
b7c388db3e
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user