@@ -303,13 +303,18 @@ def _build_submitter_pod_template(
303303 """
304304 Build submitterPodTemplate with ConfigMap volume mount for local files.
305305
306+ If files contain working_dir.zip, an init container will unzip it before
307+ the main submitter container runs.
308+
306309 Args:
307310 files: Dict of file_name -> file_content
308311 configmap_name: Name of the ConfigMap containing the files
309312
310313 Returns:
311314 submitterPodTemplate specification
312315 """
316+ from codeflare_sdk .ray .rayjobs .runtime_env import UNZIP_PATH
317+
313318 # Image has to be hard coded for the job submitter
314319 image = get_ray_image_for_python_version ()
315320 if (
@@ -324,16 +329,26 @@ def _build_submitter_pod_template(
324329 for file_name in files .keys ():
325330 config_map_items .append ({"key" : file_name , "path" : file_name })
326331
332+ # Check if we need to unzip working_dir
333+ has_working_dir_zip = "working_dir.zip" in files
334+
335+ # Base volume mounts for main container
336+ volume_mounts = [{"name" : "ray-job-files" , "mountPath" : MOUNT_PATH }]
337+
338+ # If we have a zip file, we need shared volume for unzipped content
339+ if has_working_dir_zip :
340+ volume_mounts .append (
341+ {"name" : "unzipped-working-dir" , "mountPath" : UNZIP_PATH }
342+ )
343+
327344 submitter_pod_template = {
328345 "spec" : {
329346 "restartPolicy" : "Never" ,
330347 "containers" : [
331348 {
332349 "name" : "ray-job-submitter" ,
333350 "image" : image ,
334- "volumeMounts" : [
335- {"name" : "ray-job-files" , "mountPath" : MOUNT_PATH }
336- ],
351+ "volumeMounts" : volume_mounts ,
337352 }
338353 ],
339354 "volumes" : [
@@ -348,6 +363,33 @@ def _build_submitter_pod_template(
348363 }
349364 }
350365
366+ # Add init container and volume for unzipping if needed
367+ if has_working_dir_zip :
368+ # Add emptyDir volume for unzipped content
369+ submitter_pod_template ["spec" ]["volumes" ].append (
370+ {"name" : "unzipped-working-dir" , "emptyDir" : {}}
371+ )
372+
373+ # Add init container to unzip before KubeRay's submitter runs
374+ submitter_pod_template ["spec" ]["initContainers" ] = [
375+ {
376+ "name" : "unzip-working-dir" ,
377+ "image" : image ,
378+ "command" : ["/bin/sh" , "-c" ],
379+ "args" : [
380+ # Decode base64 zip, save to temp file, extract, cleanup
381+ f"mkdir -p { UNZIP_PATH } && "
382+ f"python3 -m base64 -d { MOUNT_PATH } /working_dir.zip > /tmp/working_dir.zip && "
383+ f"python3 -m zipfile -e /tmp/working_dir.zip { UNZIP_PATH } / && "
384+ f"rm /tmp/working_dir.zip && "
385+ f"echo 'Successfully unzipped working_dir to { UNZIP_PATH } ' && "
386+ f"ls -la { UNZIP_PATH } "
387+ ],
388+ "volumeMounts" : volume_mounts ,
389+ }
390+ ]
391+ logger .info (f"Added init container to unzip working_dir to { UNZIP_PATH } " )
392+
351393 logger .info (
352394 f"Built submitterPodTemplate with { len (files )} files mounted at { MOUNT_PATH } , using image: { image } "
353395 )
0 commit comments