HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: //lib/google-cloud-sdk/lib/surface/run/__pycache__/deploy.cpython-312.pyc
�

�������dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddlm
ZddlmZddl
mZddl
mZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddl!m"Z"ddl#m$Z$ddl#m%Z%ddl&m'Z'ddl(m)Z)ddl(m*Z*dZ+dZ,Gd�d ejZ�Z.ej^j`fd!�Z1ejdejfej^j`�Gd"�d#ejh���Z5d$�Z6d%�Z7d&�Z8d'�Z9d(�Z:d)�Z;d*�Z<d+�Z=ejfej^j|�Gd,�d-e5��Z?ejfej^j��Gd.�d/e?��ZAe5jeA_y)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��eZdZdZdZy)�	BuildType�
Dockerfile�
BuildpacksN)�__name__�
__module__�__qualname__�
DOCKERFILE�
BUILDPACKS���lib/surface/run/deploy.pyr r 7s���*��*r)r c��d}tj|��}|jtj��|jtj
��|jtj|��|jtj��|jtj��|jtj��|jtj��|jtj��|jtj��|jtj��|jtj��|jtj��|jtj ��|jtj"��|jtj$��|jtj&��|jtj(��|jtj*d|���|jtj,��|jtj.��|jtj0��|S)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)r.�	help_text�groups   r*�ContainerArgGrouprH<s���)��
�
�)�
,�%����E�M�M�O�$����E�O�O�%�&����E�+�+�M�:�;����E�$�$�&�'����E�M�M�O�$����E�N�N�$�%����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�+�+�-�.����E�M�M�O�$�	�,r)c��eZdZdZddd�Zed��Zed��Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�Deploy�%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�<�tj|�tj|�tj|�tj|�tj
|�tj|�tj|�tj|�tj|�tj|�tj|�tj|�tj|�tj|�tj|�tj |�tj"|�tj$|�tj&|�tj(|�tj*|�tj,|�tj.�j1|�tj2||j5��tj6|�tj8|�tj:|�tj<|�tj>j1|�tAjBdtEjFd��ddd��}tjH|�tjJ|�tjL|�tjN|�tjP|�tjR|�tjT|�tjV|�tjX|�tjZ|�tj\|�tj^|�tj`|�tjb|�tejf|g�j1|�|jhjkd�y)N�SERVICET)�promptzService 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*�
CommonArgszDeploy.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�E�f�M�
���!�!�&�)r)c��|j|�t|j��}tj|||j��y�N)r�rHrmr�AddContainerFlags�r�r��container_argss   r*�ArgszDeploy.Args�s?���N�N�6��&�s�'7�'7�'9�:�N��&�&���� 0� 0� 2�r)c���tj|d�r |jdtjvrytj|d�r |jdtjvry|j�r3tj|||||j�d��}|s|sy|Sd}tj�tjk(rtj||||�}|s|sd}|S)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*�GetAllowUnauthzDeploy.GetAllowUnauth�s���$	�!�!�$��1��K�K���5�#?�#?�?�
�
�!�!�$��1��K�K���5�#>�#>�>�
������2�2�
�
�
��
��8�8�:�1�=��l��L��
���L�����)�"<�"<�<��2�2�
�
�K�^�);��l�
�L����r)c���tj|d�r�|j}tj|d�r�|jdtjvr}t||jdd�}d|d<t
||jdd|�t
||jddd�t
||jddd�nd	|i}t|�d
kDrc|j�D�cgc]&}|jd�s|jd�r|��(}}t|�d
k7rtjd
d��t|�dkDrtjd
d��|Scc}w)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)rr�r�r��INGRESS_CONTAINER_PRESETS�getattr�setattr�len�values�IsSpecified�c_exceptions�InvalidArgumentException)r�r�r��specified_args�c�ingress_containerss      r*�_ValidateAndGetContainersz Deploy._ValidateAndGetContainers�sx��� � ��|�4��?�?�j��
#�
#�D�(�
3��k�k�&�!�U�%D�%D�D� ��t�{�{�6�*�+�->�
��#,��w����t�{�{�6�*�+�->��	
�	�
�4�;�;�v�.�/��:L�M��
�4�;�;�v�.�/�1D�d�K���:�j�
�:�����$�$�&��&�a�
�]�]�6�
"�a�m�m�K�&@��&���


