
    .                     T   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJ	r	  SSK
Jr  SS	K
Jr  SS
K
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSK
Jr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r!  SSK"r"SSK#r# " S S\RH                  5      r%S r&S r'S r(\RR                  S 5       r*\	RV                  " \	RX                  RZ                  \	RX                  R\                  5       " S  S!\	R^                  5      5       r0S" r1S# r2S$ r3g)%z4Command for running a local development environment.    )absolute_import)division)print_function)unicode_literalsN)base)cross_platform_temp_file)flags)
kubernetes)local)local_files)run_subprocess)skaffold)yaml_helper)artifact_registry)cloud)cloud_files)cloudrun)config)
exceptions)
properties)yaml)update_manager)filesc                       \ rS rSrSrSrg)RuntimeMissingDependencyError/   z A runtime dependency is missing. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       lib/surface/code/dev.pyr   r   /   s    (r$   r   c                  l    [         R                  R                  R                  R	                  5       S:H  $ )z/Return true if the verbosity is equal to debug.debug)r   VALUEScore	verbosityGetr   r$   r%   _IsDebugr,   3   s(    						)	)	-	-	/7	::r$   c                 J    [         R                  " U SS[        5       (       + S9$ )N	skaffold_.yamlprefixsuffixdeleter   NamedTempFiler,   )skaffold_configs    r%   _SkaffoldTempFiler7   8   s%    	!	/	/^	
 r$   c                 J    [         R                  " U SS[        5       (       + S9$ )Ndeploy_r/   r0   r4   )kubernetes_configs    r%   _DeployTempFiler;   @   s%    	!	/	/^	
 r$   c              #     #    U(       d  U v   g[         R                  " U R                  5      n[        R                  " US5      nSUS'   [        [         R                  " U5      5       nUv   SSS5        g! , (       d  f       g= f7f)a1  Set build.local.push value in skaffold file.

Args:
  skaffold_file: Skaffold file handle.
  shared_docker: Boolean that is true if docker instance is shared between the
    kubernetes cluster and local docker builder.

Yields:
  Path of skaffold file with build.local.push value set to the proper value.
)buildr   FpushN)r   	load_pathnamer   GetOrCreater7   dump)skaffold_fileshared_dockerskaffold_yamllocal_blockpatched_skaffold_files        r%   _SetImagePushrH   H   sh      
 NN=#5#56M))-9KLKK	499]3	48M!! 
5	4	4s   A(B	*A8/	B	8
BB	c                       \ rS rSrSrSSS.r\S 5       rS rS r	S	 r
S
 rS r\S 5       r\\R                   S 5       5       rSrg)Devb   z;Run a Cloud Run service in a local development environment.a!            Run a Cloud Run service in a local development environment.

          This command takes Cloud Run source, builds it, and runs it on the
          local machine. This command also watches the relevant source files and
          updates the container when they change.
          a            If building images using a Dockerfile:

            $ {command} --dockerfile=<path_to_dockerfile>

          If the Dockerfile is named `Dockerfile` and is located in the current
          directory, the `--dockerfile` flag may be omitted:

            $ {command}

          To access Google Cloud Platform services with the current user's
          credentials, login to obtain the application default credentials and
          invoke this command with the `--application-default-credential` flag.

            $ gcloud auth application-default login
            $ {command} --dockerfile=<path_to_dockerfile>             --application-default-credential
          )DESCRIPTIONEXAMPLESc                    [         R                  " 5       nUR                  U R                  5       5        UR	                  U5        UR                  SS9nUR                  SSS9  UR                  SSS9  UR                  SS	S
SS9  U R                  5       [        R                  R                  :X  a!  UR                  SSSS9  UR                  SSS9  UR                  S[        S	SS9  g )NF)requiredz--kube-contextzKubernetes context.)helpz--minikube-profilezMinikube profile.z--stop-clusterT
store_truezKIf running on minikube, stop the minkube profile at the end of the session.)defaultactionrP   z--minikube-vm-driverdockerz+If running on minikube, use this vm driver.)rR   rP   z--namespacez8Kubernetes namespace for development kubernetes objects.z--skaffold-events-portz^Local port on which the skaffold events api is exposed. If not set, a random port is selected.)typehiddenrP   )
r	   CommonFlagsAddAlphaAndBetaFlagsReleaseTrackConfigureParseradd_mutually_exclusive_groupadd_argumentr   ALPHAint)clsparsercommongroups       r%   ArgsDev.Args   s    F
 0 0 23
