
    }A                     x   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  \R6                  " S5      rSr         S$S\4S jjrS r S r!S\S\S\SS4S jr" S%S jr#S r$S r%S r&S  r'S! r(S\S\)4S" jr*S# r+g)&Creates an image from Source.    N)encoding)
exceptions)cloudbuild_util)global_methods)apis)waiter)base)submit_util)artifact_registry)stages)sources)types)
properties)	resourceszSprojects/(?P<projectId>[^/]*)/locations/(?P<location>[^/]*)/builds/(?P<build>[^/]*)z/cloud-run-source-deployregionc                    U(       ae  U R                  [        R                  5        U R                  S5        [        R
                  " XF5        U R                  [        R                  5        SnSnSnU R                  [        R                  5        U(       a4  U R                  S5        [        X!U5        [        R                  " U5      nO)U R                  S5        [        R                  " X'UU5      nU R                  [        R                  5        [        UUUU
UUUUUUUUU5      n [        U U5      u  nnnU(       a6  US   S:w  a-  U R#                  [        R$                  SS	R'                  US
9S9  gU R                  [        R$                  5        US   S   S   S   UUS   UUS   4$ ! [        R                   a+  nU
(       d  U	(       a  Ue[!        U UUUUUS9u  nn SnANSnAff = f)r   zCreating Container Repository.Ngcloudz+Using the source from the specified bucket.Uploading sources.)remote_sourcestatusSUCCESSzCContainer build failed and logs are available at [{build_log_url}].build_log_url)message)NNNNNresultsimagesr   digestidname)
StartStager   CREATE_REPOUpdateHeaderMessager   CreateRepositoryCompleteStageUPLOAD_SOURCE_ValidateCmekDeploymentr   GetGcsObjectUpload_PrepareSubmitBuildRequest_SubmitBuildapitools_exceptionsHttpNotFoundError_CreateImageWithoutSubmitBuild	FailStageBUILD_READYformat)trackerbuild_imagebuild_source
build_packrepo_to_createrelease_trackalready_activated_servicesr   resource_refdelegate_builds
base_imageservice_accountbuild_worker_poolbuild_machine_typebuild_env_varsenable_automatic_updatessource_bucketkms_keybase_image_from_buildsourceclientsubmit_build_requestresponse_dictr   es                            <lib/googlecloudsdk/command_lib/run/sourcedeploys/deployer.pyCreateImagerJ   -   s
   * v))* @A&& &,,-&&	V))* MN7 !!,/F 45^^L,NF	,,-3:F;7M="7, }X.);77=v+ 8> 8  	 (&,,-i *1-h7df A 
	.	. _ g $B"$ M=s   -F2 2G1!G,,G1c                 F    [        U UUUU5      u  pg[        U UUUS9u  pX4$ )zSCreates an image from source by calling GCB direcly, bypassing the SubmitBuild API.)skip_activation_prompt)_PrepareBuildConfig_BuildFromSource)