�
�	 �A�	%��3�3��F�
�	
�
�:�����1�1�
�E�
�����s�5+E,c��|j�D]1\}}||vs�|jd�s�tjdd��y)Nr��--automatic-updates�S--automatic-updates can only be specified in the container that builds from source.��itemsr�r�r��r��deploy_from_sourcer�r��	containers     r*�(_ValidateNoAutomaticUpdatesForContainersz/Deploy._ValidateNoAutomaticUpdatesForContainerssQ��&�+�+�-���i�	
�'�	'�I�,A�,A�
�-��3�3�!�
#�
�	
�	.r)c���|j�D��cic]/\}}|jd�rtj|d�r||��1}}}t	|�dkDre|j�D��cgc]\}}tj|d�s|��}}}|rtj|��tjdd��|j||�|j�D]v\}}tj|d�r�tj�rtj|�|_
�L|rdj|�}nd}tjd|��|j!|�|Scc}}wcc}}w)	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�rr�r�r	�RequiredImageArgumentExceptionr�r�r�r�	CanPrompt�PromptForDefaultSourcer��format�RequiredArgumentException�_ValidateNoBuildFromSource)r�r�r�r�r��needs_image�messages       r*�_ValidateAndGeDeployFromSourcez%Deploy._ValidateAndGeDeployFromSource's��� *�/�/�1��1�O�D�)��%�%�g�.��(�(��H�=�		
�i��1�������"�"4�!9�!9�!;��!;�o�d�I��*�*�9�h�?��!;���

��7�7��D�D��1�1�
�M�
��	�1�1��J��.�3�3�5���i�
�
&�
&�y�(�
;����!�"�9�9�$�?�)�
�
��#�V�D�\�
��
�
�6�6�����#6�*	�#�#�$6�7����Y��s�4E,�,"E2c��t|j�|�sytt|j	���d}|jd�st
jdd��|jd�st
jdd��|jd�r&t|d�d	k7rt
jd
d��yy)z�Extra 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.)	�_IsNoBuildFromSourcerm�next�iterr�r�r�r�r�)r�r�r�s   r*r�z!Deploy._ValidateNoBuildFromSourceVs��� �� 1� 1� 3�5G�H���T�,�2�2�4�5�6�q�9�I�� � ��.��1�1�
��
��
� � ��+��1�1�
�
O�
��
	���g�&��I�w�'�9�4��1�1�
��
��
5�	'r)c���t|dd�}t|dd�}|r|S|�=|�;tj|jvr|s|jtjStjS)aReturns 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�rr�r�s     r*�_GetBaseImageForSourceContainerz&Deploy._GetBaseImageForSourceContainerzss�����t�<�J��~�/A�4�H���
��	�����6�6�'�:M�:M�M� �
�
 �
 ��!K�!K�
