
    /                        S 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  \
R6                  \
R8                  " \
R:                  R<                  5       " S S\R>                  5      5       5       r \
R8                  " \
R:                  RB                  5       " S S\ 5      5       r"g)z&The gcloud app migrate-to-run command.    N)Any)appengine_api_client)
k8s_object)base)gae_to_cr_migration_util)export_image)list_incompatible_features)	translate)config_changes)flags)log)
properties)deploy)overridec                      ^  \ rS rSrSrSSS.r\S 5       r\SS j5       r\SS	 j5       r	U 4S
 jr
S\4S jrS rSS jrS rS\S\R$                  \\4   4S jrSrU =r$ )AppEngineToCloudRun%   8Migrate a second-generation App Engine app to Cloud Run.zP          Migrates the second-generation App Engine app to Cloud Run.
          a9            To migrate an App Engine app to Cloud Run:

          through app.yaml

          gcloud app migrate-to-run --appyaml=path/to/app.yaml --entrypoint=main

          OR

          through service and version

          gcloud app migrate-to-run --service=default --version=v1 --entrypoint=main

          )DESCRIPTIONEXAMPLESc                     [         R                  R                  U5        U R                  U5        U R                  U5        g )N)r   Deploy
CommonArgsAddCloudRunFlagsclsparsers     !lib/surface/app/migrate_to_run.pyArgsAppEngineToCloudRun.Args7   s.    
MMV$NN6     returnc                     UR                  SSS9  UR                  SSS9  UR                  SSS9  UR                  SS	S9  g
)zCCommon arguments for the App Engine to Cloud Run migration command.z	--appyamlzFYAML file for the second generation App Engine version to be migrated.helpz	--servicez+service name that is deployed in App Enginez	--versionz+version name that is deployed in App Enginez--entrypointz%entrypoint required for some runtimesN)add_argumentr   s     r   r   AppEngineToCloudRun.CommonArgs=   sp        :   :   4  r!   c                 .   [         R                  " U R                  5       5      nUR                  [        R
                  " 5       5        [         R                  R                  XU R                  5       5        [        R                  " U5        [        R                  R                  U5        [        R                  R                  U5        [        R                  R                  U5        [        R                  R                  U5        [        R                  R                  U5        [        R                  " U5        [        R                   " U5        [        R"                  " U5        [        R$                  " U5        [        R&                  " U5        g)zAAdds Cloud Run flags common to Alpha and Beta migration commands.N)r   ContainerArgGroupReleaseTrackAddArgumentr   ReadinessProbeFlagcontainer_parserAddContainerFlagsAddRuntimeFlagSERVICE_MESH_FLAGAddToParserIDENTITY_FLAGIDENTITY_CERTIFICATE_FLAGIDENTITY_TYPE_FLAGMESH_DATAPLANE_FLAGAddDelegateBuildsFlagAddOverflowScalingFlagAddCpuUtilizationFlagAddConcurrencyUtilizationFlagAddPresetFlags)r   r   container_argss      r   r   $AppEngineToCloudRun.AddCloudRunFlagsT   s    --c.>.>.@ANu779:
-- 0 0 2 
 	''/	##F+	##//7	((0	))&1	'	  (	'	''/	 r!   c                   > [         R                  " U R                  5       5      U l        [        R
                  " U R                  U5        U R                  5       U l        [        R                  n U R                  [        l        U R                  U5        [        TU ]1  U5        U R                  U5        U[        l        g! U[        l        f = f)zOverrides the Deploy.Run method.

This method applies wrapper logic for FlagIsExplicitlySet.

Args:
  args: The argparse namespace.
N)r   GetApiClientForTrackr*   
api_clientr   GAEToCRMigrationUtilrelease_trackr   FlagIsExplicitlySet_FlagIsExplicitlySetWrapperStartMigrationsuperRunPrintMigrationSummary)selfargsoriginal_flag_is_explicitly_set	__class__s      r   rF   AppEngineToCloudRun.Runi   s     +??DO 11$//4H**,D&+&?&?#B"&"B"Be
$ gk$
  &"Ae"Aes   2AC Cc                 D    [        U S5      =(       a    X R                  ;   $ )aP  Wrapper function to check if a flag is explicitly set.

This wrapper checks for flags added during the migration process,
in addition to the original flags.FlagIsExplicitlySet check.

Args:
  unused_args: The arguments to check (unused).
  flag: The flag to check.

Returns:
  bool: True if the flag is explicitly set, False otherwise.
_migration_flags)hasattrrN   )rH   unused_argsflags      r   rC   /AppEngineToCloudRun._FlagIsExplicitlySetWrapper   s      4+,N9N9N1NNr!   c                    [         R                  " XR                  5       5      nUR                  S[        R
                  " [        R                  5      5        UR                  [        R                  " U R                  5       5      5        U$ )z>Returns the service config changes with some default settings.r   )
r   GetServiceConfigurationChangesr*   insertr   DeleteAnnotationChanger   BINAUTHZ_BREAKGLASS_ANNOTATIONappendSetLaunchStageAnnotationChange)rH   rI   changess      r   _GetBaseChanges#AppEngineToCloudRun._GetBaseChanges   sm    2249J9J9LMGNN	--55	
 NN55d6G6G6IJ Nr!   c           	         [         R                   " UR                  UR                  UR                  5        U R                  [
        R                  R                  L a  UR                  (       a  [        R                  R                  R                  R                  5       n[        R                  " UUR                  UR                  UR                  U R                   SS9n["        R$                  " UR                  UR                  UR&                  U5      nOA["        R(                  " UR                  UR                  UR                  UR&                  5      nSR+                  U5      S-   nUR&                  (       a+  [-        USSUR&                  05        USUR&                  -   -  n[.        R0                  R3                  SUS5        [-        US	US
   5        / U l        U GH  nUR7                  S5      (       d  M  UR9                  SS5      nUR;                  S5      nUS   R9                  SS5      US'   U R4                  R=                  US   5        US   S:X  a  UR?                  US   SSS.5        M  US   S:X  a  [-        XS   US   5        M  US   S:X  a&  UR?                  US   U RA                  U5      5        M  US   S:X  a@  US   S:X  a  UR?                  US   S5        OUS   S:X  a  UR?                  US   S5        GM-  US   S:X  a/  UR?                  US   [B        RD                  " US   5      5        GMe  US   S:X  a/  UR?                  US   [B        RD                  " US   5      5        GM  US   S:X  a/  UR?                  US   [B        RF                  " US   5      5        GM  [I        U5      S:  a  UR?                  US   US   5        GM  UR?                  US   S 5        GM     g)!ap  Starts the migration process.

This method translates App Engine configuration to Cloud Run deployment
flags and updates the `args` object with these flags, preparing it
for the `gcloud run deploy` command.

Args:
  args: The argparse namespace containing command line arguments. This
    object is mutated to include flags necessary for the Cloud Run
    deployment.
N)r?   export_service_account zset-build-env-varsGOOGLE_ENTRYPOINTz( --set-build-env-vars GOOGLE_ENTRYPOINT=zCommand to run:
SERVICE   z-- =r   -_labelsz
app-enginezgcloud-app-migrate-standard-v1)zmigrated-fromzmigration-toolimage   set_env_varstimeout600iX  3600i  min_instancesmax_instancesscalingT)%r	   appyamlserviceversionrA   r   r*   ALPHA
from_imager   VALUEScoreprojectGetr   destination_repositoryr?   r
   translate_from_image
entrypointtranslate_from_sourcejoinsetattrr   statusPrintrN   
startswithreplacesplitrX   __setattr__ParseSetEnvVarsr   
ScaleValueScalingValuelen)rH   rI   ry   export_image_responsecloud_run_deploy_commandprint_deploy_commandcommand_strcommand_argss           r   rD   "AppEngineToCloudRun.StartMigration   s    99dllDLL T..444!!&&..224g*77

,,
,,

%
%__!% "+!?!?
,,
,,
//
	" "+!@!@
,,dllDOO" 88$<=C


0
 
4t
F JJ&(<dCD)5a89D/				%	%!))$3 #((-&q/11#s;Q$$\!_5?h&


1o#/$D ?g%
$Qa
9
?n,


<?D,@,@,M
N
?i'!_%\!_c2A&(\!_d3
?o-


<?E,<,<\!_,M
N
?o-


<?E,<,<\!_,M
N
?i'


<?E,>,>|A,O
P
|q 


<?LO
<


<?D
1S 0T r!   c                 n   [         R                  R                  S5        [        R                  R
                  R                  R                  5       nUR                  =(       d    Sn[        R                  R                  R                  R                  5       nU R                  [        R                  R                  L aD  UR                  (       a3  [         R                  R                  SU SU SU SU SU SU S	35        g[         R                  R                  SU SU SU SU S
U SU S	35        g)zPrints the migration summary.zU
The code and configuration of your App Engine service has been copied to Cloud Run.
defaultzPView and edit in Cloud Run console: https://console.cloud.google.com/run/detail//z/metrics?project=zW
Deploy new versions of your code with the same configuration using "gcloud run deploy z --image=<new-image> --region=z --project=z"
z --source=. --region=N)r   r   r   r   rw   runregionrz   rb   rx   ry   rA   r   r*   ru   rv   )rH   rI   r   rs   ry   s        r   rG   )AppEngineToCloudRun.PrintMigrationSummary   s%   JJ	 ""))--/Fll'iG$$,,002GT..444	jj::@7)K\]d\e f 	 "hk'#	7 
jj::@7)K\]d\e f 	 "hk'#	7r!   	input_strc                    [         R                  " SU5      nU(       d  [        R                  " 5       $ UR	                  S5      nU(       d  [        R                  " 5       $ [        R                  " S UR                  S5       5       5      nU$ )zParses a 'set-env-vars' string and converts it into an OrderedDict.

Args:
    input_str: A string in the format of
      'set-env-vars="KEY1=VALUE1,KEY2=VALUE2"'.

Returns:
    An OrderedDict containing the environment variables.
z
="([^"]*)"rj   c              3   D   #    U  H  oR                  S S5      v   M     g7f)re   rj   N)r   ).0pairs     r   	<genexpr>6AppEngineToCloudRun.ParseSetEnvVars.<locals>.<genexpr>2  s       ''=t

3'=s    ,)researchcollectionsOrderedDictgroupr   )rH   r   matchvars_stringenv_varss        r   r   #AppEngineToCloudRun.ParseSetEnvVars  st     IImY/E$$&&++a.K$$&&&& ''2'8'8'=' H Or!   )rN   r?   rA   r"   N)__name__
__module____qualname____firstlineno____doc__detailed_helpclassmethodr   r   r   rF   boolrC   r[   rD   rG   strr   r   r   __static_attributes____classcell__rK   s   @r   r   r   %   s     A	- ! !
  , ! !(B0Od O`D:sCx( r!   r   c                   f   ^  \ rS rSrSr\SU 4S jj5       r\S\S\	\\4   4U 4S jj5       r
SrU =r$ )	AppEngineToCloudRunAlphai8  r   r"   c                    > [         TU ]  U5        UR                  SSSS9  UR                  SSSS9  UR                  SSS	9  g )
Nz--from-source
store_truezUse source based migration.)actionr%   z--from-imagezUse image based migration.z--destination-repositoryzpThe full resource name of the AR repository to export to in the format of projects/*/locations/*/repositories/*.r$   )rE   r   r&   )r   r   rK   s     r   r   #AppEngineToCloudRunAlpha.CommonArgs<  sh    	Gv
*  
 )  
 "@  r!   
containersc                 h   > [        U S5      (       a  SU R                  ;   a  0 $ [        TU ]  U5      $ )NrN   ri   )rO   rN   rE   _ValidateAndGeDeployFromSource)rH   r   rK   s     r   r   7AppEngineToCloudRunAlpha._ValidateAndGeDeployFromSourceQ  s5    t'((W8M8M-M i71*==r!    r   )r   r   r   r   r   r   r   r   r   dictr   r   r   r   s   @r   r   r   8  sB    @ ( >s >tCH~ > >r!   r   )#r   r   r   typingr   googlecloudsdk.api_lib.appr   googlecloudsdk.api_lib.runr   googlecloudsdk.callioper   googlecloudsdk.command_lib.appr   7googlecloudsdk.command_lib.app.gae_to_cr_migration_utilr   r	   r
   googlecloudsdk.command_lib.runr   r   googlecloudsdk.corer   r   surface.runr   typing_extensionsr   DefaultUniverseOnlyReleaseTracksr*   BETAr   r   ru   r   r   r!   r   <module>r      s     -  	  ; 1 ( C P ^ M 9 0 # *  & D%%**+N&-- N , Nb D%%++,>2 > ->r!   