Skip to content

feat(cli): add --python_version option to adk deploy commands#4792

Open
JesserHamdaoui wants to merge 5 commits intogoogle:mainfrom
JesserHamdaoui:feat/4784-deploy-custom-python-version
Open

feat(cli): add --python_version option to adk deploy commands#4792
JesserHamdaoui wants to merge 5 commits intogoogle:mainfrom
JesserHamdaoui:feat/4784-deploy-custom-python-version

Conversation

@JesserHamdaoui
Copy link

Summary


1. Link to an existing issue:

Problem:
The Dockerfile template used in adk deploy cloud_run and adk deploy gke hardcoded python:3.11-slim as the base image. This made it impossible to deploy agents that require a newer Python runtime (e.g., 3.12, 3.13) without manually patching the generated Dockerfile.

Solution:
Parameterize the Dockerfile base image by adding a --python_version CLI option to both adk deploy cloud_run and adk deploy gke. The option defaults to "3.11" to preserve existing behavior.

  • _DOCKERFILE_TEMPLATE in cli_deploy.py: replaced python:3.11-slim with python:{python_version}-slim.
  • to_cloud_run() and to_gke(): added python_version: str = "3.11" parameter, forwarded to the template .format() call.
  • cli_deploy_cloud_run and cli_deploy_gke in cli_tools_click.py: added @click.option("--python_version", ...) with default="3.11", forwarded to the deploy functions.

Usage:

# Deploy with Python 3.12
adk deploy cloud_run --python_version 3.12 ./my_agent

# Deploy with Python 3.13
adk deploy gke --python_version 3.13 --cluster_name my-cluster ./my_agent

# Default behavior unchanged
adk deploy cloud_run ./my_agent  # still uses python:3.11-slim

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Updated 3 existing test files:

  • test_cli_deploy_to_cloud_run.py: updated happy path to pass python_version="3.12" and assert FROM python:3.12-slim in the Dockerfile; added test_to_cloud_run_default_python_version to verify the 3.11 default.
  • test_cli_deploy.py: updated GKE happy path to pass python_version="3.12" and assert FROM python:3.12-slim.
  • test_cli_tools_click.py: added test_cli_deploy_cloud_run_python_version and test_cli_deploy_gke_python_version to verify --python_version is forwarded correctly.

Adds a --python_version CLI flag to both `adk deploy cloud_run` and
`adk deploy gke` commands. Previously the Dockerfile base image was
hardcoded to `python:3.11-slim`, making it impossible to deploy agents
that require a newer Python version. Defaults to "3.11" to preserve
existing behaviour.

Fixes google#4784
…ython_version assertions

Adds test coverage for the new --python_version option in both
to_cloud_run and to_gke deploy functions, as well as the CLI wiring.
- Asserts correct rendering of the python_version in the Dockerfile template
- Verifies CLI passthrough for --python_version on both cloud_run and gke commands
- Ensures default and custom values are handled as expected

Related to google#4784
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the adk deploy CLI commands by introducing a --python_version option. This allows users to specify the Python runtime version for their agent's Docker image when deploying to Cloud Run or GKE, addressing the previous limitation of a hardcoded Python 3.11 base image. The change provides greater flexibility for agents requiring different Python environments while maintaining existing default behavior.

Highlights

  • New CLI Option: Introduced a --python_version option for adk deploy cloud_run and adk deploy gke commands, allowing users to specify the Python runtime version for their agent's Docker image.
  • Dockerfile Parameterization: The Dockerfile template used for deployments was updated to dynamically incorporate the specified Python version, replacing the previously hardcoded python:3.11-slim base image.
  • Backward Compatibility: The new --python_version option defaults to 3.11, ensuring that existing deployment behaviors remain unchanged if the option is not explicitly provided.
  • Unit Test Coverage: Added and updated unit tests to validate the new --python_version functionality, including tests for explicit version setting and the default behavior.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/google/adk/cli/cli_deploy.py
    • Modified the _DOCKERFILE_TEMPLATE to use a python_version placeholder.
    • Added python_version parameter to _get_service_option_by_adk_version, to_cloud_run, and to_gke functions with a default of '3.11'.
    • Passed python_version to the Dockerfile template formatting in to_cloud_run and to_gke.
  • src/google/adk/cli/cli_tools_click.py
    • Added @click.option("--python_version", ...) to the cli_deploy_cloud_run and cli_deploy_gke commands.
    • Added python_version parameter to cli_deploy_cloud_run and cli_deploy_gke functions.
    • Forwarded python_version from CLI options to the respective cli_deploy functions.
  • tests/unittests/cli/utils/test_cli_deploy.py
    • Updated GKE deployment test to pass python_version="3.12" and assert the correct Dockerfile content.
  • tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py
    • Updated test_to_cloud_run_happy_path to pass python_version="3.12" and assert the correct Dockerfile content.
    • Added test_to_cloud_run_default_python_version to verify the default Python 3.11 behavior in the Dockerfile.
  • tests/unittests/cli/utils/test_cli_tools_click.py
    • Added test_cli_deploy_gke_python_version to confirm the --python_version CLI option is correctly forwarded to cli_deploy.to_gke.
Activity
  • Unit tests were added or updated to cover the new functionality.
  • All unit tests pass locally.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a --python_version option to the adk deploy commands to allow specifying the Python version for the Docker base image. My review focuses on improving code maintainability and test coverage. I've identified an unused parameter, an opportunity to refactor duplicated code, and a missing unit test. Please see the specific comments for details.

Comment on lines +1759 to +1768
@click.option(
"--python_version",
type=str,
default="3.11",
show_default=True,
help=(
"Optional. The Python version used in the Docker base image."
" (default: 3.11)"
),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This @click.option for --python_version is duplicated for the cli_deploy_gke command as well. To improve maintainability and avoid duplication, consider creating a reusable decorator for this option, similar to how adk_services_options is implemented.

For example:

def python_version_option():
  return click.option(
      "--python_version",
      type=str,
      default="3.11",
      show_default=True,
      help=(
          "Optional. The Python version used in the Docker base image."
          " (default: 3.11)"
      ),
  )

@deploy.command(...)
@python_version_option()
def cli_deploy_cloud_run(...):
  ...

@deploy.command(...)
@python_version_option()
def cli_deploy_gke(...):
  ...

This change would make the code more DRY (Don't Repeat Yourself).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I should implement this or stick to the existing pattern used for the other flag parameters

@JesserHamdaoui JesserHamdaoui force-pushed the feat/4784-deploy-custom-python-version branch from 19eb7f2 to 637a611 Compare March 12, 2026 05:59
@JesserHamdaoui JesserHamdaoui changed the title feat(cli): add --python_version option to adk deploy commands #4784 feat(cli): add --python_version option to adk deploy commands Mar 12, 2026
@adk-bot adk-bot added the tools [Component] This issue is related to tools label Mar 12, 2026
@rohityan rohityan self-assigned this Mar 12, 2026
@rohityan
Copy link
Collaborator

Hi @JesserHamdaoui , Thank you for your contribution! We appreciate you taking the time to submit this pull request.
Please fix the failing mypy-diff tests before we can proceed with the review.

@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

request clarification [Status] The maintainer need clarification or more information from the author tools [Component] This issue is related to tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for overriding Python version in "adk deploy" commands

3 participants