L�L��)�)�)r)c���t|dd�}t|dd�}|j||�}|�|S|ry|�|tjk7Stj|j
vr4|j
tj}|j
�dk(rdSdStj|j
vr4|j
tj}|j
�dk(rdSdS|S)z0Returns the automatic updates for the container.r�Nr�F�trueT)r�r�r�r��,RUN_FUNCTIONS_BUILD_ENABLE_AUTOMATIC_UPDATESr��lower�1RUN_FUNCTIONS_ENABLE_AUTOMATIC_UPDATES_DEPRECATED)r�r�rr�r�r��automatic_updates_annotations       r*�_GetAutomaticUpdateszDeploy._GetAutomaticUpdates�s����0C�T�J���~�/A�4�H���5�5�n�g�N�J��$�
���
����;�9�9�
9�9�	�@�@����	�&-�%8�%8�
�
B�
B�&�"�2�7�7�9�V�C�T�N��N��E�E����	�&-�%8�%8�
�
G�
G�&�"�2�7�7�9�V�C�T�N��N��r)c�
�t|dd�}t|dd�}|�|dk(ry|�|�tS|�Utj|jj
vr/|jj
tj}|rtSy)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�rr��	gpu_count�accelerator_values      r*�_GetMachineTypezDeploy._GetMachineType�s����~�z�4�8�H����t�4�I����c�!1�
���y�4�
$�$���	�	*�	*�g�.>�.>�.L�.L�	L�#�,�,�:�:��-�-�
���(�
(�r)c��|r|jnd\}}	}
}tt|j���\}}
|s&|r$|jj
jxsd}d}g}|
j}|r|j|j�nd}tjd|�|
j}|j|||||
||�\}}dj||j��|
_|dz}|j#|
|�}|j%|
|�}d}|j'�t(j&j*k7r|j-|
|�}t.j0j3|�ret4j6}t9j:|
d�rt=j>dd	��|t@jBk7r4t=jDd
d��tG|
�\}}t4jH}|rdn|
j }t9j:|d�s|�+|t@jBk7r|r|d
jKd�n|}tM|||
||�}dj|jN��}tQ||	||�}|
rtSjT|
�nd}tWjXd|�}tWjZ|fi|��} ||||||||||||| ||fS)N)NNNNr�zExisting source_bucket: %sz{repo}/{service})�reporz/Dockerfiler�z--base-imagez?Base image is not supported for services built from Dockerfile.z--clear-base-imagez�Base image is not supported for services built from Dockerfile. To continue the deployment, please use --clear-base-image to clear the base image.�delegate_buildsrr�z6Building using {build_type} and deploying container to)�
build_typezbuild-env-vars).�run_functions_annotationsr�r�r�r�r�r�r��'_GetSourceBucketFromBuildSourceLocation�source_location�logging�debug�function�_GetArtifactRegistryRepositoryr��
servicesIdr�r�r�rmr�GAr��os�path�existsr r&rr�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*�_BuildFromSourcezDeploy._BuildFromSource�s��$�	�)�)�
%��'�#� �!� ��%6�%<�%<�%>� ?�@��D�.��G�
�
�
�
'�
'�
,�
,�
2��d��D��G�
�
"�
"�F��	
�4�4�W�5L�5L�M�
��
�M�M�.�
�>�!�)�)�K�%)�$G�$G����"��!��%�!�M�>�.�4�4�
�K�$:�$:�5��N���=�(�K��5�5�n�g�N�J��1�1�.�'�J��������d�/�/�2�2�2��/�/���H��	�w�w�~�~�k�"��'�'�j�
�	"�	"�>�<�	@��3�3��M�
�	
�
�{�5�5�	5��4�4� �
�
�	
�'�~�6�m�d�G��'�'�j��D�n�2�2�E�� � ��'8�9���:��1O�1O�#O�&*�d�1�g�k�k�'�"��e�3��-�~�w����	A��f�
�(�(�f�)��,��)�7�G���
$�	
�
�
�+�,�
��
#�6�6�7G��N���+�+���1��N�	�
���������������r)c��d}|jr:t|j|�}	t|j|j�|	|fS|rt||�}	|	|fSt	j
tjjjjd��tj||tjk(r|jnd��d��}
tj |
|��r|
}|
j#�}	|	|fS)aKGets 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�rQ)�cluster_locationzcloud-run-source-deploy��
project_id�location_id�repo_id)�skip_activation_prompt)r��_ValidateArRepository�_ValidateServiceNameFromImager�r
�
DockerRepor�VALUES�core�project�Getr�
RepoRegionr�PLATFORM_GKEr"�ShouldCreateRepository�GetDockerString)r�r�r
rrr�rr�rr�ar_repos           r*r�z%Deploy._GetArtifactRegistryRepository^s
��8�N����+�
�
�
� :��m�$�
�
�
�� 6� 6���N�
*�*�	"�+�
#�%?��m��N�
*�*��&�&��&�&�+�+�3�3�7�7��7�F�'�2�2����!7�!7�7��/�/���,��g�
�	1�	1�
�*D�
�!���-�-�/�m��.�(�(r)c�R�|jr|jjd�Sy)N�,)�_Deploy__multi_region_regions�split�r�s r*r�z Deploy._GetRegionsForMultiRegion�s%���"�"�
�
(�
(�
.�
.�s�
3�3�r)c�,�t|j�Sr�)�boolr6r8s r*r�zDeploy._IsMultiRegion�s����+�+�,�,r)c	��|sy|j}tjd|�|sy	tj|�}t|t�rt|�dk7rtjd�ytjdtt|j����}|r|jd�Stjd�y#tjtf$r }tjd|�Yd}~yd}~wwxYw)z�Returns 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.
    Nzsource_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�rr�
