Elffuss BraidHub

kikocis/llama-stack public

fix docker configure
Changesetbc6e7bb13b7e04f5d335f6c7c1a5a7d0bedb21c473d849f84387f3513d2c0b5d
AuthorXi Yan <xiyan@meta.com> · 2024-09-18 17:23 -07:00
CommitterXi Yan <xiyan@meta.com> · 2024-09-18 17:23 -07:00
Parents52f9a9a2a96d

Browse the files at this changeset

1 file changed

modified llama_stack/cli/stack/configure.py +50 −34
@@ -53,46 +53,62 @@
5353 from termcolor import cprint
5454
5555 docker_image = None
56+
57+ build_config_file = Path(args.config)
58+
59+ if build_config_file.exists():
60+ with open(build_config_file, "r") as f:
61+ build_config = BuildConfig(**yaml.safe_load(f))
62+ self._configure_llama_distribution(build_config, args.output_dir)
63+ return
64+
65+ # if we get here, we need to try to find the conda build config file
66+ cprint(
67+ f"Could not find {build_config_file}. Trying conda build name instead...",
68+ color="green",
69+ )
5670 conda_dir = Path(os.getenv("CONDA_PREFIX")).parent / f"llamastack-{args.config}"
5771 build_config_file = Path(conda_dir) / f"{args.config}-build.yaml"
5872
59- if not build_config_file.exists():
60- cprint(
61- f"Could not find {build_config_file}. Trying docker image name instead...",
62- color="green",
63- )
64- docker_image = args.config
65-
66- builds_dir = BUILDS_BASE_DIR / ImageType.docker.value
67- if args.output_dir:
68- builds_dir = Path(output_dir)
69- os.makedirs(builds_dir, exist_ok=True)
70-
71- script = pkg_resources.resource_filename(
72- "llama_stack", "distribution/configure_container.sh"
73- )
74- script_args = [script, docker_image, str(builds_dir)]
75-
76- return_code = run_with_pty(script_args)
77-
78- # we have regenerated the build config file with script, now check if it exists
79- if return_code != 0:
80- self.parser.error(
81- f"Can not find {build_config_file}. Please run llama stack build first or check if docker image exists"
82- )
83-
84- build_name = docker_image.removeprefix("llamastack-")
85- saved_file = str(builds_dir / f"{build_name}-run.yaml")
86- cprint(
87- f"YAML configuration has been written to {saved_file}. You can now run `llama stack run {saved_file}`",
88- color="green",
89- )
73+ if build_config_file.exists():
74+ with open(build_config_file, "r") as f:
75+ build_config = BuildConfig(**yaml.safe_load(f))
76+
77+ self._configure_llama_distribution(build_config, args.output_dir)
9078 return
9179
92- with open(build_config_file, "r") as f:
93- build_config = BuildConfig(**yaml.safe_load(f))
80+ # if we get here, we need to try to find the docker image
81+ cprint(
82+ f"Could not find {build_config_file}. Trying docker image name instead...",
83+ color="green",
84+ )
85+ docker_image = args.config
86+ builds_dir = BUILDS_BASE_DIR / ImageType.docker.value
87+ if args.output_dir:
88+ builds_dir = Path(output_dir)
89+ os.makedirs(builds_dir, exist_ok=True)
90+
91+ script = pkg_resources.resource_filename(
92+ "llama_stack", "distribution/configure_container.sh"
93+ )
94+ script_args = [script, docker_image, str(builds_dir)]
95+
96+ return_code = run_with_pty(script_args)
97+
98+ # we have regenerated the build config file with script, now check if it exists
99+ if return_code != 0:
100+ self.parser.error(
101+ f"Failed to configure container {docker_image} with return code {return_code}. Please run `llama stack build first`. "
102+ )
103+ return
94104
95- self._configure_llama_distribution(build_config, args.output_dir)
105+ build_name = docker_image.removeprefix("llamastack-")
106+ saved_file = str(builds_dir / f"{build_name}-run.yaml")
107+ cprint(
108+ f"YAML configuration has been written to {saved_file}. You can now run `llama stack run {saved_file}`",
109+ color="green",
110+ )
111+ return
96112
97113 def _configure_llama_distribution(
98114 self,