
    &                     h    d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dZ	dd	e	d	fd
Z
	 	 	 	 ddZy	)z>Functions required to interact with Docker to run a container.    )absolute_import)division)unicode_literals)utils)configz/tmp/keys/cred_key.jsonFNc                    |g }| rddgng }|rddj                  ||      g}n>t        j                         xs t        j                         }ddj                  ||      g}ddj                  |      g}dg|z   |z   |z   dd	gz   |z   S )
a;  Returns a list of 'docker run' options.

  Args:
    enable_gpu: (bool) using GPU or not.
    service_account_key: (bool) path of the service account key to use in host.
    cred_mount_path: (str) path in the container to mount the credential key.
    extra_run_opts: (List[str]) other custom docker run options.
  z	--runtimenvidiaz-vz{}:{}z-ez!GOOGLE_APPLICATION_CREDENTIALS={}z--rmz--ipchost)formatr   ADCEnvVariableADCFilePath)
enable_gpuservice_account_keycred_mount_pathextra_run_optsruntimemountadc_file_pathenv_vars           /lib/googlecloudsdk/command_lib/ai/docker/run.py_DockerRunOptionsr      s     N'1[(#r'7>>"5GHE ))+Cv/A/A/CM7>>-ABE6==oNO'
G	e	#g	-& 12 
24B
C C    c                 v    |g }|g }t        |||      }ddg|z   | gz   |z   }t        j                  |       y)a  Calls `docker run` on a given image with specified arguments.

  Args:
    image_name: (str) Name or ID of Docker image to run.
    enable_gpu: (bool) Whether to use GPU
    service_account_key: (str) Json file of a service account key  auth.
    run_args: (List[str]) Extra custom options to apply to `docker run` after
      our defaults.
    user_args: (List[str]) Extra user defined arguments to supply to the
      entrypoint.
  N)r   r   r   dockerrun)r   r   ExecuteDockerCommand)
image_namer   r   run_args	user_argsrun_optscommands          r   RunContainerr"   8   sX    $ HI-(
 u(J<7)C'W%r   )FNNN)__doc__
__future__r   r   r   $googlecloudsdk.command_lib.ai.dockerr   googlecloudsdk.corer    _DEFAULT_CONTAINER_CRED_KEY_PATHr   r"    r   r   <module>r)      sG    E &  ' 6 &#<   "'*.&F%)C< "%)	&r   