feat!: add --adk_version arg to adk deploy cloud_run.

The default version for Cloud Run deployment is changed to the version in the dev environment instead of the latest version.

PiperOrigin-RevId: 759767654
This commit is contained in:
Liang Wu 2025-05-16 15:00:47 -07:00 committed by Copybara-Service
parent 801549f734
commit a1ddf0b6cc
3 changed files with 19 additions and 3 deletions

View File

@ -42,7 +42,7 @@ ENV GOOGLE_CLOUD_LOCATION={gcp_region}
# Set up environment variables - End # Set up environment variables - End
# Install ADK - Start # Install ADK - Start
RUN pip install google-adk RUN pip install google-adk=={adk_version}
# Install ADK - End # Install ADK - End
# Copy agent - Start # Copy agent - Start
@ -86,6 +86,7 @@ def to_cloud_run(
with_ui: bool, with_ui: bool,
verbosity: str, verbosity: str,
session_db_url: str, session_db_url: str,
adk_version: str,
): ):
"""Deploys an agent to Google Cloud Run. """Deploys an agent to Google Cloud Run.
@ -114,6 +115,7 @@ def to_cloud_run(
with_ui: Whether to deploy with UI. with_ui: Whether to deploy with UI.
verbosity: The verbosity level of the CLI. verbosity: The verbosity level of the CLI.
session_db_url: The database URL to connect the session. session_db_url: The database URL to connect the session.
adk_version: The ADK version to use in Cloud Run.
""" """
app_name = app_name or os.path.basename(agent_folder) app_name = app_name or os.path.basename(agent_folder)
@ -150,6 +152,7 @@ def to_cloud_run(
if session_db_url if session_db_url
else '', else '',
trace_to_cloud_option='--trace_to_cloud' if trace_to_cloud else '', trace_to_cloud_option='--trace_to_cloud' if trace_to_cloud else '',
adk_version=adk_version,
) )
dockerfile_path = os.path.join(temp_folder, 'Dockerfile') dockerfile_path = os.path.join(temp_folder, 'Dockerfile')
os.makedirs(temp_folder, exist_ok=True) os.makedirs(temp_folder, exist_ok=True)

View File

@ -18,8 +18,6 @@ from datetime import datetime
import logging import logging
import os import os
import tempfile import tempfile
from typing import AsyncGenerator
from typing import Coroutine
from typing import Optional from typing import Optional
import click import click
@ -28,6 +26,7 @@ import uvicorn
from . import cli_create from . import cli_create
from . import cli_deploy from . import cli_deploy
from .. import version
from .cli import run_cli from .cli import run_cli
from .cli_eval import MISSING_EVAL_DEPENDENCIES_MESSAGE from .cli_eval import MISSING_EVAL_DEPENDENCIES_MESSAGE
from .fast_api import get_fast_api_app from .fast_api import get_fast_api_app
@ -712,6 +711,16 @@ def cli_api_server(
exists=True, dir_okay=True, file_okay=False, resolve_path=True exists=True, dir_okay=True, file_okay=False, resolve_path=True
), ),
) )
@click.option(
"--adk_version",
type=str,
default=version.__version__,
show_default=True,
help=(
"Optional. The ADK version used in Cloud Run deployment. (default: the"
" version in the dev environment)"
),
)
def cli_deploy_cloud_run( def cli_deploy_cloud_run(
agent: str, agent: str,
project: Optional[str], project: Optional[str],
@ -724,6 +733,7 @@ def cli_deploy_cloud_run(
with_ui: bool, with_ui: bool,
verbosity: str, verbosity: str,
session_db_url: str, session_db_url: str,
adk_version: str,
): ):
"""Deploys an agent to Cloud Run. """Deploys an agent to Cloud Run.
@ -746,6 +756,7 @@ def cli_deploy_cloud_run(
with_ui=with_ui, with_ui=with_ui,
verbosity=verbosity, verbosity=verbosity,
session_db_url=session_db_url, session_db_url=session_db_url,
adk_version=adk_version,
) )
except Exception as e: except Exception as e:
click.secho(f"Deploy failed: {e}", fg="red", err=True) click.secho(f"Deploy failed: {e}", fg="red", err=True)

View File

@ -124,6 +124,7 @@ def test_to_cloud_run_happy_path(
with_ui=True, with_ui=True,
verbosity="info", verbosity="info",
session_db_url="sqlite://", session_db_url="sqlite://",
adk_version="0.0.5",
) )
# Assertions # Assertions
@ -163,6 +164,7 @@ def test_to_cloud_run_cleans_temp_dir(
with_ui=False, with_ui=False,
verbosity="info", verbosity="info",
session_db_url=None, session_db_url=None,
adk_version="0.0.5",
) )
assert deleted["path"] == tmp_dir assert deleted["path"] == tmp_dir