diff --git a/src/openenv/core/containers/runtime/_server_config.py b/src/openenv/core/containers/runtime/_server_config.py index 8eb3f96d6..361b1f03f 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"(?