@@ -17,30 +17,23 @@ def prepare_test(base_work_dir, platform):
1717
1818
1919def _get_binary_path (base_work_dir , platform ):
20- git_ref = config .project .get_config ("prepare.ramalama.repo.git_ref" )
2120 version = config .project .get_config ("prepare.ramalama.repo.version" )
2221
23- if git_ref and version :
24- raise ValueError (f"Cannot have Ramalama git_ref={ git_ref } and version={ version } set together." )
25-
2622 if version == "latest" :
2723 repo_url = config .project .get_config ("prepare.ramalama.repo.url" )
2824 version = utils .get_latest_release (repo_url )
2925 config .project .set_config ("prepare.ramalama.repo.version" , version )
3026
31- system_file = f"{ version } .zip"
32-
3327 dest_base = base_work_dir / "ramalama-ai"
34- if version :
35- # don't use 'ramalama' in the base_work_dir, otherwise Python
36- # takes it (invalidly) for the package `ramalama` package
37- dest = dest_base / system_file
38- dest_dir = dest .parent / f"ramalama-{ version .removeprefix ('v' )} "
39- else :
40- dest = dest_dir = dest_base / f"ramalama-{ git_ref } "
4128
42- ramalama_path = dest_dir / "bin" / "ramalama"
43- return ramalama_path , dest , (version , git_ref )
29+ # don't use 'ramalama' in the base_work_dir, otherwise Python
30+ # takes it (invalidly) for the package `ramalama` package
31+
32+ dest_dir = dest_base / f"ramalama-{ version .removeprefix ('v' )} "
33+
34+ ramalama_path = dest_dir / "bin" / "ramalama"
35+
36+ return ramalama_path , dest_dir , version
4437
4538
4639def get_binary_path (base_work_dir , platform ):
@@ -52,40 +45,28 @@ def get_binary_path(base_work_dir, platform):
5245
5346 return ramalama_path
5447
55- def download_ramalama (base_work_dir , dest , version , git_ref ):
48+ def download_ramalama (base_work_dir , dest , version ):
5649 repo_url = config .project .get_config ("prepare.ramalama.repo.url" )
5750
58- if version :
59- source = "/" .join ([
60- repo_url ,
61- "archive/refs/tags" ,
62- f"{ version } .zip" ,
63- ])
64- run .run_toolbox (
65- "remote" , "download" ,
66- source = source , dest = dest ,
67- tarball = True ,
68- )
51+ kwargs = dict (
52+ repo_url = repo_url ,
53+ dest = dest ,
54+ )
55+ if version .startswith ("pr-" ):
56+ pr_number = version .removeprefix ("pr-" )
57+ kwargs ["refspec" ] = f"refs/pull/{ pr_number } /head"
6958 else :
70- kwargs = dict (
71- repo_url = repo_url ,
72- dest = dest ,
73- )
74- if git_ref .startswith ("pr-" ):
75- pr_number = git_ref .removeprefix ("pr-" )
76- kwargs ["refspec" ] = f"refs/pull/{ pr_number } /head"
77- else :
78- kwargs ["refspec" ] = git_ref
79-
80- run .run_toolbox (
81- "remote" , "clone" ,
82- ** kwargs ,
83- artifact_dir_suffix = "_llama_cpp" ,
84- force = True ,
85- )
59+ kwargs ["version" ] = version
8660
87- remote_access .run_with_ansible_ssh_conf (base_work_dir , "git show -s --format='%cd%n%s%n%H' --date=format:'%y%m%d.%H%M' > ramalama-commit.info" ,
88- chdir = dest )
61+ run .run_toolbox (
62+ "remote" , "clone" ,
63+ ** kwargs ,
64+ artifact_dir_suffix = "_llama_cpp" ,
65+ force = True ,
66+ )
67+
68+ remote_access .run_with_ansible_ssh_conf (base_work_dir , "git show -s --format='%cd%n%s%n%H' --date=format:'%y%m%d.%H%M' > ramalama-commit.info" ,
69+ chdir = dest )
8970
9071
9172def build_container_image (base_work_dir , ramalama_path ):
@@ -100,6 +81,7 @@ def build_container_image(base_work_dir, ramalama_path):
10081
10182 chdir = ramalama_path .parent .parent
10283
84+ logging .info ("Building the ramalama image ..." )
10385 with env .NextArtifactDir (f"build_ramalama_{ image_name } _image" ):
10486 cmd = f"env PATH=$PATH:{ podman_mod .get_podman_binary (base_work_dir ).parent } "
10587 cmd += f" time ./container_build.sh build { image_name } "
@@ -111,6 +93,10 @@ def build_container_image(base_work_dir, ramalama_path):
11193 LLAMA_CPP_REPO = config .project .get_config ("prepare.llama_cpp.source.repo.url" ),
11294 )
11395
96+ if config .project .get_config ("prepare.ramalama.build_image.debug" ):
97+ extra_env ["RAMALAMA_IMAGE_BUILD_DEBUG" ] = "y"
98+ extra_env ["RAMALAMA_IMAGE_INCLUDE_DEBUG" ] = "y"
99+
114100 ret = remote_access .run_with_ansible_ssh_conf (base_work_dir , cmd ,
115101 extra_env = extra_env ,
116102 chdir = chdir , check = False , capture_stdout = True )
@@ -125,11 +111,10 @@ def build_container_image(base_work_dir, ramalama_path):
125111
126112
127113def prepare_binary (base_work_dir , platform ):
128- ramalama_path , dest , (version , git_ref ) = _get_binary_path (base_work_dir , platform )
129- system_file = dest .name
114+ ramalama_path , dest , version = _get_binary_path (base_work_dir , platform )
130115
131- if git_ref or not remote_access .exists (ramalama_path ):
132- download_ramalama (base_work_dir , dest , version , git_ref )
116+ if version . startswith ( "pr-" ) or not remote_access .exists (ramalama_path ):
117+ download_ramalama (base_work_dir , dest , version )
133118 else :
134119 logging .info (f"ramalama { platform .name } already exists, not downloading it." )
135120
@@ -138,11 +123,17 @@ def prepare_binary(base_work_dir, platform):
138123 image_name = build_container_image (base_work_dir , ramalama_path )
139124
140125 if config .project .get_config ("prepare.ramalama.build_image.publish.enabled" ):
141- version = config .project .get_config ("prepare.llama_cpp.source.repo.version" )
142126 podman_mod .login (base_work_dir , "prepare.ramalama.build_image.publish.credentials" )
127+
128+ version = config .project .get_config ("prepare.llama_cpp.source.repo.version" )
129+
143130 dest_image_name = image_name .partition (":" )[0 ] + f":{ version } "
144- dest_image_latest = image_name .partition (":" )[0 ] + f":latest"
145- logging .info (f"Pushing the image to { dest_image_name } and latest" )
131+ dest_image_latest = image_name .partition (":" )[0 ] + ":latest"
132+ if config .project .get_config ("prepare.ramalama.build_image.debug" ):
133+ dest_image_latest = dest_image_latest .removesuffix (":latest" ) + ":debug"
134+ dest_image_name += "-debug"
135+
136+ logging .info (f"Pushing the image to { dest_image_name } and { dest_image_latest } " )
146137
147138 podman_mod .push_image (base_work_dir , image_name , dest_image_name )
148139 podman_mod .push_image (base_work_dir , image_name , dest_image_latest )
@@ -186,13 +177,12 @@ def stop_server(base_work_dir, ramalama_path):
186177def run_model (base_work_dir , platform , ramalama_path , model , unload = False ):
187178 inference_server_port = config .project .get_config ("test.inference_server.port" )
188179
189- if config .project .get_config ("prepare.ramalama.repo.git_ref" ):
190- commit_date_cmd = remote_access .run_with_ansible_ssh_conf (base_work_dir , f"cat ramalama-commit.info" , chdir = ramalama_path .parent .parent , check = False , capture_stdout = True )
191- if commit_date_cmd .returncode != 0 :
192- logging .warning ("Couldn't find the Ramalama commit info file ..." )
193- else :
194- logging .warning (f"Ramalama commit info: { commit_date_cmd .stdout } " )
195- (env .ARTIFACT_DIR / "ramalama-commit.info" ).write_text (commit_date_cmd .stdout )
180+ commit_date_cmd = remote_access .run_with_ansible_ssh_conf (base_work_dir , f"cat ramalama-commit.info" , chdir = ramalama_path .parent .parent , check = False , capture_stdout = True )
181+ if commit_date_cmd .returncode != 0 :
182+ logging .warning ("Couldn't find the Ramalama commit info file ..." )
183+ else :
184+ logging .warning (f"Ramalama commit info: { commit_date_cmd .stdout } " )
185+ (env .ARTIFACT_DIR / "ramalama-commit.info" ).write_text (commit_date_cmd .stdout )
196186
197187 artifact_dir_suffix = None
198188 if unload :
0 commit comments