
                            S r SSKrSSKrSSK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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+Sr, " S S \RZ                  5      r.\R^                  R`                  4S! jr1\Rd                  \Rf                  " \R^                  R`                  5       " S" S#\Rh                  5      5       5       r5S$ r6S% r7S& r8S' r9S( r:S) r;S* r<S+ r=\Rf                  " \R^                  R|                  5       " S, S-\55      5       r?\Rf                  " \R^                  R                  5       " S. S/\?5      5       rA\5R                   \Al         g)0 Deploy a container to Cloud Run.    N)api_enabler)
k8s_object)service)traffic)base)
exceptions)docker_util)artifact_registry)
build_util)config_changes)connection_context)container_parser)flags)messages_util)	platforms)pretty_print)resource_args)resource_change_validators)serverless_operations)stages)map_util)concept_parsers)presentation_specs)
properties)
console_io)progress_trackerzproject.tomlE2_HIGHCPU_8c                       \ rS rSrSrSrSrg)	BuildType7   
Dockerfile
Buildpacks N)__name__
__module____qualname____firstlineno__
DOCKERFILE
BUILDPACKS__static_attributes__r$       lib/surface/run/deploy.pyr    r    7   s    **r,   r    c                    Sn[         R                  " US9nUR                  [        R                  " 5       5        UR                  [        R
                  " 5       5        UR                  [        R                  " U 5      5        UR                  [        R                  " 5       5        UR                  [        R                  " 5       5        UR                  [        R                  " 5       5        UR                  [        R                  " 5       5        UR                  [        R                  " 5       5        UR                  [        R                  " 5       5        UR                  [        R                  " 5       5        UR                  [        R                  " 5       5        UR                  [        R                  " 5       5        UR                  [        R                   " 5       5        UR                  [        R"                  " 5       5        UR                  [        R$                  " 5       5        UR                  [        R&                  " 5       5        UR                  [        R(                  " 5       5        UR                  [        R*                  " SU S95        UR                  [        R,                  " 5       5        UR                  [        R.                  " 5       5        UR                  [        R0                  " 5       5        U$ )z=Returns an argument group with all per-container deploy args.z
Container Flags

The following flags apply to a single container. If the --container flag is
specified these flags may only be specified after a --container flag. Otherwise
they will apply to the primary ingress container.
)helpF)mutexrelease_track)r   ArgumentGroupAddArgumentr   PortArg	Http2FlagMutexEnvVarsFlags
MemoryFlagCpuFlagArgsFlagSecretsFlagsDependsOnFlagAddVolumeMountFlagRemoveVolumeMountFlagClearVolumeMountsFlagAddCommandAndFunctionFlagBaseImageArgAutomaticUpdatesFlagBuildServiceAccountMutexGroupBuildWorkerPoolMutexGroupMutexBuildEnvVarsFlagsSourceAndImageFlagsStartupProbeFlagLivenessProbeFlagGpuFlag)r1   	help_textgroups      r-   ContainerArgGrouprK   <   s   ) 

)
,%EMMO$EOO%&E++M:;E$$&'EMMO$ENN$%E&&()E'')*E,,./E//12E//12E3356E&&()E..01E779:E3356E0023e=I E**,-E++-.EMMO$	,r,   c                       \ 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S rS rS rS rS rS rS rS rS rS rS rS rS rSrg)Deployc   %Create or update a Cloud Run service.z<          Creates or updates a Cloud Run service.
          a            To deploy a container to the service `my-backend` on Cloud Run:

              $ {command} my-backend --image=us-docker.pkg.dev/project/image

          You may also omit the service name. Then a prompt will be displayed
          with a suggested default value:

              $ {command} --image=us-docker.pkg.dev/project/image

          To deploy to Cloud Run on Kubernetes Engine, you need to specify a cluster:

              $ {command} --image=us-docker.pkg.dev/project/image --cluster=my-cluster
          )DESCRIPTIONEXAMPLESc                    [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R
                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                  " U5        [         R                   " U5        [         R"                  " U5        [         R$                  " U5        [         R&                  " U5        [         R(                  " U5        [         R*                  " U5        [         R,                  " U5        [         R.                  " 5       R1                  U5        [         R2                  " XR5                  5       5        [         R6                  " U5        [         R8                  " U5        [         R:                  " U5        [         R<                  " U5        [         R>                  R1                  U5        [@        RB                  " S[D        RF                  " SS9SSSS9n[         RH                  " U5        [         RJ                  " U5        [         RL                  " U5        [         RN                  " U5        [         RP                  " U5        [         RR                  " U5        [         RT                  " U5        [         RV                  " U5        [         RX                  " U5        [         RZ                  " U5        [         R\                  " U5        [         R^                  " U5        [         R`                  " U5        [         Rb                  " U5        [d        Rf                  " U/5      R1                  U5        URh                  Rk                  S5        g )NSERVICET)promptzService to deploy to.F)requiredprefixesnone)6r   AddAllowUnauthenticatedFlagAddAllowUnencryptedBuildFlagAddBinAuthzPolicyFlagsAddBinAuthzBreakglassFlagAddCloudSQLFlagsAddCmekKeyFlag"AddCmekKeyRevocationActionTypeFlagAddCpuThrottlingFlagAddCustomAudiencesFlagAddDefaultUrlFlagAddDeployHealthCheckFlagAddDescriptionFlagAddEgressSettingsFlag!AddEncryptionKeyShutdownHoursFlagAddGpuTypeFlagGpuZonalRedundancyFlagAddRevisionSuffixArgAddSandboxArgAddSessionAffinityFlagAddStartupCpuBoostFlagAddVpcConnectorArgs AddVpcNetworkGroupFlagsForUpdateRemoveContainersFlagAddToParserAddVolumesFlagsReleaseTrackAddServiceMinMaxInstancesFlagAddInvokerIamCheckFlagAddScalingFlagAddEndpointVisibilityEnumCONFIG_MAP_FLAGSr   ResourcePresentationSpecr   GetServiceResourceSpecAddPlatformAndLocationFlagsAddConcurrencyFlagAddTimeoutFlagAddAsyncFlagAddLabelsFlagsAddGeneralAnnotationFlagsAddMinInstancesFlagAddMaxInstancesFlagAddNoTrafficFlagAddDeployTagFlagAddServiceAccountFlagAddClientNameAndVersionFlagsAddIngressFlagAddRegionsArgr   ConceptParserdisplay_info	AddFormat)clsparserservice_presentations      r-   
