
    C                     @   S r SSKJr  SSKJr  SSKJ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 rS r\R                   \R"                  " \R$                  R&                  \R$                  R(                  5       " S S\R*                  5      5       5       rg)z?Implementation of gcloud dataflow flex_template build command.
    )absolute_import)division)unicode_literalsN)apis)actions)arg_parsers)base)
propertiesc           	      	   U R                  SS9nUR                  5       nUR                  5       nU R                  SSS[        R                  " SS5      S9  UR                  S	S
S9  U R                  SS[        R                  " SS5      S9  U R                  SS[        R                  " SS5      S9  U R                  SS[        R                  " SS5      S9  U R                  SS/ SQSS9  U R                  SS[        R
                  " 5       S9  U R                  SSS[        R                  " [        R                  R                  R                  5      S9  U R                  SS [        R                  " SS5      S9  U R                  S!S"[        R                  " SS5      S9  U R                  S#[        R                  " S$S%5      S&S'9  U R                  S([        R                  " S$S%5      S)S'9  U R                  S*[        S+S'9  U R                  S,[        R                  " [        R                  R                  R                  5      S-S.9  U R                  S/[        S0S'9  U R                  S1S2S9  U R                  S3S4S9  U R                  S5S6S9  U R                  S7S8S9  U R                  5       nUR                  S9S:S9  UR                  S;S<S9  U R                  S=[        R                  " [        R                  R                  R                  5      S>S.9  U R                  S?S@[        R                  " SS5      SASB9  U R                  SCSD[        R                  " 5       [        R                   SESF9  U R                  SGSH[        R"                  " 5       [        R                   SISF9  UR                  SJSK[        R                  " SLSM5      SSN9  UR                  SS9nUR                  SOSP[        R                  " 5       [        R                   SQSF9  UR                  SRSS[        R                  " 5       [        R                   STSF9  UR                  SUSVSWSX9  UR                  SYSSZ[        R
                  " 5       S[S\9  UR                  S]S^S_SX9  UR                  S`Sa[        R                  " SbSc5      SSN9  UR                  SdSe[        R"                  " 5       [        R                   SfSSg9  gA)hzgRegisters flags for this command.

Args:
  parser: argparse.ArgumentParser to register arguments with.
T)requiredtemplate_file_gcs_pathTEMPLATE_FILE_GCS_PATHz]The Google Cloud Storage location of the flex template file.Overrides if file already exists.z^gs://.*zMust begin with 'gs://')metavarhelptypez--imagezLPath to the any image registry location of the prebuilt flex template image.)r   z%--image-repository-username-secret-ida  Secret Manager secret id for the username to authenticate to private registry. Should be in the format projects/{project}/secrets/{secret}/versions/{secret_version} or projects/{project}/secrets/{secret}. If the version is not provided latest version will be used.zD^projects\/[^\n\r\/]+\/secrets\/[^\n\r\/]+(\/versions\/[^\n\r\/]+)?$z~Must be in the format 'projects/{project}/secrets/{secret}' or'projects/{project}/secrets/{secret}/versions/{secret_version}'.)r   r   z%--image-repository-password-secret-ida  Secret Manager secret id for the password to authenticate to private registry. Should be in the format projects/{project}/secrets/{secret}/versions/{secret_version} or projects/{project}/secrets/{secret}. If the version is not provided latest version will be used.z--image-repository-cert-patha)  The full URL to self-signed certificate of private registry in Cloud Storage. For example, gs://mybucket/mycerts/selfsigned.crt. The certificate provided in Cloud Storage must be DER-encoded and may be supplied in binary or printable (Base64) encoding. If the certificate is provided in Base64 encoding, it must be bounded at the beginning by -----BEGIN CERTIFICATE-----, and must be bounded at the end by -----END CERTIFICATE-----. If this parameter is provided, the docker daemon in the template launcher will be instructed to trust that certificate. z--sdk-languagez&SDK language of the flex template job.)JAVAPYTHONGOYAML)r   choicesr   z--metadata-filez;Local path to the metadata json file for the flex template.z--print-onlyzKPrints the container spec to stdout. Does not save in Google Cloud Storage.F)r   defaultactionz--staging-locationzbDefault Google Cloud Storage location to stage local files.(Must be a URL beginning with 'gs://'.)z--temp-locationzDefault Google Cloud Storage location to stage temporary files. If not set, defaults to the value for --staging-location.(Must be a URL beginning with 'gs://'.)z--service-account-emailz	.*@.*\..*z"must provide a valid email addressz.Default service account to run the workers as.)r   r   z--cloud-build-service-accounta  Service account to run the Cloud Build in the format projects/{project}/serviceAccounts/{service_account}. Ensure that the account you are using to run 'gcloud dataflow flex-template build' has 'ServiceAccountUser' role on the specified Cloud Build service account you provide with the --cloud-build-service-account flag. The specified service account must have required permissions to build the image. If the specified service account is in a project that is different from the project where you are starting builds, see https://cloud.google.com/build/docs/securing-builds/configure-user-specified-service-accounts#cross-project_set_up to grant the necessary access.z--max-workersz)Default maximum number of workers to run.z--disable-public-ipsz8Cloud Dataflow workers must not use public IP addresses.)r   r   z--num-workersz,Initial number of workers to use by default.z--worker-machine-typezIDefault type of machine to use for workers. Defaults to server-specified.z--subnetworkzODefault Compute Engine subnetwork for launching instances to run your pipeline.z	--networkzLDefault Compute Engine network for launching instances to run your pipeline.z--dataflow-kms-keyz3Default Cloud KMS key to protect the job resources.z--worker-regionz%Default region to run the workers in.z--worker-zonez#Default zone to run the workers in.z--enable-streaming-enginez9Enable Streaming Engine for the streaming job by default.z--gcs-log-dirzYGoogle Cloud Storage directory to save build logs.(Must be a URL beginning with 'gs://'.)N)r   r   r   z--additional-experimentsADDITIONAL_EXPERIMENTSz'Default experiments to pass to the job.)r   r   r   r   z--additional-user-labelsADDITIONAL_USER_LABELSz]Default user labels to pass to the job. Example: --additional-user-labels='{"key1":"value1"}'z--image-gcr-pathzpThe Google Container Registry or Google Artifact Registry location to store the flex template image to be built.z0^(.*\.){0,1}gcr.io/.*|^(.){2,}-docker.pkg.dev/.*a  Must begin with '[multi-region.]gcr.io/' or '[region.]-docker.pkg.dev/'. Please check https://cloud.google.com/container-registry/docs/overview for available multi-regions in GCR or https://cloud.google.com/artifact-registry/docs/repo-organize#locations for available location in GAR)r   r   r   z--jarJARa  Local path to your dataflow pipeline jar file and all their dependent jar files required for the flex template classpath. You can pass them as a comma separated list or repeat individually with --jar flag. Ex: --jar="code.jar,dep.jar" or --jar code.jar, --jar dep.jar.z	--py-pathPY_PATHa<  Local path to your dataflow pipeline python files and all their dependent files required for the flex template classpath. You can pass them as a comma separated list or repeat individually with --py-path flag. Ex: --py-path="path/pipleline/,path/dependency/" or --py-path path/pipleline/, --py-path path/dependency/.z--go-binary-pathGO_BINARY_PATHzLocal path to your compiled dataflow pipeline Go binary. The binary should be compiled to run on the target worker architecture (usually linux-amd64). See https://beam.apache.org/documentation/sdks/go-cross-compilation/ for more information.)r   r   z--yaml-pipeline-pathYAML_PIPELINE_PATHz&Local path to your YAML pipeline file.)r   r   r   r   z--yaml-image
YAML_IMAGEzLPath to the any image registry location of the prebuilt yaml template image.z--flex-template-base-imagea  Flex template base image to be used while building the container image. Allowed choices are allowed labels (JAVA11/17/21/25, PYTHON3, GO), supported distroless images (JAVA11/17/21/25_DISTROLESS, GO_DISTROLESS), or full gcr.io path of the specific version of the base image. For labels, we use the latest base image version to build the container. You can also provide a specific version from this link  https://gcr.io/dataflow-templates-base/zM^(JAVA11|JAVA17|JAVA21|JAVA25|GO)(_DISTROLESS)?$|^JAVA8$|^PYTHON3$|^gcr.io/.*zMust be JAVA11, JAVA17, JAVA21, JAVA25, PYTHON3, GO, (or with `_DISTROLESS` suffix for supported distroless variants), or begin with 'gcr.io/'z--envENVaX  Environment variables to create for the Dockerfile. You can pass them as a comma separated list or repeat individually with --env flag. Ex: --env="A=B,C=D" or --env A=B, --env C=D.When you reference files/dir in env variables, please specify relative path to the paths passed via --py-path.Ex: if you pass. --py-path="path/pipleline/" then set FLEX_TEMPLATE_PYTHON_PY_FILE="pipeline/pipeline.py" You can find the list of supported environment variables in this link. https://cloud.google.com/dataflow/docs/guides/templates/configuring-flex-templates#setting_required_dockerfile_environment_variables.)r   r   r   r   r   )add_mutually_exclusive_groupadd_argument_groupadd_argumentr   RegexpValidatorFileContentsr   StoreBooleanPropertyr
   VALUESdataflow
print_onlyintdisable_public_ipsenable_streaming_engineArgListUpdateActionArgDict)parser
image_argsimage_building_args	yaml_argsregion_grouppipeline_argss         +lib/surface/dataflow/flex_template/build.py_CommonArgsr7      s%    22D2A*"557++-)&0&&{'BD  E    
 	-4
 &&
QOP  Q 	-4
 &&
QOP  Q 	$5 &&{'BD  E 	3.	   	H##%  '
 	$))



$
$
/
/1  2 	6&&{'BD	  E 	6 &&{'BD  E 	&&|'KM;	  = 	%&&
<
,  ( 	6   	))



$
$
7
79E	  G 	9  ;
 	  
 	  
 	  
 	@  B 446,2  4 0  2 	!))



$
$
<
<>F	  H 	6&&{'BD   	 & %%0  3 	 & %%;  	 ""E&&
=57  #  &BB C - %%-  	/  %%E  
G $  & "##%3   	   """5 &&
Z ) # . "" %%
= # #     c                 L   [         R                  " U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  [        R                  R                  R                  R                  5       U R                  U R                   U R"                  [        R                  R                  R$                  R                  5       U R&                  U R(                  S9nU R*                  S:X  a  U R,                  (       d  [/        S5      e[0        R2                  " U R4                  5      nU R,                  US'   [0        R6                  " USS9U l        [         R8                  R;                  U 5      nOU R<                  nU(       d  U R>                  n[         R8                  RA                  U R>                  U RB                  U RD                  U RF                  U RH                  U RJ                  U R*                  U RL                  U RN                  5	        [         R8                  RQ                  U RR                  X0R4                  U R*                  U RT                  UU RV                  U RX                  U RZ                  5	      $ )zyRuns the command.

Args:
  args: The arguments that were provided to this command invocation.

Returns:
  A Job message.
)max_workersnum_workersnetwork
subnetworkworker_machine_typekms_key_namestaging_locationtemp_locationr+   service_account_emailworker_regionworker_zoner,   additional_experimentsadditional_user_labelsr   zyaml_pipeline_path is required.yamlDefinition   )indent).r   TemplateArgumentsr:   r;   r<   r=   r>   dataflow_kms_keyr@   rA   r
   r'   r(   r+   GetBoolrB   rC   rD   r,   rE   rF   sdk_languageyaml_pipeline_path
ValueErrorjsonloadsmetadata_filedumps	TemplatesGetYamlTemplateImageimageimage_gcr_pathBuildAndStoreFlexTemplateImageflex_template_base_imagejarpy_pathgo_binary_pathenvgcs_log_dircloud_build_service_accountBuildAndStoreFlexTemplateFiler   r)   #image_repository_username_secret_id#image_repository_password_secret_idimage_repository_cert_path)argstemplate_argsmetadata
image_paths       r6   
_CommonRunrh   S  s    ((""""ll22((,,&&#**33FFNN  66&&""(//88PPwy!88!88#:-& 
& ""899zz$,,-H!%!8!8HHQ7D44T:JJ	$$JNN11%%((
 
	5	5
!!:/A/A
-
..
..0O0O	
Q Qr8   c                   8    \ rS rSrSrSSS.r\S 5       rS rSr	g)	Buildi  z:Builds a flex template file from the specified parameters.az            To build and store a flex template JSON file, run:

            $ {command} gs://template-file-gcs-path --image=gcr://image-path               --metadata-file=/local/path/to/metadata.json --sdk-language=JAVA

          If using prebuilt template image from private registry, run:

            $ {command} gs://template-file-gcs-path               --image=private.registry.com:3000/image-path               --image-repository-username-secret-id="projects/test-project/secrets/username-secret"
              --image-repository-password-secret-id="projects/test-project/secrets/password-secret/versions/latest"
              --metadata-file=metadata.json
              --sdk-language=JAVA

          To build the template image and flex template JSON file, run:

            $ {command} gs://template-file-gcs-path               --image-gcr-path=gcr://path-to-store-image               --jar=path/to/pipeline.jar --jar=path/to/dependency.jar               --env=FLEX_TEMPLATE_JAVA_MAIN_CLASS=classpath               --flex-template-base-image=JAVA11               --metadata-file=/local/path/to/metadata.json --sdk-language=JAVA
          )DESCRIPTIONEXAMPLESc                     [        U 5        g N)r7   )r0   s    r6   Args
Build.Args  s
    r8   c                     [        U5      $ rn   )rh   )selfrd   s     r6   Run	Build.Run  s    dr8    N)
__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodro   rs   __static_attributes__ru   r8   r6   rj   rj     s3     C G	-<  r8   rj   )rz   
__future__r   r   r   rP   googlecloudsdk.api_lib.dataflowr   googlecloudsdk.callioper   r   r	   googlecloudsdk.corer
   r7   rh   DefaultUniverseOnlyReleaseTracksReleaseTrackGABETACommandrj   ru   r8   r6   <module>r      s    &  '  0 + / ( *rj	8Qv D%%(($*;*;*@*@A&DLL & B &r8   