Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/google/adk/cli/cli_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ def _ensure_agent_engine_dependency(requirements_txt_path: str) -> None:
f.write(f'google-adk[a2a]=={__version__}\n')


def _get_agent_requirements_copy(
app_name: str, requirements_txt_path: str
) -> str:
"""Returns the Dockerfile step that copies an agent's requirements file."""
if not os.path.exists(requirements_txt_path):
return ''
return (
f'COPY --chown=myuser:myuser "agents/{app_name}/requirements.txt" '
f'"/app/agents/{app_name}/requirements.txt"'
)


_DOCKERFILE_TEMPLATE: Final[str] = """
FROM python:3.11-slim
WORKDIR /app
Expand All @@ -200,17 +212,18 @@ def _ensure_agent_engine_dependency(requirements_txt_path: str) -> None:
RUN python -c "import os, glob, google.adk.cli as cli; d = os.path.dirname(cli.__file__); [os.remove(f) for f in glob.glob(os.path.join(d, 'dev_server*'))]; [os.remove(f) for f in glob.glob(os.path.join(d, '__pycache__', 'dev_server*'))]" || true
# Install ADK - End

# Install Agent Deps - Start
{agent_requirements_copy}
{install_agent_deps}
# Install Agent Deps - End

# Copy agent - Start

# Set permission
COPY --chown=myuser:myuser "agents/{app_name}/" "/app/agents/{app_name}/"
{extra_packages_copy}
# Copy agent - End

# Install Agent Deps - Start
{install_agent_deps}
# Install Agent Deps - End

EXPOSE {port}

CMD adk {command} --port={port} {host_option} {service_option} {trace_to_cloud_option} {otel_to_cloud_option} {allow_origins_option} {a2a_option} {trigger_sources_option} {gemini_enterprise_option}{express_mode_option} "/app/agents"
Expand Down Expand Up @@ -855,6 +868,9 @@ def to_cloud_run(
app_name=app_name,
port=port,
command='api_server --with_ui' if with_ui else 'api_server',
agent_requirements_copy=_get_agent_requirements_copy(
app_name, requirements_txt_path
),
install_agent_deps=install_agent_deps,
service_option=_get_service_option_by_adk_version(
adk_version,
Expand Down Expand Up @@ -1380,6 +1396,9 @@ def create_dockerfile_for_agent_engine(resource_name: str) -> None:
app_name=app_name,
port=8080,
command='api_server',
agent_requirements_copy=_get_agent_requirements_copy(
app_name, requirements_txt_path
),
install_agent_deps=install_agent_deps,
service_option=_get_service_option_by_adk_version(
adk_version,
Expand Down Expand Up @@ -1560,6 +1579,9 @@ def to_gke(
app_name=app_name,
port=port,
command='api_server --with_ui' if with_ui else 'api_server',
agent_requirements_copy=_get_agent_requirements_copy(
app_name, requirements_txt_path
),
install_agent_deps=install_agent_deps,
service_option=_get_service_option_by_adk_version(
adk_version,
Expand Down
18 changes: 18 additions & 0 deletions tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,29 @@ def test_to_cloud_run_happy_path(

# Check agent dependencies installation based on include_requirements
if include_requirements:
requirements_copy = (
'COPY --chown=myuser:myuser "agents/agent/requirements.txt" '
'"/app/agents/agent/requirements.txt"'
)
agent_copy = (
'COPY --chown=myuser:myuser "agents/agent/" "/app/agents/agent/"'
)
assert requirements_copy in dockerfile_content
assert (
'RUN pip install -r "/app/agents/agent/requirements.txt"'
in dockerfile_content
)
assert (
dockerfile_content.index(requirements_copy)
< dockerfile_content.index(
'RUN pip install -r "/app/agents/agent/requirements.txt"'
)
< dockerfile_content.index(agent_copy)
)
else:
assert 'COPY --chown=myuser:myuser "agents/agent/requirements.txt"' not in (
dockerfile_content
)
assert "# No requirements.txt found." in dockerfile_content

assert (
Expand Down