
    +                        S 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r\R>                  " \R@                  RB                  \R@                  RD                  5      \RF                   " S S\RH                  5      5       5       r%g)z@Command for deploying containers from Compose file to Cloud Run.    N)api_enabler)base)docker_util)util)artifact_registry)
exceptions)flags)pretty_print)up)compose_resource)
exit_codes)tracker)config)log)metrics)
properties)progress_trackerzcloud-run-source-deployc                   l    \ rS rSrSrSSS.r\S 5       r\S 5       rS r	S	 r
S
 rS rS rS rS rSrg)Up*   z/Deploy to Cloud Run from compose specification.z"          {description}
          z          To deploy a container from the source Compose file on Cloud Run:

              $ {command} compose.yaml

          To deploy to Cloud Run with unauthenticated access:

              $ {command} compose.yaml --allow-unauthenticated
         )DESCRIPTIONEXAMPLESc                    [         R                  " U 5        [         R                  " U 5        [         R                  " U 5        [         R                  " U 5        U R                  5       nUR                  SSSS9  UR                  SSSS9  g )Nz
--no-build
store_truez(Skip building from source if applicable.)actionhelpz--buildzForce build of images.)r	   AddDeployFromComposeArgumentAddRegionArgAddDryRunFlagAddAllowUnauthenticatedFlagadd_mutually_exclusive_groupadd_argument)parserbuild_groups     lib/surface/run/compose/up.py
CommonArgsUp.CommonArgs>   s    	&&v.	v		%%f-557K7  
 %      c                 .    [         R                  U 5        g )N)r   r&   )r#   s    r%   ArgsUp.ArgsP   s    MM&r(   c           	      	   U R                  5       n[        R                  " 5       R                  n[        R
                  R                  USSS5      n	U" SUUU	S9n
