
    1                        d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ dd	l
mZ d
 Ze	j                   e	j                  e	j                   j"                         G d de	j$                                      Z e	j                  e	j                   j(                         G d de             Z e	j                  e	j                   j,                         G d de             Zy)zSubmit build command.    )absolute_import)division)unicode_literalsN)cloudbuild_util)base)flags)submit_utilc                 h   | j                         }|j                  dddd       |j                  ddd	       t        j                  |        t        j                  |        t        j
                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |       }t        j                  |        t        j                  |        t        j                   |        | j"                  j%                  d
       | j"                  j'                  d       t        j(                  |        t        j*                  |        | j                  dd       | j                  dd       | j                  dt-        j.                  d             | j                  dt-        j.                  d             |S )zRegister flags for this command.

  Args:
    parser: An argparse.ArgumentParser-like object. It is mocked out in order to
      capture some information, but behaves like an ArgumentParser.

  Returns:
    worker pool flag group
  source?.a   The location of the source to build. The location can be a directory on a local disk, an archive file (e.g., .zip, .tar.gz) or a manifest file (.json) in Google Cloud Storage, a Git repo url starting with http:// or https://, a 2nd-gen Cloud Build repository resource, or a Developer Connect GitRepositoryLink resource. If the source is a local directory, this command skips the files specified in the `--ignore-file`. If `--ignore-file` is not specified, use`.gcloudignore` file. If a `.gcloudignore` file is absent and a `.gitignore` file is present in the local source directory, gcloud will use a generated Git-compatible `.gcloudignore` file that respects your .gitignored files. The global `.gitignore` is not respected. For more information on `.gcloudignore`, see `gcloud topic gcloudignore`.)nargsdefaulthelpz--no-source
store_truez:Specify that no source should be uploaded with this build.)actionr   aj  
        table(
          id,
          createTime.date('%Y-%m-%dT%H:%M:%S%Oz', undefined='-'),
          duration(start=startTime,end=finishTime,precision=0,calendar=false,undefined="  -").slice(2:).join(""):label=DURATION,
          build_source(undefined="-"):label=SOURCE,
          build_images(undefined="-"):label=IMAGES,
          status
        )
      Nz--git-source-dirzDirectory, relative to the source root, in which to run the build.
This must be a relative path. If a step's `dir` is specified and is an absolute
path, this value is ignored for that step's execution.
)r   z--git-source-revisiona  Revision to fetch from the Git repository such as a branch, a tag, a commit
SHA, or any Git ref to run the build.

Cloud Build uses `git fetch` to fetch the revision from the Git repository;
therefore make sure that the string you provide for `revision` is parsable by
the command. For information on string values accepted by `git fetch`, see
https://git-scm.com/docs/gitrevisions#_specifying_revisions. For information on
`git fetch`, see https://git-scm.com/docs/git-fetch.
z--diraf      Directory, relative to the source root, in which to run the build. This is
    used when the build source is a 2nd-gen Cloud Build repository resource, or
    a Developer Connect GitRepositoryLink resource. This must be a relative
    path. If a step's `dir` is specified and is an absolute path, this value is
    ignored for that step's execution.
    z
