@@ -91,6 +91,113 @@ def main():
9191 """Agent Development Kit CLI tools."""
9292 pass
9393
94+ def add_common_deploy_options (command ):
95+ """Add common options to deploy subcommands."""
96+ options = [
97+ click .option (
98+ "--service_name" ,
99+ type = str ,
100+ default = "adk-default-service-name" ,
101+ help = (
102+ "Optional. The service name to use in target environment (default:"
103+ " 'adk-default-service-name')."
104+ ),
105+ ),
106+ click .option (
107+ "--env" ,
108+ multiple = True ,
109+ help = "Optional. Environment variables as multiple --env key=value pairs." ,
110+ ),
111+ click .option (
112+ "--provider-args" ,
113+ multiple = True ,
114+ help = "Optional. Provider-specific arguments as multiple --provider-args key=value pairs." ,
115+ ),
116+ click .option (
117+ "--app_name" ,
118+ type = str ,
119+ default = "" ,
120+ help = (
121+ "Optional. App name of the ADK API server (default: the folder name"
122+ " of the AGENT source code)."
123+ ),
124+ ),
125+ click .option (
126+ "--port" ,
127+ type = int ,
128+ default = 8000 ,
129+ help = "Optional. The port of the ADK API server (default: 8000)." ,
130+ ),
131+ click .option (
132+ "--trace_to_cloud" ,
133+ is_flag = True ,
134+ show_default = True ,
135+ default = False ,
136+ help = "Optional. Whether to enable cloud tracing for deployment." ,
137+ ),
138+ click .option (
139+ "--with_ui" ,
140+ is_flag = True ,
141+ show_default = True ,
142+ default = False ,
143+ help = (
144+ "Optional. Deploy ADK Web UI if set. (default: deploy ADK API server"
145+ " only)"
146+ ),
147+ ),
148+ click .option (
149+ "--temp_folder" ,
150+ type = str ,
151+ default = lambda : os .path .join (
152+ tempfile .gettempdir (),
153+ "deploy_src" ,
154+ datetime .now ().strftime ("%Y%m%d_%H%M%S" ),
155+ ),
156+ help = (
157+ "Optional. Temp folder for the generated source files"
158+ " (default: a timestamped folder in the system temp directory)."
159+ ),
160+ ),
161+ click .option (
162+ "--verbosity" ,
163+ type = click .Choice (
164+ ["debug" , "info" , "warning" , "error" , "critical" ], case_sensitive = False
165+ ),
166+ default = "WARNING" ,
167+ help = "Optional. Override the default verbosity level." ,
168+ ),
169+ click .option (
170+ "--session_db_url" ,
171+ help = (
172+ """Optional. The database URL to store the session.
173+
174+ - Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
175+
176+ - Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
177+
178+ - See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
179+ ),
180+ ),
181+ click .option (
182+ "--adk_version" ,
183+ type = str ,
184+ default = version .__version__ ,
185+ show_default = True ,
186+ help = (
187+ "Optional. The ADK version used in deployment. (default: the"
188+ " version in the dev environment)"
189+ ),
190+ ),
191+ click .argument (
192+ "agent" ,
193+ type = click .Path (
194+ exists = True , dir_okay = True , file_okay = False , resolve_path = True
195+ ),
196+ ),
197+ ]
198+ for option in options :
199+ command = option (command )
200+ return command
94201
95202@main .group ()
96203def deploy ():
@@ -617,26 +724,7 @@ def cli_api_server(
617724 server = uvicorn .Server (config )
618725 server .run ()
619726
620-
621- @deploy .command ("cloud_run" )
622- @click .option (
623- "--cloud-provider" ,
624- type = str ,
625- help = (
626- "Optional. Name of cloud provider where to deploy the agent. When absent,"
627- " default the agent will be deployed locally as a docker container."
628- ),
629- )
630- @click .option (
631- "--env" ,
632- multiple = True ,
633- help = "Optional. Environment variables as multiple --env key=value pairs." ,
634- )
635- @click .option (
636- "--provider-args" ,
637- multiple = True ,
638- help = "Optional. Provider-specific arguments as multiple --provider-args key=value pairs." ,
639- )
727+ @deploy .command ("cloud_run" , cls = HelpfulCommand )
640728@click .option (
641729 "--project" ,
642730 type = str ,
@@ -653,99 +741,9 @@ def cli_api_server(
653741 " gcloud run deploy will prompt later."
654742 ),
655743)
656- @click .option (
657- "--service_name" ,
658- type = str ,
659- default = "adk-default-service-name" ,
660- help = (
661- "Optional. The service name to use in Cloud Run (default:"
662- " 'adk-default-service-name')."
663- ),
664- )
665- @click .option (
666- "--app_name" ,
667- type = str ,
668- default = "" ,
669- help = (
670- "Optional. App name of the ADK API server (default: the folder name"
671- " of the AGENT source code)."
672- ),
673- )
674- @click .option (
675- "--port" ,
676- type = int ,
677- default = 8000 ,
678- help = "Optional. The port of the ADK API server (default: 8000)." ,
679- )
680- @click .option (
681- "--trace_to_cloud" ,
682- is_flag = True ,
683- show_default = True ,
684- default = False ,
685- help = "Optional. Whether to enable Cloud Trace for cloud run." ,
686- )
687- @click .option (
688- "--with_ui" ,
689- is_flag = True ,
690- show_default = True ,
691- default = False ,
692- help = (
693- "Optional. Deploy ADK Web UI if set. (default: deploy ADK API server"
694- " only)"
695- ),
696- )
697- @click .option (
698- "--temp_folder" ,
699- type = str ,
700- default = os .path .join (
701- tempfile .gettempdir (),
702- "cloud_run_deploy_src" ,
703- datetime .now ().strftime ("%Y%m%d_%H%M%S" ),
704- ),
705- help = (
706- "Optional. Temp folder for the generated Cloud Run source files"
707- " (default: a timestamped folder in the system temp directory)."
708- ),
709- )
710- @click .option (
711- "--verbosity" ,
712- type = click .Choice (
713- ["debug" , "info" , "warning" , "error" , "critical" ], case_sensitive = False
714- ),
715- default = "WARNING" ,
716- help = "Optional. Override the default verbosity level." ,
717- )
718- @click .option (
719- "--session_db_url" ,
720- help = (
721- """Optional. The database URL to store the session.
722-
723- - Use 'agentengine://<agent_engine_resource_id>' to connect to Agent Engine sessions.
724-
725- - Use 'sqlite://<path_to_sqlite_file>' to connect to a SQLite DB.
726-
727- - See https://docs.sqlalchemy.org/en/20/core/engines.html#backend-specific-urls for more details on supported DB URLs."""
728- ),
729- )
730- @click .argument (
731- "agent" ,
732- type = click .Path (
733- exists = True , dir_okay = True , file_okay = False , resolve_path = True
734- ),
735- )
736- @click .option (
737- "--adk_version" ,
738- type = str ,
739- default = version .__version__ ,
740- show_default = True ,
741- help = (
742- "Optional. The ADK version used in Cloud Run deployment. (default: the"
743- " version in the dev environment)"
744- ),
745- )
746- def cli_deploy_cloud_run (
744+ @add_common_deploy_options
745+ def cli_deploy_to_cloud_run (
747746 agent : str ,
748- cloud_provider : Optional [str ],
749747 project : Optional [str ],
750748 region : Optional [str ],
751749 service_name : str ,
@@ -769,9 +767,9 @@ def cli_deploy_cloud_run(
769767 adk deploy cloud_run --project=[project] --region=[region] path/to/my_agent
770768 """
771769 try :
772- cli_deploy .to_cloud_run (
770+ cli_deploy .run (
773771 agent_folder = agent ,
774- cloud_provider = cloud_provider ,
772+ provider = "gcp" ,
775773 project = project ,
776774 region = region ,
777775 service_name = service_name ,
@@ -788,3 +786,47 @@ def cli_deploy_cloud_run(
788786 )
789787 except Exception as e :
790788 click .secho (f"Deploy failed: { e } " , fg = "red" , err = True )
789+
790+ @deploy .command ("docker" , cls = HelpfulCommand )
791+ @add_common_deploy_options
792+ def cli_deploy_docker (
793+ agent : str ,
794+ service_name : str ,
795+ app_name : str ,
796+ temp_folder : str ,
797+ port : int ,
798+ trace_to_cloud : bool ,
799+ with_ui : bool ,
800+ verbosity : str ,
801+ session_db_url : str ,
802+ adk_version : str ,
803+ provider_args : Tuple [str ],
804+ env : Tuple [str ],
805+ ):
806+ """Deploys an agent to Docker container.
807+
808+ AGENT: The path to the agent source code folder.
809+
810+ Example:
811+ adk deploy docker path/to/my_agent
812+ """
813+ try :
814+ cli_deploy .run (
815+ agent_folder = agent ,
816+ project = None ,
817+ region = None ,
818+ provider = "docker" ,
819+ service_name = service_name ,
820+ app_name = app_name ,
821+ temp_folder = temp_folder ,
822+ port = port ,
823+ trace_to_cloud = trace_to_cloud ,
824+ with_ui = with_ui ,
825+ verbosity = verbosity ,
826+ session_db_url = session_db_url ,
827+ adk_version = adk_version ,
828+ provider_args = provider_args ,
829+ env = env ,
830+ )
831+ except Exception as e :
832+ click .secho (f"Deploy failed: { e } " , fg = "red" , err = True )
0 commit comments