SnU
R                  (       d  U
R                  (       a.  [        U
R                  [        5      (       a  U
R                  S   n[        R                  " [        R                  R                  R                  R!                  5       SU5        ["        R$                  " XR&                  5      e [(        R*                  R-                  U
R                  S	   5      n[.        R0                  " S
5        [.        R0                  " SU 35        UR2                  (       d#  ["        R4                  " S[6        R8                  S9e[        R                  R:                  R2                  R!                  SS9nUR=                  UR>                  5      nU(       a  [@        RB                  " X5        [D        RF                  " SU RI                  U5      SSSS9 nURK                  XSXR>                  URL                  S9n[.        R0                  " SU5        SSS5        WRO                  5       nU" SUUUUU	S9nUR                  (       Ga  [(        RP                  R-                  UR                  S	   5      n[.        R0                  " S5        [.        R0                  " S[        URR                  RU                  5       5      [        URV                  RU                  5       5      -    35        URV                  RU                  5        H  n[(        RX                  " UUUUS9  M     URR                  RU                  5        H  n[(        RX                  " UUUUS9  M     U$ UR                  (       a.  [        UR                  [        5      (       a  UR                  S   n[        R                  " [        R                  R                  R                  R!                  5       SU5        ["        R$                  " UUR&                  5      e! , (       d  f       GN= f! ["        RZ                   a    e [\         aW  n[.        R0                  " SU
R                   35        ["        R4                  " [_        U5      [6        R`                  5      UeSnAff = f)z-Handles the resource and translate run logic.surfaceruncomposeresource)commandcompose_fileregionoutzFailed to process compose file.resource_errorr   z+Successfully parsed resources config proto.zResourcesConfig:
z3Could not determine project name from compose file.	exit_codeTrequiredzSetting up resources...zSetup failedFzResource setup complete.)failure_messagesuppress_outputsuccess_message)no_buildbuildzHandled ResourcesConfig:
%sN	translate)r1   r2   resources_configproject_numberr3   r4   z1Successfully translated resources config to YAML.zYAML files:
)yaml_file_pathr3   argsrelease_tracktranslate_errorzRaw output: )1ReleaseTrackr   Pathsglobal_config_dirospathjoinstdoutstderr
isinstancelistr   CustomKeyValuer   VALUEScommand_nameGetcompose_exceptionsGoBinaryErrorr8   r   ResourcesConfig	from_jsonr   debugprojectGcloudErrorr   PROJECT_NAME_MISSINGcoreget_required_apisr>   r   check_and_enable_apisr   StagedProgressTracker_AddTrackerStageshandle_resourcesr?   to_jsonTranslateResultservicesvaluesmodelsdeploy_applicationComposeError	ExceptionstrUNKNOWN_ERROR)selfcommand_executorr2   reporB   r3   rD   rE   cfg_dirout_dirresource_responseerror_message
config_obj
project_idrequired_apisr   rA   resources_config_jsonresponsetranslate_result
model_yamlservice_yamles                          r%   _ResourceAndTranslateRunUp._ResourceAndTranslateRunT   s    %%'Mlln..G ggll7Iui@G(!	 6M## 
	!	!j

"
"D' ' *004



#
#
0
0
4
4
6


 ,,
44 T#33==

"
"1
%j 
ii=>	ii$ZL12 ,,A 55
 	

 $$))1155t5Dj 224==Am	))*D11
#

 
 
,(4 %66'MM 7 
 			02BC /668!#0'h 
+;;EEOOA
 			EF		$--4467$?O?V?V?]?]?_:``ac	
 +1188:J

-
-')	 ; -55<<>L

-
-))	 ?& o ??z(//4@@"//"--%%22668	

 !..8--
 	
m v **  	ii,07789:**
a&***s:   DQ3 5=Q!2EQ3 9B(Q3 !
Q0+Q3 3S(AS##S(c                    [         R                  R                  S5         [        R                  " USS9nU R                  U5         [
        R                  R                  R                  R!                  SS9n[$        R&                  " U5      nU R)                  UU5      n[*        R,                  " UU[.        S9n[0        R2                  " USSS9(       a  U R5                  U5        [6        R8                  " 5       nUR:                  (       a  UR:                  n	OU R=                  5       n	U R?                  XXeX!5      n
U
$ ! [
        R                   a3  n[        R                  " [        U5      [        R                  5      eSnAff = f! [
        R                   a3  n[        R                  " [        U5      [        R"                  5      eSnAff = f)z=Deploy a container from the source Compose file to Cloud Run.z&Deploying from Compose to Cloud Run...T)promptNr9   )ru   location_idrepo_id)skip_activation_promptskip_console_prompt) r   statusPrintr	   	GetRegionr   RequiredPropertyErrorrU   r[   rk   r   REGION_NOT_SET_SetRegionConfigrR   r]   rZ   rT   PROJECT_NOT_SETprojects_utilGetProjectNumber_GenerateRepositoryNamer   
DockerRepoDEFAULT_REPO_NAMEr   ShouldCreateRepository_CreateARRepositoryr   RunComposeWrapperr2   _GetComposeFiler}   )rm   rD   r3   r|   rZ   rB   ro   docker_reporn   r2   rx   s              r%   RunUp.Run   s   JJ=>tD1f
 	&!!!&&..22D2Ag
 #33G<N''D ((!K //Dd {+++-&&l))+l,,fH OI ++ **
a&*++  ++ **
a&*,, s/   D? 1F	 ?F.FF	G.GGc                 p    SR                  U5      nSR                  X1R                  SS5      [        5      $ )z#Generate a name for the repository.z{}-docker.pkg.devz{}/{}/{}:/)formatreplacer   )rm   rZ   r3   
repositorys       r%   r   Up._GenerateRepositoryName   s6    $++F3JOOC-/@ r(   c                 2   [         R                  R                  R                  R	                  5       (       d`  [
        R                  R                  SR                  US95        [         R                  R                  R                  R                  U5        gg)zSet the region config.z]Region set to {region}.You can change the region with gcloud config set run/region {region}.
)r3   N)
r   rR   r.   r3   rT   r   r   r   r   Set)rm   r3   s     r%   r   Up._SetRegionConfig   sm      ''++--	jj//5vVv/D ""&&v. .r(   c                     S H+  n[         R                  R                  U5      (       d  M)  Us  $    [        R                  " S[
        R                  S9e)N)zcompose.yamlzcompose.ymlzdocker-compose.yamlzdocker-compose.ymlz5No compose file found. Please provide a compose file.r7   )rJ   rK   existsr   ConfigurationErrorr   COMPOSE_FILE_NOT_FOUND)rm   filenames     r%   r   Up._GetComposeFile  sI     
	!	! 
'
'?33 r(   c                 t    [         R                  " SUR                   35        [        R                  " USS9  g)z6Create an Artifact Registry Repository if not present.z&Creating AR Repository in the region: T)r   N)r
   Successlocationr   CreateRepository)rm   r   s     r%   r   Up._CreateARRepository  s3    
01E1E0FG &&{4Pr(   c           
      X   / nUR                   (       a`  UR                    HP  nUR                  [        R                  " SU S3[        R
                  R                  R                  US9S95        MR     UR                  (       aJ  UR                  [        R                  " S[        R
                  R                  R                  5       S95        UR                  R                  (       d  UR                  R                  (       aJ  UR                  [        R                  " S[        R
                  R                  R                  5       S95        UR                  (       aJ  UR                  [        R                  " S[        R
                  R                  R                  5       S95        U$ )z&Add a tracker to the progress tracker.zBuilding container z from source...)	container)keyzCreating secrets...zCreating volumes...zCreating configs...)source_buildsappendr   StagestagesStagedProgressTrackerStageBUILDget_keysecretsSECRETSvolumes
bind_mountnamed_volumeVOLUMESconfigsCONFIGS)rm   cfgstaged_operationscontainer_names       r%   ra   Up._AddTrackerStages  sG   
--.  ""%n%5_E55;;CC, D 	
 . {{

 
 #33;;CCE {{!9!9

 
 #33;;CCE {{

 
 #33;;CCE r(    N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr&   r*   r}   r   r   r   r   r   ra   __static_attributes__r   r(   r%   r   r   *   sg     8	-  "  tl)V/Q"r(   r   )&r   rJ   googlecloudsdk.api_lib.runr   googlecloudsdk.callioper   $googlecloudsdk.command_lib.artifactsr   #googlecloudsdk.command_lib.projectsr   r   googlecloudsdk.command_lib.runr   r   r	   r
   r   &googlecloudsdk.command_lib.run.composer   rU   r   r   r   googlecloudsdk.corer   r   r   r   googlecloudsdk.core.consoler   r   ReleaseTracksrG   ALPHABETADefaultUniverseOnlyBinaryBackedCommandr   r   r(   r%   <module>r      s    G 	 2 ( < E < 5 0 7 - C S = D & # ' * 8 .  D%%++T->->-C-CDP	!	! P  EPr(   