6"///?E	'.CD	+2EF
	   T..444
 <  >
 
I  K
  *	  +r$   c                     [        U5        [        5       (       a  [        U5        UR                  S5      (       a#  UR                  (       a  U R                  U5        g U R                  U5        g )Nr   )_EnsureComponentsInstalledr,   _PrintDependencyVersionsIsKnownAndSpecifiedr   	_RunCloud	_RunLocal)selfargss     r%   RunDev.Run   sH    t$zzt$((TZZ
nnT
nnTr$   c                 @   [         R                  " XR                  5       5      n[        R                  " U5      n[
        R                  " UR                  5       5      n[        USS 5      n[        5         [        U5       n[
        R                  " UR                  UR                  5      5      nUR                  =(       d    [        R                  " 5       n[!        U5       n	U R#                  U5       n
U R%                  XZR&                  5         [)        U	U
R*                  5       nU R-                  XUU5       n[.        R0                  " UR2                  U5         UR5                  5         S S S 5        S S S 5        S S S 5        S S S 5        S S S 5        S S S 5        S S S 5        g ! , (       d  f       N?= f! , (       d  f       NH= f! , (       d  f       NQ= f! , (       d  f       NZ= f! , (       d  f       Nc= f! , (       d  f       Nl= f! , (       d  f       g = f)N	namespace)r   AssembleSettingsrY   r   LocalRuntimeFilessixensure_textKubernetesConfiggetattr_EnsureDockerRunningr;   SkaffoldConfigr@   skaffold_events_port
portpickerpick_unused_portr7   _GetKubernetesEngine_WithKubeNamespacecontext_namerH   rD   _SkaffoldProcessr   PrintUrlThreadContextservice_namewait)rk   rl   settingslocal_file_generatorr:   rp   kubernetes_filer6   skaffold_event_portrC   kube_contextrG   running_processs                r%   rj   Dev._RunLocal   s   %%d,=,=,?@H&88B(<(M(M(OPk40I	*	+

-
-o.B.B
CEo 
#
#
Dz'B'B'D _-$$T*l""9.G.GH%3358M  !6i!469H))(*?*?*=??65 I + . 
,	+? ?6 65 5 IH +* .- 
,	+s   A#H$G>6G-G	)G="F:F)0F:8G G	G-G>H)
F73F::
GG
GG	
G*&G--
G;7G>>
H	H
Hc           	         [         R                  " U5      n[         R                  " U5        [        R                  " XU R                  5       5        [        R                  " U5      n[        R                  " UR                  5       5      nUR                  (       a   [        R                  " UR                  5        [        U5       n[        R                  " UR                  UR                   5      5      nUR"                  =(       d    [$        R&                  " 5       n[)        U5       nU R+                  UU5       n	[,        R.                  " UR0                  U5         U	R3                  5         S S S 5        S S S 5        S S S 5        S S S 5        g ! , (       d  f       N'= f! , (       d  f       N0= f! , (       d  f       N9= f! , (       d  f       g = fN)r   rq   ValidateSettingsr   PromptToOverwriteCloudrY   r   CloudRuntimeFilesrs   rt   ru   ar_repor   CreateIfNeededr;   rx   r@   ry   rz   r{   r7   _CloudSkaffoldProcessr   r   r   r   )
rk   rl   r   cloud_file_generatorr:   r   r6   r   rC   r   s
             r%   ri   Dev._RunCloud   sP   %%d+H	8$##DD4E4E4GH&88B(<(M(M(OP&&x'7'78	*	+

-
-o.B.B
CEo 
#
#
Dz'B'B'D _-%%m&9;>M))(*?*?*=??; . 
,	+? ?; ; .- 
,	+sU   A#G+F4>"F# F	1F#9F4G
F F##
F1-F44
G	>G
Gc                     [         R                  " UR                  UR                  UUR                  [        5       U5      $ r   )r   Skaffoldr@   r~   env_varsr,   )rk   rG   r   rp   r   s        r%   r   Dev._SkaffoldProcess   s9    277)66	)22HJ02 2r$   c                 R    [         R                  " UR                  [        5       US9$ )N)r'   events_port)r   r   r@   r,   )rk   rG   r   s      r%   r   Dev._CloudSkaffoldProcess   s&    ""j') )r$   c                 d   ^  U 4S jnU 4S jnT R                  S5      (       a  U" 5       $ U" 5       $ )zGet the appropriate kubernetes implementation from the args.

Args:
  args: The namespace containing the args.

Returns:
  The context manager for the appropriate kubernetes implementation.
c                  D   > [         R                  " T R                  5      $ r   )r
   ExternalClusterContextr   )rl   s   r%   External*Dev._GetKubernetesEngine.<locals>.External   s    ..t/@/@AAr$   c            	         > TR                  S5      (       a  TR                  n O[        R                  n [        R                  " U TR
                  [        TSS5      [        5       5      $ )Nminikube_profileminikube_vm_driverrT   )IsSpecifiedr   r
   DEFAULT_CLUSTER_NAMEMinikubestop_clusterrv   r,   )cluster_namerl   s    r%   r   *Dev._GetKubernetesEngine.<locals>.Minikube   sZ    			,	-	-,,!66  t/@/@!(/CX!N!)- -r$   r   )r   )rl   r   r   s   `  r%   r|   Dev._GetKubernetesEngine   s1    B- ''ZZr$   c              #      #    U (       a$  [         R                  " X5         Sv   SSS5        gSv   g! , (       d  f       g= f7f)zCreate and destory a kubernetes namespace if one is specified.

Args:
  namespace_name: Namespace name.
  context_name: Kubernetes context name.

Yields:
  None
N)r
   KubeNamespace)namespace_namer~   s     r%   r}   Dev._WithKubeNamespace	  s2      ##NA BA  BAs   A3A
AAr   N)r   r   r    r!   r"   detailed_helpclassmethodrc   rm   rj   ri   r   r   staticmethodr|   
contextlibcontextmanagerr}   r#   r   r$   r%   rJ   rJ   b   sz    D-< #+ #+J0(2)  8   r$   rJ   c                      [         R                  " S5      n U (       d  [        S5      e [        R                  " U S/S[        5       S9  g! [        R                   a    [        S5      ef = f)zMake sure docker is running.rT   zWCannot locate docker on $PATH. Install docker from https://docs.docker.com/get-docker/.info   )timeout_secshow_outputzIUnable to reach docker daemon. Make sure docker is running and reachable.N)
file_utilsFindExecutableOnPathr   r   rm   r,   
subprocessCalledProcessError)rT   s    r%   rw   rw     sn    **84&	
'	/0 0 'RXZP		&	& 
'	 s    A  A+c                 T   [         R                  " 5       R                  (       d  gS/nU R                  S5      (       a#  UR	                  S5        UR	                  S5        O(U R                  S5      (       a  OUR	                  S5        [        R                  R                  U5        g)z4Make sure the components needed later are installed.Nr   r   zcloud-run-proxyzlog-streamingr   minikube)	r   Pathssdk_rootrh   appendr   r   UpdateManagerEnsureInstalledAndRestart)rl   
componentss     r%   rf   rf   .  s    		 	  |*	g&&'(o&''

#88Dr$   c                     S[         R                  " 5       0nU R                  S5      (       a  O[        R                  " 5       US'   [        UR                  5       5       H  u  p#[        U< SU< S35        M     g)z.Print the version strings of the dependencies.r   r   r   z: 
N)r   
GetVersionr   r
   GetMinikubeVersionsorteditemsprint)rl   dependency_versionsr@   versions       r%   rg   rg   B  sf    #X%8%8%:;	n%%&0&C&C&E
#1779:md	g
&' ;r$   )4r"   
__future__r   r   r   r   r   r   googlecloudsdk.callioper   googlecloudsdk.command_lib.coder   r	   r
   r   r   r   r   r   %googlecloudsdk.command_lib.code.cloudr   r   r   r   googlecloudsdk.corer   r   r   r   googlecloudsdk.core.updaterr   googlecloudsdk.core.utilr   r   rz   rs   Errorr   r,   r7   r;   r   rH   ReleaseTracksrY   BETAr]   CommandrJ   rw   rf   rg   r   r$   r%   <module>r      s    ; &  % '   ( D 1 6 1 7 : 4 7 C 7 = : & * * $ 6 8  
)J$4$4 );
 " "2 D%%**D,=,=,C,CDv$,, v Evr$E(
(r$   