r2   r3   r4   r5   r8   r   build_messagesbuild_configrG   r   s
             rI   r.   r.      sF     "5". "27	"- 
	%%    c                    [         R                  " 5       nU(       Gau  [        R                  " U5      nUb?  US   R	                  S/ 5      nUR                  SU 35        US   R                  SU05        [        R                  R                  R                  R                  S5        [        R                  " U40 SS_SU_SS_S	S_S
S_SS_SU_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SU_SS_SS_SS_6nUcL  UR                  S   R                  S:X  d   eUR                  S   R                   R#                  SS U 3/5        UR%                  UR'                  UR(                  UR                  UR*                  S!9S"9Ul        XX4$ U R/                  [0        R2                  5        U R5                  S#5        [        R                  R                  R                  R                  S5        [        R                  " U40 SS_SU_SS_S	S_S
S_SS_SU_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SU_SS_SS_6nU R7                  [0        R2                  5        XX4$ )$z%Prepare build config for cloud build.Nr   envszGOOGLE_LABEL_SOURCE=Fno_cachemessagessubstitutions
arg_configis_specified_sourceT	no_sourcerD   gcs_source_staging_dirignore_filearg_gcs_log_dirarg_machine_typearg_disk_sizearg_worker_poolarg_dirarg_revisionarg_git_source_dirarg_git_source_revisionarg_service_account	buildpack	hide_logsskip_set_source
client_tag	gcloudrunz"gcr.io/cloud-builders/gcb-internalz--labelzgoogle.source=bucketobject
generation)storageSourcer   )r   GetMessagesModuler   GetGsutilUrigetappendupdater   VALUESbuilds
use_kanikoSetr   CreateBuildConfigstepsr    argsextendSourceStorageSourcerk   rm   rD   r!   r   r&   r#   r%   )	r2   r3   r4   r5   r   rO   urirS   rP   s	            rI   rM   rM      sh    #446. 

}
-C]vr*d
kk(./mFD>* ''++E200   	
  !    $        !"  #$ !%%& !'( )* +, -. /L6 "''+OOOO  ''nSE4J(KL(//$22 '' %%$// 3 
 0 LL 
	%%= v++, 45''++E200   	
  !    $        !"  #$ !%%& !'( )* +, -L0 &../		%%rQ   rD   image_repositoryrB   returnc                    U(       d  g[         R                  " U 5      (       d  [        R                  " SU  S35      eU(       d  [        R                  " S5      e[	        U5      (       a  [        R                  " S5      eg)z/Validate the CMEK parameters of the deployment.NzInvalid source location: z. Deployments encrypted with a customer-managed encryption key (CMEK) expect the source to be passed in a pre-configured Cloud Storage bucket. See https://cloud.google.com/run/docs/securing/using-cmek#source-deploy for more details.zDeployments encrypted with a customer-managed encryption key (CMEK) require a pre-configured Artifact Registry repository to be passed via the `--image` flag. See https://cloud.google.com/run/docs/securing/using-cmek#source-deploy for more details.a  The default Artifact Registry repository can not be used when deploying with a customer-managed encryption key (CMEK). Please provide a pre-configured repository using the `--image` flag. See https://cloud.google.com/run/docs/securing/using-cmek#source-deploy for more details.)r   IsGcsObjectr   ArgumentError_IsDefaultImageRepository)rD   r   rB   s      rI   r'   r'     s     

			V	$	$

"
"
#F8 , 	  


"
"	  /00

"
"	  1rQ   c           	         [         R                  n[        R                  " USUSUUS9u  pVSUR                   SU SUR
                   3n[        R                  R                  USS9nUR                  n	U R                  [        R                  5        U R                  S5        U R                  [        R                  S	R                  U	S
95        [!        U5      n
X4$ )zGBuild an image from source if a user specifies a source when deploying.T)rf   build_regionrL   	projects//locations//operations/(cloudbuild.projects.locations.operations
collectionBuilding Container.(Logs are available at [{build_log_url}].r   )r   DEFAULT_REGIONr   Build	projectIdr   r   REGISTRYParseRelativeNamelogUrlr!   r   r0   r#   UpdateStager1   _PollUntilBuildCompletes)r2   rO   rP   rL   r   build_build_opbuild_op_refr   rG   s              rI   rN   rN   0  s     !//,
3(% )\N,uxxjY(##55E 6 , ,,-	V''(	34	077% 8  +<8-		%%rQ   c                    [         R                  " [        R                  S5      nSR	                  [
        R                  R                  R                  R                  SS9US9nUR                  UR                  UR                  UR                  S9n[        U5      nU(       Ga  SnUS   R                  S	S5      nUS   R                  S
/ 5       H/  nUR!                  S5      (       d  M  UR#                  S5      S   nM1     U	bh  UR$                  R'                  [)        U	R+                  5       5       VVs/ s H*  u  nnUR$                  R&                  R-                  UUS9PM,     snnS9n	UR/                  UUR1                  UUS   R                  S5      UR%                  UUU	U
US9SUUUU[3        X5      US9
S9$ UR/                  UUR1                  UU SUR5                  5       UUUU[3        X5      US9
S9$ s  snnf )zBUpload the provided build source and prepare submit build request.v2z%projects/{project}/locations/{region}T)required)projectr   rj   Nr   project_descriptorrS   GOOGLE_FUNCTION_TARGET=   )keyvalue)additionalPropertiesimage)	baseImagefunctionTargetenvironmentVariablesenableAutomaticUpdatesprojectDescriptor)
rn   imageUribuildpackBuilddockerBuildtagsserviceAccount
workerPoolmachineTypereleaseTrackrE   )parent"googleCloudRunV2SubmitBuildRequest)r   ro   r   SERVERLESS_API_NAMEr1   r   rt   corer   GetGoogleCloudRunV2StorageSourcerk   r    rm   _GetBuildTagsrq   
startswithsplitGoogleCloudRunV2BuildpacksBuildEnvironmentVariablesValuesorteditemsAdditionalProperty'RunProjectsLocationsBuildsSubmitRequest"GoogleCloudRunV2SubmitBuildRequest_MapToReleaseTrackEnumGoogleCloudRunV2DockerBuild)docker_imager5   r   r;   rD   r9   r<   r=   r>   r?   r@   r7   rE   rU   r   storage_sourcer   function_targetr   envr   r   s                         rI   r*   r*   O  sK     ##N$F$FM(299$$,,00$0? : & 99]]6;;6;L;L : . 
|	$$O#A**+?F!}  ,	0	1	1))C.+ - !??YY
 !'~';';'= >	  !?*#u 66PPcc d  !?	  Z n ;;+3+V+V(]&&w/#CC$.%3'?"4 D  *(*/H! ,W ,
 <  . 
	9	9)1)T)T&::<(&(-mF *U * 
: 
 = s   :1H 
c                 V    [         R                  " U 5       SU R                  5        3/$ )Nr   )r   GetKindName)r9   s    rI   r   r     s*    ]]<()<+<+<+>*?
@	AArQ   c                 Z   [         R                  " [        R                  S5      n[        R
                  " 5       nUR                  R                  U5      nUR                  (       a  U R                  UR                  5        UR                  n[        R                  " UR                  5      n[        R                  " UR                  U5      R                   n[#        UR$                  5      nSUR&                   SU SUR(                   3n	[*        R,                  R/                  U	SS9n
UR0                  nU R3                  [4        R6                  5        U R9                  S5        U R;                  [4        R6                  SR=                  US	95        [?        U
5      nXUR@                  4$ )
a  Call Build API to submit a build.

Arguments:
  tracker: StagedProgressTracker, to report on the progress of releasing.
  submit_build_request: SubmitBuildRequest, the request to submit build.

Returns:
  response_dict: Build resource returned by Cloud build.
  build_log_url: The url to build log
  build_response.baseImageUri: The rectified uri of the base image that should
  be used in automatic base image update.
r   r   r   r   r   r   r   r   r   )!r   GetClientInstancer   r   r   ro   projects_locations_buildsSubmitbaseImageWarning
AddWarningbuildOperationr   MessageToJsonmetadataJsonToMessageBuildOperationMetadatar   _GetBuildRegionr    r   r   r   r   r   r   r!   r   r0   r#   r   r1   r   baseImageUri)r2   rF   
run_clientrO   build_responser   jsonr   r   r    r   r   rG   s                rI   r+   r+     sp     %%n&H&H$O*"446.77>>. $$~667**(			 1 1	2$

 
 ++T	E  !,,U__%[l588*	U$##55
A 6 , ,,-	V''(	34	077% 8  +<8-	~'B'B	BBrQ   c                     [         R                  " 5       n[        R                  " UR                  UR
                  5      n[        R                  " X 5      n[        R                  " UR                  5      $ )N)
r   r   r	   CloudOperationPollerprojects_builds
operationsPollUntilDoner   MessageToPyValueresponse)r   rE   poller	operations       rI   r   r     sZ    ,,.&&&f//& ""68)		"	"9#5#5	66rQ   c                 x    [         R                  U 5      nU(       a  UR                  S5      $ [        SU  35      e)NlocationzInvalid build name: )_BUILD_NAME_PATTERNmatchgroup
ValueError)
build_namer   s     rI   r   r     s7    

#
#J
/%
;;z"")*677rQ   c                     [         U ;   $ )z2Checks if the image repository is the default one.)_DEFAULT_IMAGE_REPOSITORY_NAME)r   s    rI   r   r     s    	'+;	;;rQ   c                     SnU (       aF  U [         R                  R                  :w  a(  UR                  R                  nU" U R
                  5      nU$ )z-Returns the enum value for the release track.N)calliope_baseReleaseTrackGAr   ReleaseTrackValueValuesEnumr    )r7   rU   release_track_enum_valuerelease_track_enum_clss       rI   r   r     sK    !}(B(B(E(EE33OO   6m6H6HI	!!rQ   )	FNNNNNFNN)F),__doc__reapitools.base.pyr   r   r,   !googlecloudsdk.api_lib.cloudbuildr   googlecloudsdk.api_lib.runr   googlecloudsdk.api_lib.utilr   r	   googlecloudsdk.callioper
   r   !googlecloudsdk.command_lib.buildsr   googlecloudsdk.command_lib.runr   r   ,googlecloudsdk.command_lib.run.sourcedeploysr   r   googlecloudsdk.corer   r   compiler   r   strrJ   r.   rM   r'   rN   r*   r   r+   r   r   boolr   r    rQ   rI   <module>r     s    $ 	 % > = 5 , . 9 9 < 5 1 @ > * ) jjY  "<   "%f fR&2\&~#&14	F CH&>OdB-C`78< < <
"rQ   