isinstance�dictr��re�searchr�r�r�rG�JSONDecodeError�	TypeError)r�r�source_location_map�container_to_source_map�x�es      r*�+_GetSourceBucketFromZipDeploySourceLocationz2Deploy._GetSourceBucketFromZipDeploySourceLocation�s����
�!�L�L���M�M�+�-@�A��
�� $�
�
�+>� ?���0�$�7�
�(�
)�Q�
.��
�
�K�	
��
�)�)�
�d�4�(?�(F�(F�(H�#I�J��a�
��w�w�q�z��
�m�m�L�M�
��� � �)�,��
�m�m�9�1�=�
���s%�AC�3AC�<C�D�+D�Dc��tjd|�|sytjd|�}|r|j	d�Stjd�y)Nzsource_location: %sr<r�r=)r�r�rArBrG)r�r�rGs   r*r�z.Deploy._GetSourceBucketFromBuildSourceLocation�sI���M�M�'��9��
�
�	�	�$�o�6�A��
�W�W�Q�Z���M�M�J�K�r)c��tj||j��}|jdt	j
tj��|jt	j|j���|j�r/|jt	j|j���|S)z>Returns the service config changes with some default settings.r)�regions)
r�GetServiceConfigurationChangesrm�insertr
�DeleteAnnotationChanger�BINAUTHZ_BREAKGLASS_ANNOTATION�append�SetLaunchStageAnnotationChanger��SetRegionsAnnotationChanger6)r�r�rs   r*�_GetBaseChangeszDeploy._GetBaseChanges�s����2�2�4��9J�9J�9L�M�G��N�N�	��-�-��5�5�	
���N�N��5�5�d�6G�6G�6I�J������
�n�n�
�
3�
3��1�1����Nr)c��tj|tjj|j�|j
���S)N)�is_multiregion)r�GetConnectionContextr�Product�RUNrmr��r�r�s  r*�_ConnectionContextzDeploy._ConnectionContext�s?���2�2��
�
�
��������*�*�,�	�r)c
�h�t|�xr|	}
|
xrD|j�tjjtjjfv}tj|du||t|�|
|du|du|j���}|
rd}
nd}
|�[|
dz
}
|j�r|
dz
}
n|
dz
}
tj|d�s%|jtjd�	��|j�rd
}nd}|
dz
}
tj|
|||j �
�S)N)�include_iam_policy_set�
include_route�include_validate_service�include_upload_source�
include_build�include_create_repo�include_iap�regions_listzBuilding and deploying�	Deployingz newz Multi-Region servicez service�	cpu_boostT)rfzNMulti-region deployment failed. Some regions might already be serving traffic.zDeployment failedz...)�failure_message�suppress_output)r:rmr�ALPHA�BETAr�
ServiceStagesr�r�rr�rQr
�StartupCpuBoostChanger�StagedProgressTracker�async_)r�r�rrr	rr��
has_latest�iap�
skip_build�requires_buildr_�deployment_stages�headerrgs               r*�_GetTrackerzDeploy._GetTracker�sL���+�,�?�Z��N�-� �$�2C�2C�2E�����������J�3���,�,�+�4�7� �!9�"�#4�5�$�*�$�6��t�O��3�3�5�	���'�f��f������f�	
�	�	�	��)�)���*���
�
&�
&�t�[�
9����~�;�;�d�K�L�������
,�o�
�e�O�F��1�1���'����	�r)c�x�tj�g}|r"|jd�|jd�|S)Nzartifactregistry.googleapis.comzcloudbuild.googleapis.com)r�get_run_apirQ)r�r	�apiss   r*�_GetRequiredApiszDeploy._GetRequiredApis(s5���#�#�%�&�D��
�k�k�3�4�
�k�k�-�.��Kr)c��|j�rD|js8tjt	j
||j
���y|jr0tjdj|j���ytjt	j||j��y)Nz>Service [{{bold}}{serv}{{reset}}] is deploying asynchronously.)�serv)r�rnr�Successr�0GetSuccessMessageForMultiRegionSynchronousDeployr�r�r��%GetSuccessMessageForSynchronousDeploy�
no_traffic)r�rr�s   r*�_DisplaySuccessMessagezDeploy._DisplaySuccessMessage/s�������T�[�[����
�
H�
H��t�5�5�7���

�������"�F����F�5��
���
�
=�
=��t����r)c�H�tj|d�r|jSy)z&Returns the IAP status of the service.rpN)rr�rprZs  r*�_GetIapzDeploy._GetIapBs��� � ��u�-�
�X�X�o�r)c�H	��������������������� �!�"�#�tj���_tj��j	�tj
j�}�j��}�j|���jjj�� tj� ��j��}d�|tjk(rFt!j"t$j&j(j*j-�|���j/��}d�d�d�"d}d�d}d�t1�dd��d�d�d�d�g}d�d�d�#d�!t3j4|��5��j7� ��t9�j	���rvd�d�!t;t=�j?���\�}	�s&�r$�j@jBjDxsd�|	jF�"�jI���#d|	_%n��r��jM��� ||���\}���"}���}������#tOjPt$j&j(j*j-d��tjR����	��jU��}
|
jW|��jY��� ���t[j\����rs|rq�j@jBj^rQtj`�}|r%|
jctejfg��ntijjd
d��tmjn���tqjrtmjt|� |���duxstvjx�jzv��j}������������������������ �!�"�#fd�}	||
���j�����cddd�S#t~j�$rY}
tj��t�|
��r.|
jctej�d�
��||
��n|
�Yd}
~
��d}
~
wwxYw#1swYyxYw)rFNzDeploying container to�keyr�r�Tr!)r$�regionrz	--commandz
--functionc����j��|�
���
���	5}�j�|�j�|�j��j	����tj�����tj�d�xstj�d�tj�d�����	���tjjjj�dk(������cddd�S#1swYyxYw)N�revision_suffix�tagr�r�)�asyn�allow_unauthenticated�multiregion_regions�prefetch�build_image�
build_pack�build_region�build_sourcerr�
generate_namer�r��!deploy_from_source_container_namerrrr�enable_automatic_updates�
is_verboser�kms_key�iap_enabledrq)
ru�ReleaseServicermrnr�r�GetFirstRegionr�rr+r,�	verbosityr.)�changes_�trackerr�rr�r�rrrrr�r�r�rorpr�r�r�rrr�rr�rqr�rs  ������������������������r*�_ReleaseServicez#Deploy.Run.<locals>._ReleaseService�s ���
�
�
����������

���*�*������!���;�;�$0�"&�"@�"@�"B���� �/�/��5�!�+�)C��+�+�D�2C�D�<��.�.�t�U�;�#�7�7��)��$�0Q�$9� 1�!3�+�'?�#�*�*�/�/�9�9�=�=�?�7�J�)���#�C+�"�

�

�

�s�CC>�>D)�gpu_zonal_redundancy)Er�GetMultiRegionr6�GetAndValidatePlatformrmrXrYr�r��CONCEPTSr�Parse�ValidateResourceryrr�r�check_and_enable_apisrr+r,r-r.r[r�r�Connect�
GetServicer�r�r�r�r�r�r�r�rIr�rr�+ValidateBuildServiceAccountAndPromptWarning�	GetRegionrT�extendr�r�ValidateClearVpcConnectorr��PromptForClearCommandrQr
�ContainerCommandChanger��ConflictingArgumentsExceptionr�MaybeLogDefaultGpuTypeMessager�Info�GetStartDeployMessager�LATEST_REVISION_KEY�spec_trafficr�r	�	HttpError�ShouldRetryNoZonalRedundancy�str�GpuZonalRedundancyChanger�)$r�r�rr��
required_apisr
rr�
build_changesr�r�
clear_commandr�rHr�rr�rrrrr�r�r�rorpr�r�r�rrrr�rqr�rs$``            @@@@@@@@@@@@@@@@@@@@@@r*�Runz
Deploy.RunHsc�����"'�"6�"6�t�"<�D���+�+��d���!�5�=�=�#4�#4��H��/�/��5�J��<�<�Z�H���-�-�'�'�-�-�/�K�	���;�'��)�)�*<�=�M�!&���9�-�-�-�#.�#D�#D�
�
�
�
 �
 �
(�
(�
,�
,�
.�
�$� ��*�*�4�0�L��E��D�
�F�0���N��K��J��d�E�4�(�G� ���N������M�(*�%�#���M��J�	�	&�	&��0�
�	��%�%�k�2�g�	�d�/�/�1�3E�	F����
�<@��#�)�)�+�,�=
�9�)�>�1�W����(�(�-�-�3��,� �&�&���H�H��
�
� )����"
�!�!������&��
�!	
��������!��-����$��	�>�>�!�(�(�-�-�5�5�9�9�4�9�H��?�?�4�(�"7�	
��$�$�T�*�g�
�n�n�]�#��(�(��z�;��P�l� �:�:�7�D�I�	��7�+�+�5�5�=�=��5�5�7�-�
��N�N�>�@�@��D�E��<�<����
�
�1�1�$��@����
�
-�
-��K�):����T�/�
P�W�8�8�G�<P�<P�P��
�L�L���c�.�.�.�.�`�!�'�*���!�!�'�4�0�
�]
�
��D�
!�
!�	��-�-�d�C��F�;�
�.�.��5�5�',���
$�G�,�'��'���	��E
�
�s8�I8R�P)�R�)R�<AR�R�R�R�R!N)r#r$r%�__doc__�
detailed_help�classmethodr�r�r�r�r�r�r�r�r�r�rr�r�r�rIr�rTr[ruryr�r�r�r(r)r*rJrJcs���.��
�	�-�(�9*��9*�v����1�f%�N
�-�^"�H*�8"�H�BA�F<)�|�
-�!�F��*	�5�n��&�vr)rJc���|tjjk7ry|rt|�dk7ryt	t|j
���d}|jd�S)zLChecks if this is a source deployment that should skip the Cloud Build step.Fr��no_build)rrmrir�r�r�r�r�)r.r	r�s   r*r�r�s[���d�'�'�-�-�-��	�c�"3�4��9���4�)�/�/�1�2�3�A�6�)�	�	�	�z�	*�*r)c��d}tj||�}|stjdd|����|j	d�}|j	d�}|j	d�}tj|||��}tj||d�	�rtjdd
|�d���|j�S)zGChecks the format and existence of the repository in Artifact Registry.z+([\w-]+)-docker\.pkg\.dev/([\w-]+)/([\w-]+)r�z�The 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���r#T)r'�skip_console_promptz1The artifact repository provided does not exist: z-. Please create the repository and try again.)
rA�matchr�r�rGr
r*rr1r2)rr�image_uri_regexr�r�r$r&r3s        r*r(r(s���C�/�
�(�(�?�$=�
>�%�	�
�
/�
/��	 �
!:�:�	<����;�;�q�>�&��{�{�1�~�*��K�K��N�'��"�"����
�'��-�-�
�7���
�
/�
/��;�$�
%�&7�	7���
�	 �	 �	"�"r)c��d}tj||�}|rD|jd�r2|jd�|k7rtjdd|�d|�d���yyy)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)rAr�rGr�r�)�	image_uri�
service_idr�r�s    r*r)r)4s{��C��
�(�(�?�I�
.�%��
�+�+�n�
%�
�+�+�n�
%��
3�
�
/�
/��K��+�8���A�	G���4�&�r)c���d|jig}g}|j}|dztz}t|dd�}t|dd�}|�9dj	|�}|djdd	j
|�
�gi�n*|�(|djdddj
|�
�gi�tjj|�r|djdti�||fS)z'A helper method to configure buildpack.r��/r�Nr�� r�envszGOOGLE_ENTRYPOINT="{command}")r�z#GOOGLE_FUNCTION_SIGNATURE_TYPE=httpzGOOGLE_FUNCTION_TARGET={target})�target�project_descriptor)
r�r��_PROJECT_TOML_FILE_NAMEr��join�updater�r�r�r�)r�rrr��project_toml_file�command_arg�function_argr�s        r*rrGs����I�O�O�
$�	%�$��'����&��s�l�%<�<���	�9�d�3�+���J��5�,����h�h�{�#�G���G�N�N�	�1�8�8��8�I�J�K������G�N�N��1�-�4�4�L�4�I�
����W�W�^�^�%�&���G�N�N�(�*A�B�C�	
�w��r)c��t|�rRtj}|r?|jj	|�r$|jt
j|��ytj|d�r|jS|S)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�rrQr
rOrr�r)r�rrr�worker_pool_keys     r*rr`st��!��&�!�L�L�O��7�&�&�*�*�?�;�
�n�n�^�:�:�?�K�L��
�	"�	"�4�)<�	=�����'�r)c�|�tj|d�xs%tj|d�xr
|jS)N�clear_build_worker_poolr)rr�r)r�s r*r�r�{s?��	�	"�	"�4�)B�	C�
�����&9�:�%��$�$�
$�r)c���tj}t|dd�}t||�rB|r?|jj|�r$|j
tj|��y|xs|S)a6Returns 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.
  rN)	r��.RUN_FUNCTIONS_BUILD_SERVICE_ACCOUNT_ANNOTATIONr��_ShouldClearBuildServiceAccountr�rrQr
rO)r�r
r�rr�build_sa_keyrs       r*rr�sf��$�K�K�,�!�)�-D�d�K��$�T�+@�A��7�&�&�*�*�<�8�
�n�n�^�:�:�<�H�I��	�	A�"A�Ar)c�d�tj|d�rytj|d�r|syy)N�clear_build_service_accountTrF)rr�)r�rs  r*r�r��s0��
���t�%B�C������&=�>�#��	r)c� �eZdZdZed��Zy)�
BetaDeployrKc�
�|j|�tjj|�tj|�t|j
��}tj|||j
��yr�)	r�r�SERVICE_MESH_FLAGrk�
AddIapFlagrHrmrr�r�s   r*r�zBetaDeploy.Args�sc���N�N�6��
���'�'��/�	���V��&�s�'7�'7�'9�:�N��&�&���� 0� 0� 2�r)N)r#r$r%r�r�r�r(r)r*r�r��s��-��	��	r)r�c�&�eZdZdZd�Zed��Zy)�AlphaDeployrKc��|j�D]B\}}|jd�s�||vs|jd�s�.tjdd��y)Nr�r�r�r�r�r�s     r*r�z4AlphaDeploy._ValidateNoAutomaticUpdatesForContainers�s[��&�+�+�-���i�	�	�	�2�	3�
�(�
(�I�,A�,A�*�,M��3�3�!�
#�
�	
�	.r)c��|j|�tj|�tj|�tjj|�tjj|�tjj|�tjj|�t|j��}|jtj��tj|||j��tj|�tj |�tj"|�tj$|�tj&|�yr�)r�rr��AddRuntimeFlagr�rk�
IDENTITY_FLAG� ENABLE_WORKLOAD_CERTIFICATE_FLAG�MESH_DATAPLANE_FLAGrHrmr0�ReadinessProbeFlagrr��AddDelegateBuildsFlag�AddOverflowScalingFlag�AddCpuUtilizationFlag�AddConcurrencyUtilizationFlag�AddPresetFlagsr�s   r*r�zAlphaDeploy.Args�s���N�N�6��
���V��	���� �	���'�'��/�	���#�#�F�+�	�*�*�6�6�v�>�	���)�)�&�1�&�s�'7�'7�'9�:�N����u�7�7�9�:��&�&���� 0� 0� 2��
����'�	� � ��(�	����'�	�'�'��/�	���� r)N)r#r$r%r�r�r�r�r(r)r*r�r��s��-�
��!��!r)r�)Br��enumrr��os.pathr�rA�googlecloudsdk.api_lib.runrrrr�r�googlecloudsdk.callioperr	r��$googlecloudsdk.command_lib.artifactsr
�googlecloudsdk.command_lib.runrrr
rrrrrrrrrr�$googlecloudsdk.command_lib.util.argsr�(googlecloudsdk.command_lib.util.conceptsrr�googlecloudsdk.corer�googlecloudsdk.core.consolerrr�r��Enumr rmr�rH�UniverseCompatible�
ReleaseTracks�CommandrJr�r(r)rrr�rr�rjr�rir�r(r)r*�<module>rs���'�����	�2�1�=�.�(�>�<�<�5�9�=�;�5�0�8�4�7�8�E�@�1�9�D�G�*�2�8�(��(����	�	��
%)�$5�$5�$8�$8�$�N�������D�%�%�(�(�)�Y�T�\�\�Y�*��Y�x+�%#�P�&�2�6�B�6�����D�%�%�*�*�+�
��
�,�
� ����D�%�%�+�+�,�$!�*�$!�-�$!�N�n�n��r)