From c39b99c9141182baa606c2b8edac389f8df2bf5c Mon Sep 17 00:00:00 2001 From: Juanma Barea Date: Thu, 19 Jun 2025 12:49:01 +0200 Subject: [PATCH 1/4] fix: venv stack build fails on linux if / in image-name Signed-off-by: Juanma Barea --- llama_stack/cli/stack/_build.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/llama_stack/cli/stack/_build.py b/llama_stack/cli/stack/_build.py index 7ade6f17a..7b48f8b49 100644 --- a/llama_stack/cli/stack/_build.py +++ b/llama_stack/cli/stack/_build.py @@ -334,7 +334,9 @@ def _generate_run_config( ) run_config.providers[api].append(p_spec) - run_config_file = build_dir / f"{image_name}-run.yaml" + # Use only the basename for the run config file to avoid path issues with forward slashes + image_basename = os.path.basename(image_name) + run_config_file = build_dir / f"{image_basename}-run.yaml" with open(run_config_file, "w") as f: to_write = json.loads(run_config.model_dump_json()) @@ -371,12 +373,17 @@ def _run_stack_build_command_from_build_config( if not image_name: raise ValueError("Please specify an image name when building a venv image") + # At this point, image_name should not be None due to the validation above + if not image_name: + raise ValueError("Image name is required but was not provided") + if template_name: build_dir = DISTRIBS_BASE_DIR / template_name build_file_path = build_dir / f"{template_name}-build.yaml" else: build_dir = DISTRIBS_BASE_DIR / image_name - build_file_path = build_dir / f"{image_name}-build.yaml" + image_basename = os.path.basename(image_name) + build_file_path = build_dir / f"{image_basename}-build.yaml" os.makedirs(build_dir, exist_ok=True) run_config_file = None @@ -395,7 +402,7 @@ def _run_stack_build_command_from_build_config( build_file_path, image_name, template_or_config=template_name or config_path or str(build_file_path), - run_config=run_config_file, + run_config=str(run_config_file) if run_config_file else None, ) if return_code != 0: raise RuntimeError(f"Failed to build image {image_name}") From 37f0f60ed4f1081e389c873cae629c239ac89729 Mon Sep 17 00:00:00 2001 From: Juanma Barea Date: Fri, 20 Jun 2025 13:13:47 +0200 Subject: [PATCH 2/4] improves the solution to the fix Signed-off-by: Juanma Barea --- llama_stack/cli/stack/_build.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/llama_stack/cli/stack/_build.py b/llama_stack/cli/stack/_build.py index 7b48f8b49..181886a5d 100644 --- a/llama_stack/cli/stack/_build.py +++ b/llama_stack/cli/stack/_build.py @@ -334,9 +334,10 @@ def _generate_run_config( ) run_config.providers[api].append(p_spec) - # Use only the basename for the run config file to avoid path issues with forward slashes - image_basename = os.path.basename(image_name) - run_config_file = build_dir / f"{image_basename}-run.yaml" + run_config_file = build_dir / f"{image_name}-run.yaml" + + # Create the directory structure for the run config file + os.makedirs(run_config_file.parent, exist_ok=True) with open(run_config_file, "w") as f: to_write = json.loads(run_config.model_dump_json()) @@ -382,10 +383,10 @@ def _run_stack_build_command_from_build_config( build_file_path = build_dir / f"{template_name}-build.yaml" else: build_dir = DISTRIBS_BASE_DIR / image_name - image_basename = os.path.basename(image_name) - build_file_path = build_dir / f"{image_basename}-build.yaml" + build_file_path = build_dir / f"{image_name}-build.yaml" - os.makedirs(build_dir, exist_ok=True) + # Create the directory structure for the build file + os.makedirs(build_file_path.parent, exist_ok=True) run_config_file = None # Generate the run.yaml so it can be included in the container image with the proper entrypoint # Only do this if we're building a container image and we're not using a template From 02bfe47ddd414da0c24e678b84648408d8e2fdf2 Mon Sep 17 00:00:00 2001 From: Juanma Barea Date: Wed, 25 Jun 2025 15:13:03 +0200 Subject: [PATCH 3/4] improve run_config assignation Signed-off-by: Juanma Barea --- llama_stack/cli/stack/_build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llama_stack/cli/stack/_build.py b/llama_stack/cli/stack/_build.py index 181886a5d..c51fc649c 100644 --- a/llama_stack/cli/stack/_build.py +++ b/llama_stack/cli/stack/_build.py @@ -403,7 +403,7 @@ def _run_stack_build_command_from_build_config( build_file_path, image_name, template_or_config=template_name or config_path or str(build_file_path), - run_config=str(run_config_file) if run_config_file else None, + run_config=run_config_file.as_posix() if run_config_file else None, ) if return_code != 0: raise RuntimeError(f"Failed to build image {image_name}") From fac7e937bc236314ff2285e0a46d4f8e7a617241 Mon Sep 17 00:00:00 2001 From: Juanma Barea Date: Thu, 26 Jun 2025 10:45:42 +0200 Subject: [PATCH 4/4] fix pre-commit errors Signed-off-by: Juanma Barea --- llama_stack/cli/stack/_build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llama_stack/cli/stack/_build.py b/llama_stack/cli/stack/_build.py index c51fc649c..1db3456ce 100644 --- a/llama_stack/cli/stack/_build.py +++ b/llama_stack/cli/stack/_build.py @@ -335,7 +335,7 @@ def _generate_run_config( run_config.providers[api].append(p_spec) run_config_file = build_dir / f"{image_name}-run.yaml" - + # Create the directory structure for the run config file os.makedirs(run_config_file.parent, exist_ok=True)