o
    bi                     @   s   d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
 e eZdede jfdd	Zded
edeee  dede jdefddZG dd deZG dd deZdS )    N)ListOptional)RuntimeEnvContext)RuntimeEnvPlugin)check_output_cmd	image_uriloggerc                    s:   ddd| dddg}| d|  t||dI d H }| S )	Npodmanrunz--rmpythonz-cz\import ray._private.workers.default_worker as default_worker; print(default_worker.__file__)zPulling image %s)r   )infor   strip)r   r   pull_image_cmdworker_path r   V/home/ubuntu/.local/lib/python3.10/site-packages/ray/_private/runtime_env/image_uri.py_create_impl   s   r   r   run_optionscontextray_tmp_dirc              	   C   s   ||_ d}|dd|d | ddddd	g	}t }tj D ]\}	}
|	d
r)|
||	< q||j | D ]\}	}
|d ||	 d|
 d q4|d |d |rZ|	| |d |d ||  d
|}|d|  ||_d S )Nr	   r
   z-v:z--cgroup-manager=cgroupfsz--network=hostz
--pid=hostz
--ipc=hostz--userns=keep-idRAY_z--envz=''zRAY_JOB_ID=$RAY_JOB_IDz--entrypointr    z)Starting worker in container with prefix )override_worker_entrypointdictosenvironitems
startswithupdateenv_varsappendextendjoinr   py_executable)r   r   r   r   r   r   container_drivercontainer_commandr!   env_var_nameenv_var_valuecontainer_command_strr   r   r   _modify_context_impl    s>   











r+   c                
   @   sz   e Zd ZdZdZedd ZdefddZde	e d	d
de
dejdef
ddZefdee d	d
de
de	ej fddZdS )ImageURIPluginz/Starts worker in a container of a custom image.r   c                   C   s   h dS )N>   configr!   r   r   r   r   r   r   get_compatible_keyso   s   z"ImageURIPlugin.get_compatible_keysr   c                 C   
   || _ d S N_ray_tmp_dirselfr   r   r   r   __init__s      
zImageURIPlugin.__init__uriruntime_env
RuntimeEnvr   r   returnc                    s(   |  sd S t|  |I d H | _d S r0   )r   r   r   r4   r7   r8   r   r   r   r   r   createv   s   zImageURIPlugin.createurisc                 C   s*   |  sd S t|  | jg ||| j d S r0   )r   r+   r   r2   r4   r=   r8   r   r   r   r   r   modify_context   s   zImageURIPlugin.modify_contextN)__name__
__module____qualname____doc__namestaticmethodr.   strr5   r   r   loggingLoggerfloatr<   default_loggerr   r?   r   r   r   r   r,   j   s6    

r,   c                
   @   sn   e Zd ZdZdZdefddZdee ddd	ed
e	j
def
ddZefdee ddd	ed
ee	j
 fddZdS )ContainerPluginzStarts worker in container.	containerr   c                 C   r/   r0   r1   r3   r   r   r   r5      r6   zContainerPlugin.__init__r7   r8   r9   r   r   r:   c                    s0   |  r	| sd S t| |I d H | _d S r0   )has_py_containerpy_container_imager   r   r;   r   r   r   r<      s   zContainerPlugin.creater=   c                 C   sP   |  r| s
d S | r|d t| | p| j| ||| j d S )NzYou are using `container.worker_path`, but the path to `default_worker.py` is now automatically detected from the image. `container.worker_path` is deprecated and will be removed in future versions.)rM   rN   py_container_worker_pathwarningr+   r   py_container_run_optionsr2   r>   r   r   r   r?      s   zContainerPlugin.modify_contextN)r@   rA   rB   rC   rD   rF   r5   r   r   rG   rH   rI   r<   rJ   r   r?   r   r   r   r   rK      s2    
rK   )rG   r   typingr   r    ray._private.runtime_env.contextr   ray._private.runtime_env.pluginr   ray._private.runtime_env.utilsr   	getLoggerr@   rJ   rF   rH   r   r+   r,   rK   r   r   r   r   <module>   s.    


J,