
    ,                        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[        R                  " 5       [        R                  R                  :*  UR                  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.                  " XR0                  5      e [2        R4                  R7                  U
R                  S	   5      n[        R8                  " S
5        [        R8                  " SU 35        UR:                  (       d#  [,        R<                  " S[>        R@                  S9e[$        R&                  RB                  R:                  R+                  SS9nURE                  URF                  5      nU(       a  [H        RJ                  " X5        [L        RN                  " SU RQ                  U5      SSSS9 nURS                  XSXRF                  URT                  S9n[        R8                  " SU5        SSS5        WRW                  5       nU" SUUU[        R                  " 5       [        R                  R                  :*  UR                  UUU	S9	nUR                  (       Ga  [2        RX                  R7                  UR                  S	   5      n[        R8                  " S5        [        R8                  " S[        URZ                  R]                  5       5      [        UR^                  R]                  5       5      -    35        UR^                  R]                  5        H  n[2        R`                  " UUUUS9  M     URZ                  R]                  5        H  n[2        R`                  " 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R0                  5      e! , (       d  f       GN1= f! [b         aW  n[        R8                  " SU
R                   35        [,        R<                  " [e        U5      [>        Rf                  5      UeSnAff = f)z-Handles the resource and translate run logic.surfaceruncomposeresource)commandcompose_filedebugdry_run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   repor2   resources_configr3   r4   project_numberr5   r6   z1Successfully translated resources config to YAML.zYAML files:
)yaml_file_pathr5   argsrelease_tracktranslate_errorzRaw output: )4ReleaseTrackr   Pathsglobal_config_dirospathjoinr   GetVerbosityloggingDEBUGr4   stdoutstderr
isinstancelistr   CustomKeyValuer   VALUEScommand_nameGetcompose_exceptionsGoBinaryErrorr:   r   ResourcesConfig	from_jsonr3   projectGcloudErrorr   PROJECT_NAME_MISSINGcoreget_required_apisr@   r   check_and_enable_apisr   StagedProgressTracker_AddTrackerStageshandle_resourcesrA   to_jsonTranslateResultservicesvaluesmodelsdeploy_application	ExceptionstrUNKNOWN_ERROR)selfcommand_executorr2   rC   rE   r5   rG   rH   cfg_dirout_dirresource_responseerror_message
config_obj
project_idrequired_apisr   rD   resources_config_jsonresponsetranslate_result
model_yamlservice_yamles                          r%   _ResourceAndTranslateRunUp._ResourceAndTranslateRunT   sU    %%'Mlln..G ggll7Iui@G(! CKK$5$55 6M## 
	!	!j

"
"D' ' *004



#
#
0
0
4
4
6


 ,,
44 U#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  "ckk&7&77,,'
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--
 	
s |  	ii,07789:**
a&***s:   DS( /=S,FS( .B(S( 
S% S( (
U	2AUU	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)promptNr;   )rx   location_idrepo_id)skip_activation_promptskip_console_prompt) r   statusPrintr	   	GetRegionr   RequiredPropertyErrorr[   r`   ro   r   REGION_NOT_SET_SetRegionConfigrX   rb   r_   rZ   PROJECT_NOT_SETprojects_utilGetProjectNumber_GenerateRepositoryNamer   
DockerRepoDEFAULT_REPO_NAMEr   ShouldCreateRepository_CreateARRepositoryr   RunComposeWrapperr2   _GetComposeFiler   )rq   rG   r5   r   r_   rE   rC   docker_reporr   r2   r{   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   )rq   r_   r5   
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}.
)r5   N)
r   rX   r.   r5   rZ   r   r   r   r   Set)rq   r5   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.r9   )rM   rN   existsr   ConfigurationErrorr   COMPOSE_FILE_NOT_FOUND)rq   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)rq   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)rq   cfgstaged_operationscontainer_names       r%   rf   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   rf   __static_attributes__r   r(   r%   r   r   *   sg     8	-  "  wr)V/Q"r(   r   )&r   rM   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   r[   r   r   r   googlecloudsdk.corer   r   r   r   googlecloudsdk.core.consoler   r   ReleaseTracksrJ   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S	!	! S  ESr(   