--revisiona      Revision to fetch from the Git repository such as a branch, a tag, a commit
    SHA, or any Git ref to run the build. This is used when the build source is
    a 2nd-gen Cloud Build repository resource, or a Developer Connect
    GitRepositoryLink resource.

    Cloud Build uses `git fetch` to fetch the revision from the Git repository;
    therefore make sure that the string you provide for `revision` is parsable
    by the command. For information on string values accepted by `git fetch`,
    see https://git-scm.com/docs/gitrevisions#_specifying_revisions. For
    information on `git fetch`, see https://git-scm.com/docs/git-fetch.
)add_mutually_exclusive_groupadd_argumentr   AddRegionFlagAddServiceAccountFlagAddGcsSourceStagingDirFlagAddGcsLogDirFlagAddTimeoutFlagAddPollingIntervalFlagAddMachineTypeFlagAddDiskSizeFlagAddSubstitutionsFlagAddDefaultBucketsBehaviorFlagAddWorkerPoolFlagAddNoCacheFlagAddAsyncFlagAddSuppressLogsFlagdisplay_info	AddFormatAddCacheUpdaterAddIgnoreFileFlagAddConfigFlagstextwrapdedent)parserr   worker_poolss      lib/surface/builds/submit.py_CommonArgsr-      s    ..0&"  ( 	G   ff%""6* vv&6"V$%%f-((0,vVF# 	!
 	 	%%d+&!v   		   	??  	  	 	??      
    c                   4    e Zd ZdZdddZdZed        Zd Zy)	SubmitISubmit a build using Cloud Build.

  Submit a build using Cloud Build.
  a            {description}

          When the `builds/use_kaniko` property is `True`, builds submitted with
          `--tag` will use Kaniko
          (https://github.com/GoogleContainerTools/kaniko) to execute builds.
          Kaniko executes directives in a Dockerfile, with remote layer caching
          for faster builds. By default, Kaniko will cache layers for 6 hours.
          To override this, set the `builds/kaniko_cache_ttl` property.
      a  
      To submit a build with source located at storage URL `gs://bucket/object.zip`:

         $ {command}  "gs://bucket/object.zip" --tag=gcr.io/my-project/image

      To submit a build with source located at storage URL `gs://bucket/object.zip`
      using config file `config.yaml`:

        $ {command} "gs://bucket/object.zip" --tag=gcr.io/my-project/image --config=config.yaml

      To submit a build with source from a source manifest:

        $ {command} "gs://bucket/manifest.json" --tag=gcr.io/my-project/image --config=config.yaml

      To submit a build with local source `source.tgz` asynchronously:

        $ {command} "source.tgz" --tag=gcr.io/my-project/image --async

      To submit a build with source from a Git repository `https://github.com/owner/repo`:

        $ {command} "https://github.com/owner/repo" --git-source-revision=main --config=config.yaml

      To submit a build with source from a 2nd-gen Cloud Build repository resource `projects/my-project/locations/us-west1/connections/my-conn/repositories/my-repo`:

        $ {command} "projects/my-project/locations/us-west1/connections/my-conn/repositories/my-repo" --revision=main

      To submit a build with source from a Developer Connect GitRepositoryLink resource `projects/my-project/locations/us-west1/connections/my-conn/gitRepositoryLinks/my-repo-link`:

        $ {command} "projects/my-project/locations/us-west1/connections/my-conn/gitRepositoryLinks/my-repo-link" --revision=main
      )DESCRIPTIONEXAMPLESFc                     t        |        y N)r-   )r*   s    r,   ArgszSubmit.Args   s
    r.   c                 2   |j                   }t        j                         }t        j                  |j
                  |j                  ||j                  |j                  |j                  d      |j                  |j                  |j                  |j                  |j                  |j                  |j                   |j"                  |j$                  |j&                  |j(                  |j*                  |j,                  |j.                  d|j0                  dd      }t        j2                  ||      }|xs t        j4                  }t        j6                  |||j                  d      |j                  |j                  |j                  |j(                  |j*                  |j$                  |j&                  |j                  d||j0                        }t        j8                  ||j:                  ||| j<                  |j>                  |j@                        \  }}|S )N  This is what gets called when the user runs this command.

    Args:
      args: an argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      Some value that we want to have printed later.

    Raises:
      FailedBuildException: If the build is completed and not 'SUCCESS'.
    r   FTgcloudsubmitsskip_set_source
client_tag)build_regionsupport_gclsuppress_logspolling_interval)!regionr   GetMessagesModuler	   CreateBuildConfigtagno_cachesubstitutionsconfigIsSpecified	no_sourcer   gcs_source_staging_dirignore_filegcs_log_dirmachine_type	disk_sizeworker_poolgit_source_dirgit_source_revisiondirrevisionservice_accountpackdefault_buckets_behaviorDetermineBuildRegionDEFAULT_REGION	SetSourceBuildasync__support_gclr?   r@   selfargsr=   messagesbuild_configbuild_s          r,   Runz
Submit.Run   s    ;;L002H 00"##  		%%"1L6 33L,OLA?#A#AL (("##  %%L$   !%%((..0HE1 Lr.   N)	__name__
__module____qualname____doc__detailed_helpr\   staticmethodr6   rd    r.   r,   r0   r0      s8    	

)-V , Kr.   r0   c                       e Zd ZdZdZy)
SubmitBetar1   TN)re   rf   rg   rh   r\   rk   r.   r,   rm   rm     s    
 ,r.   rm   c                   &    e Zd ZdZed        Zd Zy)SubmitAlphar1   c                 D    t        |       }t        j                  |       y r5   )r-   r   AddConfigFlagsAlpha)r*   r+   s     r,   r6   zSubmitAlpha.Args,  s    v&L	l+r.   c                    |j                   }t        j                         }t        j                  |j
                  |j                  ||j                  |j                  |j                  d      |j                  |j                  |j                  |j                  |j                  |j                  |j                   |j"                  |j$                  |j&                  |j(                  |j*                  |j,                  |j.                  |j0                  d|j2                  dd      }t        j4                  ||      }|xs t        j6                  }t        j8                  |||j                  d      |j                  |j                  |j                  |j(                  |j*                  |j,                  |j.                  |j                  d||j2                        }t        j:                  ||j<                  ||d|j>                        \  }}|S )r8   r   FTr9   r:   )r=   r>   r@   ) rA   r   rB   r	   CreateBuildConfigAlpharD   rE   rF   rG   rH   rI   r   rJ   rK   rL   rM   rN   memory
vcpu_countrO   rR   rS   rP   rQ   rU   rV   rW   rX   rY   rZ   r[   r@   r]   s          r,   rd   zSubmitAlpha.Run1  s    ;;L002H 55"##  		%%"3L8 33L,OLA?#A#AL (("##  %%L$   !..0HE1 Lr.   N)re   rf   rg   rh   rj   r6   rd   rk   r.   r,   ro   ro   %  s!    
 , ,Kr.   ro   )rh   
__future__r   r   r   r(   !googlecloudsdk.api_lib.cloudbuildr   googlecloudsdk.callioper   !googlecloudsdk.command_lib.buildsr   r	   r-   UniverseCompatibleReleaseTracksReleaseTrackGACreateCommandr0   BETArm   ALPHAro   rk   r.   r,   <module>r      s     &  '  = ( 3 9tn D%%(()BT B * BJ D%%**+  , D%%++,V* V -Vr.   