From e6b11dcaf0c7ac6d4e7d829a624bbcabdc25cd0c Mon Sep 17 00:00:00 2001 From: Jin Long Date: Thu, 29 Oct 2026 01:17:39 +0800 Subject: [PATCH] fix(core): parse continued Dockerfile CMD instructions --- .../core/containers/runtime/_server_config.py | 36 +++++++++++- tests/test_core/test_server_config.py | 55 +++++++++++++++++++ 2 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 tests/test_core/test_server_config.py diff --git a/src/openenv/core/containers/runtime/_server_config.py b/src/openenv/core/containers/runtime/_server_config.py index 8eb3f96d60..361b1f03f4 100644 --- a/src/openenv/core/containers/runtime/_server_config.py +++ b/src/openenv/core/containers/runtime/_server_config.py @@ -30,13 +30,45 @@ def parse_openenv_app_field(yaml_content: str) -> str | None: def parse_dockerfile_cmd(dockerfile_content: str) -> str | None: """Extract the server command from the last Dockerfile ``CMD``.""" last_cmd: str | None = None + instruction = "" + escape = "\\" + directives = True for line in dockerfile_content.splitlines(): - stripped = line.strip() + stripped = line.lstrip() if stripped.startswith("#"): + if directives: + directive = re.fullmatch( + r"#\s*(syntax|check|escape)\s*=\s*(.+)", + stripped, + flags=re.IGNORECASE, + ) + if directive is None: + directives = False + elif directive[1].lower() == "escape" and directive[2].strip() in ( + "\\", + "`", + ): + escape = directive[2].strip() continue - match = re.match(r"CMD\s+(.+)", stripped, flags=re.IGNORECASE) + if not stripped.strip(): + directives = False + continue + directives = False + if not instruction: + match = re.match(r"\s*CMD\s+(.+)", line, flags=re.IGNORECASE) + if match: + last_cmd = match.group(1).strip() + continuation = re.search( + rf"(?