CommonArgsDeploy.CommonArgs|   s   	%%f-	&&v.	  (	##F+	6"	 	,,V4	v&	  (	F#	""6*	V$	'	++F3	 	  (	v&		  (	  (	f%	**62	 ,,V4	&"2"2"45	''/	  (	  
##F+	&&v. .FF,,D9 
%%f-	V$	 	v	 	##F+	f%	f%	6"	6"	'	&&v.	 	!!#7"89EEfM
!!&)r,   c                     U R                  U5        [        U R                  5       5      n[        R                  " XU R                  5       5        g N)r   rK   rq   r   AddContainerFlagsr   r   container_argss      r-   ArgsDeploy.Args   s=    NN6&s'7'7'9:N&& 0 0 2r,   c                 P   [         R                  " US5      (       a"  UR                  S   [         R                  ;   a  g[         R                  " US5      (       a"  UR                  S   [         R                  ;   a  gU R                  5       (       a?  [         R                  " UUUU(       + U R                  5       S   S9nU(       d  U(       d  gU$ Sn[        R                  " 5       [        R                  :X  a,  [         R                  " XX4(       + 5      nU(       d	  U(       d  SnU$ )a  Returns allow_unauth value for a service change.

Args:
  args: argparse.Namespace, Command line arguments
  operations: serverless_operations.ServerlessOperations, Serverless client.
  service_ref: protorpc.messages.Message, A resource reference object for
    the service See googlecloudsdk.core.resources.Registry.ParseResourceId
    for details.
  service_exists: True if the service being changed already exists.

Returns:
  allow_unauth value where
  True means to enable unauthenticated access for the service.
  False means to disable unauthenticated access for the service.
  None means to retain the current value for the service.
presetnameFTr   )region_overrideN)r   FlagIsExplicitlySetr   PRIVATE_ACCESS_PRESETSPUBLIC_ACCESS_PRESETS_IsMultiRegionGetAllowUnauthenticated_GetRegionsForMultiRegionr   GetPlatformPLATFORM_MANAGED)selfargs
operationsservice_refservice_existsallow_unauths         r-   GetAllowUnauthDeploy.GetAllowUnauth   s    $ 	!!$11KK5#?#??!!$11KK5#>#>>22



88:1=l LL)"<"<<22
K);l
 Lr,   c                    [         R                  " US5      (       a  UR                  n[         R                  " US5      (       a  UR                  S   [         R                  ;   at  [        X!R                  S      S5      nSUS'   [        X!R                  S      SU5        [        X!R                  S      SS5        [        X!R                  S      SS 5        OS	U0n[        U5      S
:  at  UR                  5        Vs/ s H3  nUR                  S5      (       d  UR                  S5      (       d  M1  UPM5     nn[        U5      S
:w  a  [        R                  " SS5      e[        U5      S:  a  [        R                  " SS5      eU$ s  snf )N
containersr   r   _specified_args--imageimageimageplaceholderautomatic_updates    port	use_http2--containerz8Exactly one container must specify --port or --use-http2
   z*Services may include at most 10 containers)r   r   r   r   INGRESS_CONTAINER_PRESETSgetattrsetattrlenvaluesIsSpecifiedc_exceptionsInvalidArgumentException)r   r   r   specified_argscingress_containerss         r-   _ValidateAndGetContainers Deploy._ValidateAndGetContainers   sz     |44??j 
#
#D(
3
3kk&!U%D%DD {{6*+->
 #,w{{6*+->	
 	
;;v./:LM
;;v./1DdK:j
: $$&&a]]6""ammK&@ &  
 
	 A	%33F
 	

 :11
E  s    0F
4F
c                     UR                  5        H9  u  p4X1;  d  M  UR                  S5      (       d  M$  [        R                  " SS5      e   g )Nr   --automatic-updatesS--automatic-updates can only be specified in the container that builds from source.itemsr   r   r   r   deploy_from_sourcer   r   	containers        r-   (_ValidateNoAutomaticUpdatesForContainers/Deploy._ValidateNoAutomaticUpdatesForContainers  sQ     &++-		'I,A,A
- - 33!#
 	
	 .r,   c                 X   UR                  5        VVs0 s H;  u  p#UR                  S5      (       a  [        R                  " US5      (       d  M9  X#_M=     nnn[	        U5      S:  av  UR                  5        VVs/ s H%  u  p#[        R                  " US5      (       a  M#  UPM'     nnnU(       a  [
        R                  " U5      e[        R                  " SS5      eU R                  XA5        UR                  5        H  u  p#[        R                  " US5      (       a  M#  [        R                  " 5       (       a  [        R                  " U5      Ul        MZ  U(       a  SR                  U5      nOSn[        R                  " SU5      e   U R!                  U5        U$ s  snnf s  snnf )	Nr   sourcer   r   z2At most one container can be deployed from source.zwContainer {} requires a container image to deploy (e.g. `gcr.io/cloudrun/hello:latest`) if no build source is provided.zjRequires a container image to deploy (e.g. `gcr.io/cloudrun/hello:latest`) if no build source is provided.r   )r   r   r   r   r   r	   RequiredImageArgumentExceptionr   r   r   r   	CanPromptPromptForDefaultSourcer   formatRequiredArgumentException_ValidateNoBuildFromSource)r   r   r   r   r   needs_imagemessages          r-   _ValidateAndGeDeployFromSource%Deploy._ValidateAndGeDeployFromSource'  s     *//11OD%%g..((H=	 	1   " "4!9!9!;!;od**9h? !;  
 
77DD11
M  	11 .335&&y(;;!!"99$?)
#VD\  
 66 # 6* 	##$67Ys   8F F ;"F&!F&c                    [        U R                  5       U5      (       d  g[        [        UR	                  5       5      5      S   nUR                  S5      (       d  [        R                  " SS5      eUR                  S5      (       d  [        R                  " SS5      eUR                  S5      (       a(  [        US5      S	:w  a  [        R                  " S
S5      egg)zExtra validation for Zip deployments.

This is a no-op for if the --no-build flag is not set.

Args:
  deploy_from_source: The build from source map of container name to
    container object.
Nr   
base_imagez
--no-buildzESource deployment must specify --base-image when skippingCloud Build.commandzCSource deployment must specify --command when skipping Cloud Build.r   scratchr   zLSource deployment --image must be set to "scratch" when skippingCloud Build.)	_IsNoBuildFromSourcerq   nextiterr   r   r   r   r   )r   r   r   s      r-   r   !Deploy._ValidateNoBuildFromSourceV  s       1 1 35GHH T,22456q9I  ..11
 
   ++11

O 
 	g&&Iw'9411
  5 	'r,   c                     [        USS5      n[        USS5      nU(       a  U$ UcE  UbB  [        R                  UR                  ;   a$  U(       d  UR                  [        R                     $ [        R                  $ )zReturns the base image for the container.

Args:
  container_args: command line arguments for container that is build from
    source
  service: existing Cloud run service which could be None.

Returns:
  base_image: string. Base image of the container.
r   Nclear_base_image)r   service_libRUN_FUNCTIONS_BUILD_BASE_IMAGEannotationsDEFAULT_BASE_IMAGE)r   r   r   r   r   s        r-   _GetBaseImageForSourceContainer&Deploy._GetBaseImageForSourceContainerz  ss     t<J~/A4H 	66':M:MM   !K!KLL)))r,   c                    [        USS5      n[        USS5      nU R                  X5      nUb  U$ U(       a  gUc  U[        R                  :g  $ [        R                  UR
                  ;   a5  UR
                  [        R                     nUR                  5       S:X  a  S$ S$ [        R                  UR
                  ;   a5  UR
                  [        R                     nUR                  5       S:X  a  S$ S$ U$ )z0Returns the automatic updates for the container.r   Nr   FtrueT)r   r   r   r   ,RUN_FUNCTIONS_BUILD_ENABLE_AUTOMATIC_UPDATESr   lower1RUN_FUNCTIONS_ENABLE_AUTOMATIC_UPDATES_DEPRECATED)r   r   r   r   r   r   automatic_updates_annotations          r-   _GetAutomaticUpdatesDeploy._GetAutomaticUpdates  s   0CTJ~/A4H55nNJ$ ;9999 	@@	 &-%8%8

B
B&" 2779VCTNNEE	 &-%8%8

G
G&" 2779VCTNNr,   c                 "   [        USS5      n[        USS5      nUb  US:X  a  gUc  Ub  [        $ Ub\  [        R                  UR                  R
                  ;   a4  UR                  R
                  [        R                     nU(       a  [        $ g)a}  Gets the default pool build machine type to use based on the user flags and annotations.

User flags take precedence over annotations for an existing service.

Args:
  container_args: base.ArgumentGroup, Container arguments using source
    build.
  service: Service, existing Cloud run service.

Returns:
  build_machine_type or
  None meaning default machine type should be used
gpu_typeNgpu0)r   _GPU_BUILD_MACHINE_TYPEr   GPU_TYPE_NODE_SELECTORtemplatenode_selector)r   r   r   r   	gpu_countaccelerator_values         r-   _GetMachineTypeDeploy._GetMachineType  s     ~z48Ht4Ic!1y4$$		*	*g.>.>.L.L	L#,,::--
 (
(r,   c                    U(       a  UR                   OSu  nn	n
n[        [        UR                  5       5      5      u  pU(       d0  U(       a)  UR                  R
                  R                  =(       d    SnS n/ nUR                  nU(       a  U R                  UR                  5      OS n[        R                  " SU5        UR                  nU R                  UUUUUUU5      u  nnSR                  UUR                  S9Ul        US-   nU R#                  X5      nU R%                  X5      nU R'                  X5      n[(        R*                  R-                  U5      (       ao  [.        R0                  n[2        R4                  " US5      (       a  [6        R8                  " SS	5      eU[:        R<                  :w  a  [6        R>                  " S
S5      eO[A        U5      u  p[.        RB                  nU(       a  S OUR                   n[2        R4                  " US5      (       d  Ub1  U[:        R<                  :w  a  U(       a  US   RE                  S5      OUn[G        XXU5      nSR                  URH                  S9n[K        XX5      nU
(       a  [L        RN                  " U
5      OS n[P        RR                  " SU5      n[P        RT                  " U40 UD6n UUUUUUUUUUUUU UU4$ )N)NNNNr   zExisting source_bucket: %sz{repo}/{service})repor   z/Dockerfiler   z--base-imagez?Base image is not supported for services built from Dockerfile.z--clear-base-imagezBase image is not supported for services built from Dockerfile. To continue the deployment, please use --clear-base-image to clear the base image.delegate_buildsr   r   z6Building using {build_type} and deploying container to)
build_typezbuild-env-vars)+run_functions_annotationsr   r   r   r   r   r   r   '_GetSourceBucketFromBuildSourceLocationsource_locationloggingdebugfunction_GetArtifactRegistryRepositoryr   
servicesIdr   r   r   r   ospathexistsr    r)   r   r   r   r   r   r   r   _CreateBuildPackr*   get_GetBuildServiceAccountvalue_GetBuildWorkerPooljsonloadsr   GetMapFlagsFromArgsApplyMapFlags)!r   r   build_from_sourcer   conn_contextplatformalready_activated_servicesr   annotated_build_service_accountannotated_build_worker_poolannotated_build_env_varsannotated_build_image_urir   r   packchangesr   source_bucketis_functiondocker_stringrepo_to_createdocker_filer   r   build_machine_typer  r   build_service_accountoperation_messagebuild_worker_poolold_build_env_varsbuild_env_var_flagsbuild_env_varss!                                    r-   _BuildFromSourceDeploy._BuildFromSource  s   $  	))%'# !  %6%<%<%> ?@DG'',,2dDG""F  	44W5L5LM 
 MM.> !))K %)$G$G"!%!M> .44K$:$: 5 N =(K55nNJ11.J--nF	ww~~k""''j 
	"	"><	@	@33M
 	
 
{55	544 
 	
 
6 '~6md''jDn22E  '899:1O1O#O&*d1gkk'"e3~ 	Af
((f)  ,7
 $ 	

+, 
 #667GN++1N 	 r,   c                    SnUR                   (       a9  [        UR                   U5      n	[        UR                   UR                  5        X4$ U(       a  [        Xd5      n	X4$ [        R
                  " [        R                  R                  R                  R                  SS9[        R                  " UU[        R                  :X  a  UR                  OSS9SS9n
[        R                   " XS9(       a  U
nU
R#                  5       n	X4$ )a  Gets the AR repo from flags or annotations if they exist, otherwise return the repository to create.

Args:
  args: argparse.Namespace, Command line arguments
  conn_context: ConnectionInfo object, context to get project location.
  platform: properties.VALUES.run.platform, platform to run on and to check
    if it is GKE.
  already_activated_services: bool, True if the user has already activated
    the required APIs.
  container_args: base.ArgumentGroup, Container arguments using source
    build.
  annotated_build_image_uri: str, build image uri from service annotations.
  service_ref: ServiceRef, reference to the existing Cloud run service.

Returns:
  A string location of the AR repository and the docker_util.DockerRepo
  object to create by default if none provided.
NTrU   )cluster_locationzcloud-run-source-deploy
project_idlocation_idrepo_id)skip_activation_prompt)r   _ValidateArRepository_ValidateServiceNameFromImager	  r
   
DockerRepor   VALUEScoreprojectGetr   
RepoRegionr   PLATFORM_GKEr0  ShouldCreateRepositoryGetDockerString)r   r   r  r  r  r   r  r   r#  r"  ar_repos              r-   r  %Deploy._GetArtifactRegistryRepository[  s   8 N+


 :m $


 6 6 **	"+
#m **&&&&++33777F'22 !7!77 // ,g 
	1	1

 !--/m((r,   c                 \    U R                   (       a  U R                   R                  S5      $ g )N,)_Deploy__multi_region_regionssplitr   s    r-   r    Deploy._GetRegionsForMultiRegion  s%    ""((..s33r,   c                 ,    [        U R                  5      $ r   )boolrE  rG  s    r-   r   Deploy._IsMultiRegion  s    ++,,r,   c           	      T   U(       d  gUR                   n[        R                  " SU5        U(       d  g [        R                  " U5      n[        U[        5      (       a  [        U5      S:w  a  [        R                  " S5        g[        R                  " S[        [        UR                  5       5      5      5      nU(       a  UR                  S5      $ [        R                  " S5        g! [        R                  [        4 a!  n[        R                  " SU5         SnAgSnAff = f)zReturns the source bucket from the zip deploy source annotation run.googleapis.com/source.

If the annotations has more than one entry, return None.

Args:
  service: existing Cloud run service.
Nzsource_location map: %sr   z=source_location is not a valid map or has more than one entrygs://([^/]+)/.*6source_location does not match pattern gs://([^/]+)/.*z#failed to parse source location: %s)*source_deploy_no_build_source_location_mapr  r  r  r  
isinstancedictr   researchr   r   r   rJ   JSONDecodeError	TypeError)r   r   source_location_mapcontainer_to_source_mapxes         r-   +_GetSourceBucketFromZipDeploySourceLocation2Deploy._GetSourceBucketFromZipDeploySourceLocation  s     !LLMM+-@A $

+> ?0$77()Q.K	
 
))
d4(?(F(F(H#IJa 
wwqzmmLM  ), mm91=s%   AC, AC, C, ,D'D""D'c                     [         R                  " SU5        U(       d  g [        R                  " SU5      nU(       a  UR	                  S5      $ [         R                  " S5        g )Nzsource_location: %srM  r   rN  )r  r  rR  rS  rJ   )r   r  rX  s      r-   r  .Deploy._GetSourceBucketFromBuildSourceLocation  sI    MM'9
		$o6AWWQZMMJKr,   c                    [         R                  " XR                  5       5      nUR                  S[        R
                  " [        R                  5      5        UR                  [        R                  " U R                  5       5      5        U R                  5       (       a-  UR                  [        R                  " U R                  S95        U$ )z>Returns the service config changes with some default settings.r   )regions)r   GetServiceConfigurationChangesrq   insertr   DeleteAnnotationChanger   BINAUTHZ_BREAKGLASS_ANNOTATIONappendSetLaunchStageAnnotationChanger   SetRegionsAnnotationChangerE  )r   r   r  s      r-   _GetBaseChangesDeploy._GetBaseChanges  s    2249J9J9LMGNN	--55	
 NN55d6G6G6IJ nn

3
311 Nr,   c                     [         R                  " U[        R                  R                  U R                  5       U R                  5       S9$ )N)is_multiregion)r   GetConnectionContextr   ProductRUNrq   r   r   r   s     r-   _ConnectionContextDeploy._ConnectionContext  s?     22**,	 r,   c
                 
   [        U5      =(       a    U	(       + n
[        R                  " US LUU
[        U5      U
US LUS LU R                  5       S9nU
(       a  SnOSnUcd  US-  nU R	                  5       (       a  US-  nOUS-  n[
        R                  " US5      (       d#  UR                  [        R                  " SS	95        U R	                  5       (       a  S
nOSnUS-  n[        R                  " UUUUR                  S9$ )N)include_iam_policy_setinclude_routeinclude_validate_serviceinclude_upload_sourceinclude_buildinclude_create_repoinclude_iapregions_listzBuilding and deploying	Deployingz newz Multi-Region servicez service	cpu_boostT)r{  zNMulti-region deployment failed. Some regions might already be serving traffic.zDeployment failedz...)failure_messagesuppress_output)rJ  r   ServiceStagesr   r   r   r   rd  r   StartupCpuBoostChanger   StagedProgressTrackerasync_)r   r   r   r  r  r#  r   
has_latestiap
skip_buildrequires_builddeployment_stagesheaderr|  s                 r-   _GetTrackerDeploy._GetTracker  s    +,?ZN,,+47 !/"#45$*$6tO335	 'fff					))*&&t[99~;;dKL 
 ,o
eOF11'	 r,   c                     [         R                  " 5       /nU(       a)  U(       d"  UR                  S5        UR                  S5        U$ )Nzartifactregistry.googleapis.comzcloudbuild.googleapis.com)r   get_run_apird  )r   r   is_no_build_from_sourceapiss       r-   _GetRequiredApisDeploy._GetRequiredApis"  s8    ##%&D"9
kk34
kk-.Kr,   c                    U R                  5       (       aJ  UR                  (       d9  [        R                  " [        R
                  " XR                  5       5      5        g UR                  (       a.  [        R                  " SR                  UR                  S95        g [        R                  " [        R                  " XR                  5      5        g )Nz>Service [{{bold}}{serv}{{reset}}] is deploying asynchronously.)serv)r   r  r   Successr   0GetSuccessMessageForMultiRegionSynchronousDeployr   r   r   %GetSuccessMessageForSynchronousDeploy
no_traffic)r   r   r   s      r-   _DisplaySuccessMessageDeploy._DisplaySuccessMessage)  s    T[[

H
H557
 
"FF5
 

=
=r,   c                 T    [         R                  " US5      (       a  UR                  $ g)z&Returns the IAP status of the service.r  N)r   r   r  rn  s     r-   _GetIapDeploy._GetIap<  s!      u--XXor,   c                 	  ^ ^^^^^^^^^^^^^^^^^^^ ^!^"^#^$ [         R                  " T5      T l        [         R                  " TT R	                  5       [         R
                  R                  5      nT R                  T5      nT R                  U5      m[        T R	                  5       T5      nTR                  R                  R                  5       m![         R                  " T!5        T R                  TU5      nSmU[        R                   :X  aG  ["        R$                  " [&        R(                  R*                  R,                  R/                  5       U5      mT R1                  T5      nSmSmSm#SnSmSnSm[3        TSS5      mSmSmSmSm/ n	SmSmSm$Sm"[4        R6                  " UT5       mTR9                  T!5      m U(       a  SmSm"[;        [=        TR?                  5       5      5      u  mn
T(       d0  T (       a)  T R@                  RB                  RD                  =(       d    SmU
RF                  m#T RI                  T 5      m$SU
l%        OT(       a  T RM                  TTT!UUTT 5      u  nmmm#nmmmn	mmmmmm$[N        RP                  " [&        R(                  R*                  R,                  R/                  SS9[         RR                  " T5      TS	9  T RU                  T5      nURW                  U	5        T RY                  TTT!T 5      m[Z        R\                  " T T5        T (       a  U(       a~  T R@                  RB                  R^                  (       aY  [         R`                  " 5       nU(       a&  URc                  [d        Rf                  " / 5      5        O[h        Rj                  " S
S5      e[l        Rn                  " TT 5        [p        Rr                  " [l        Rt                  " UT!U5      5        T SL =(       d    [v        Rx                  T Rz                  ;   mT R}                  T5      mUUUUUUUUUUUUUUUUUUU U U!U"U#U$4S jn U" U5      m T R                  T T5        T sSSS5        $ ! [~        R                   a\  n[         R                  " T[        U5      5      (       a0  URc                  [d        R                  " SS95        U" U5      m  SnANUeSnAff = f! , (       d  f       g= f)r   FNzDeploying container tokeyr   r   Tr/  )r2  regionr&  z	--commandz
--functionc                  *  > TR                  TTU T
TTTTT5	       nTR                  TU TR                  5       UTR                  TTR	                  5       TTT[
        R                  " T5      TTT[
        R                  " TS5      =(       d    [
        R                  " TS5      [
        R                  " TS5      TTTT	TTT[        R                  R                  R                  R                  5       S:H  TTTTS9sS S S 5        $ ! , (       d  f       g = f)Nrevision_suffixtagr   r  )asynallow_unauthenticatedmultiregion_regionsprefetchbuild_image
build_packbuild_regionbuild_sourcer#  r  generate_namer   r   !deploy_from_source_container_namer&  r(  r%  r+  enable_automatic_updates
is_verboser   kms_keyiap_enabledr  )r  ReleaseServicerq   r  r   r   GetFirstRegionr   r   r9  r:  	verbosityr<  )changes_trackerr   r  r   r   r+  r%  r&  r(  r   r  r  r  r  r   r  r   r  r#  r   r   r   r  r   r   s     r-   _ReleaseService#Deploy.Run.<locals>._ReleaseService  s    

 **!;;$0"&"@"@"B //5!+)C++D2CD <..tU;#77) $0Q$9 1!3+'?#**//99==?7J)#C + "

 

 

s   CD
D)gpu_zonal_redundancy)Er   GetMultiRegionrE  GetAndValidatePlatformrq   rl  rm  r   r   r   CONCEPTSr   ParseValidateResourcer  r   r   r   check_and_enable_apisr   r9  r:  r;  r<  ro  r   r   Connect
GetServicer   r   r   r   r   r   r   rZ  r   r,  r   +ValidateBuildServiceAccountAndPromptWarning	GetRegionrg  extendr   r   ValidateClearVpcConnectorr   PromptForClearCommandrd  r   ContainerCommandChanger   ConflictingArgumentsExceptionr   MaybeLogDefaultGpuTypeMessager   InfoGetStartDeployMessager   LATEST_REVISION_KEYspec_trafficr  r	   	HttpErrorShouldRetryNoZonalRedundancystrGpuZonalRedundancyChanger  )%r   r   r  r   r  required_apisr  r'  r!  build_changesr   r  clear_commandr  rY  r   r  r   r+  r%  r&  r(  r   r  r  r  r  r   r  r   r  r#  r   r   r  r   r   s%   ``             @@@@@@@@@@@@@@@@@@@@@@r-   Run
Deploy.RunB  ss   "'"6"6t"<D++d!5==#4#4H //5J<<ZH2/ --''--/K	;'))3M "'9---#.#D#D



 
 
(
(
,
,
.$  **40LEDF0NKJdE4(G NM(*%#MJ		&	&0
	%%k2g	 
<@#))+,=
9)> 1W((--3 ,  &&HH
  )" !!&
!	
!-$ 	>>!((--559949H??4("7	
 $$T*gnn]#((z;Pl ::7DI	7++55==557-NN>@@DE<< 
 11$@

-
-K): T/
PW88G<P<PP  LLc. . . .`!'* !!'40]
 
D !! 	--dCF;;
..55',
 $G,''	E
 
s>   ,JSQ)S)S=ASSSSS
S*)__multi_region_regionsN)r%   r&   r'   r(   __doc__detailed_helpclassmethodr   r   r   r   r   r   r   r   r   r   r,  r  r   r   rZ  r  rg  ro  r  r  r  r  r  r+   r$   r,   r-   rM   rM   c   s     .	-( 9* 9*v  1f%N
-^"H*8"HB~@<)|
-!F*	2h&{r,   rM   c                     U [         R                  R                  :X  a  gU(       a  [        U5      S:w  a  g[	        [        UR                  5       5      5      S   nUR                  S5      $ )zLChecks if this is a source deployment that should skip the Cloud Build step.Fr   no_build)r   rq   GAr   r   r   r   r   )r1   r  r   s      r-   r   r      s[    d''***	c"3494)//123A6)			z	**r,   c                    Sn[         R                  " X 5      nU(       d  [        R                  " SSU  35      eUR	                  S5      nUR	                  S5      nUR	                  S5      n[
        R                  " UUUS9n[        R                  " UUSS	9(       a  [        R                  " SS
U  S35      eUR                  5       $ )zGChecks the format and existence of the repository in Artifact Registry.z+([\w-]+)-docker\.pkg\.dev/([\w-]+)/([\w-]+)r   zThe artifact repository found for the function was not in the expected format [REGION]-docker.pkg.dev/[PROJECT-ID]/[REPO-NAME] or
[REGION]-docker.pkg.dev/[PROJECT-ID]/[REPO-NAME]/[SERVICE-NAME], please try again. 
Retrieved value was: r         r1  T)r5  skip_console_promptz1The artifact repository provided does not exist: z-. Please create the repository and try again.)
rR  matchr   r   rJ   r
   r8  r   r?  r@  )r  r  image_uri_regexr  r  r2  r4  rA  s           r-   r6  r6    s     C/
((?
>%	

/
/	 
 !::	<  ;;q>&{{1~*KKN'""' --7
 
/
/;$
% &7	7  
	 	 	""r,   c                     Sn[         R                  " X 5      nU(       aK  UR                  S5      (       a4  UR                  S5      U:w  a  [        R                  " SSU  SU S35      eggg)zGChecks the service extracted from the image uri matches the service id.zt(?P<region>[\w-]+)-docker\.pkg\.dev/(?P<project_id>[\w-]+)/(?P<repo_name>[\w-]+)/(?P<service_name>[\w-]+)(?:/(.+))?$service_namer   zAThe service name found in the Artifact Registry repository path, z#, does not match the service name, .N)rR  r  rJ   r   r   )	image_uri
service_idr  r  s       r-   r7  r7  3  s|    C  ((?
.%
++n
%
%
++n
%
3

/
/K+8A	G  4 & r,   c                    SU R                   0/n/ nU R                  nUS-   [        -   n[        U SS5      n[        U SS5      nUb6  SR	                  U5      nUS   R                  SS	R                  US
9/05        O(Ub%  US   R                  SSSR                  US9/05        [        R                  R                  U5      (       a  US   R                  S[        05        X4$ )z'A helper method to configure buildpack.r   /r   Nr   r   envszGOOGLE_ENTRYPOINT="{command}")r   z#GOOGLE_FUNCTION_SIGNATURE_TYPE=httpzGOOGLE_FUNCTION_TARGET={target})targetproject_descriptor)
r   r   _PROJECT_TOML_FILE_NAMEr   joinupdater   r
  r  r  )r   r  r  r   project_toml_filecommand_argfunction_argr   s           r-   r  r  F  s    IOO
$	%$'&sl%<<	9d3+J5,hh{#GGNN	1888IJK GNN1-44L4I
  WW^^%&&GNN(*ABC	r,   c                 0   [        U 5      (       a]  [        R                  nU(       aE  UR                  R	                  U5      (       a%  UR                  [        R                  " U5      5        g[        R                  " U S5      (       a  U R                  $ U$ )a  Gets the build worker pool from user flags and annotations.

Args:
  args: argparse.Namespace, Command line arguments
  annotated_build_worker_pool: Build worker pool value from service
    annotations.
  service: Existing Cloud Run service.
  changes: List of config changes.

Returns:
  build_worker_pool value or
  None meaning clear-worker-pool flag was set
  or build-worker-pool was an empty string.
Nr(  )_ShouldClearBuildWorkerPoolr   *RUN_FUNCTIONS_BUILD_WORKER_POOL_ANNOTATIONr   r  rd  r   rb  r   r   r(  )r   r  r   r  worker_pool_keys        r-   r  r  _  s}     !&&!LLO7&&**?;;nn^::?KL 
	"	"4)<	=	=  'r,   c                     [         R                  " U S5      =(       d/    [         R                  " U S5      =(       a    U R                  (       + $ )Nclear_build_worker_poolr(  )r   r   r(  )r   s    r-   r  r  z  s?    		"	"4)B	C 
&9: %$$
$r,   c                    [         R                  n[        USS5      n[        X5      (       aM  U(       aE  UR                  R                  U5      (       a%  UR                  [        R                  " U5      5        gU=(       d    U$ )a  Returns cloud build service account.

Args:
  args: argparse.Namespace, Command line arguments
  annotated_build_service_account: string. The build service account annotated
    on the service used by cloud run functions.
  container: Container. The container to deploy.
  service: Service. The service being changed.
  changes: List of config changes.

Returns:
  build service account value where
  None means there were no annotations, user specified to clear the
  build service account, or the build service account was an empty string.
r&  N)	r   .RUN_FUNCTIONS_BUILD_SERVICE_ACCOUNT_ANNOTATIONr   _ShouldClearBuildServiceAccountr   r  rd  r   rb  )r   r  r   r   r  build_sa_keyr&  s          r-   r  r    si    $ KK,!)-DdK$TAA7&&**<88nn^::<HI		A"AAr,   c                     [         R                  " U S5      (       a  g[         R                  " U S5      (       a  U(       d  gg)Nclear_build_service_accountTr&  F)r   r   )r   r&  s     r-   r  r    s6    
t%BCC&=>>#	r,   c                   .    \ rS rSrSrS r\S 5       rSrg)
BetaDeployi  rO   c                     UR                  5        HO  u  p4UR                  S5      (       d  M  X1;  d  UR                  S5      (       d  M:  [        R                  " SS5      e   g )Nr   r  r   r   r   r   s        r-   r   3BetaDeploy._ValidateNoAutomaticUpdatesForContainers  s\     &++-			2	3	3

(I,A,A*,M,M33!#
 	
	 .r,   c                 T   U R                  U5        [        R                  R                  U5        [        R                  " U5        [        U R                  5       5      nUR                  [        R                  " 5       5        [        R                  " XU R                  5       5        g r   )r   r   SERVICE_MESH_FLAGro   
AddIapFlagrK   rq   r3   ReadinessProbeFlagr   r   r   s      r-   r   BetaDeploy.Args  sx    NN6 
''/	V&s'7'7'9:Nu779:&& 0 0 2r,   r$   N)	r%   r&   r'   r(   r  r   r  r   r+   r$   r,   r-   r  r    s    -
 
 
r,   r  c                   (    \ rS rSrSr\S 5       rSrg)AlphaDeployi  rO   c                    U R                  U5        [        R                  " U5        [        R                  " U5        [        R                  R                  U5        [        R                  R                  U5        [        R                  R                  U5        [        R                  R                  U5        [        U R                  5       5      nUR                  [        R                  " 5       5        [        R                  " XU R                  5       5        [        R                  " U5        [        R                   " U5        [        R"                  " U5        [        R$                  " U5        [        R&                  " U5        g r   )r   r   r  AddRuntimeFlagr  ro   IDENTITY_FLAG ENABLE_WORKLOAD_CERTIFICATE_FLAGMESH_DATAPLANE_FLAGrK   rq   r3   r  r   r   AddDelegateBuildsFlagAddOverflowScalingFlagAddCpuUtilizationFlagAddConcurrencyUtilizationFlagAddPresetFlagsr   s      r-   r   AlphaDeploy.Args  s
   NN6 
V	 	''/	##F+	**66v>	))&1&s'7'7'9:Nu779:&& 0 0 2 
'	  (	'	''/	 r,   r$   N)r%   r&   r'   r(   r  r  r   r+   r$   r,   r-   r  r    s    -! !r,   r  )Br  enumr  r  os.pathr
  rR  googlecloudsdk.api_lib.runr   r   r   r   r   googlecloudsdk.callioper   r	   r   $googlecloudsdk.command_lib.artifactsr
   googlecloudsdk.command_lib.runr   r   r   r   r   r   r   r   r   r   r   r   r   $googlecloudsdk.command_lib.util.argsr   (googlecloudsdk.command_lib.util.conceptsr   r   googlecloudsdk.corer   googlecloudsdk.core.consoler   r   r  r   Enumr    rq   r  rK   UniverseCompatibleReleaseTracksCommandrM   r   r6  r7  r  r  r  r  r  BETAr  ALPHAr  r$   r,   r-   <module>r$     s   '     	 2 1 = . ( > < < 5 9 = ; 5 0 8 4 7 8 E @ 1 9 D G * 2 8( ( 		 
 %)$5$5$8$8 $N D%%(()XT\\ X * Xv+%#P&26B6 D%%**+  ,< D%%++,!* ! -!4 nn r,   