Skip to content

fix(cli): install agent deps before copying source in deploy Dockerfiles - #7181

Open
Anusha0501 wants to merge 1 commit into
google:mainfrom
Anusha0501:fix/deploy-dockerfile-cache-requirements
Open

Anusha0501 wants to merge 1 commit into
google:mainfrom
Anusha0501:fix/deploy-dockerfile-cache-requirements

Conversation

@Anusha0501

@Anusha0501 Anusha0501 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Or, if no issue exists, describe the change:

Problem:
adk deploy Dockerfiles copy the entire agent tree before pip install -r requirements.txt. Any source-only change invalidates the dependency layer and re-downloads packages.

Solution:
Copy requirements.txt into its own layer and install it before copying the rest of the agent. Cloud Run, Agent Engine, and GKE all share _DOCKERFILE_TEMPLATE, so the order is applied in one place. Agents without requirements.txt still emit the existing no-op comment.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.
PYTHONPATH=src pytest tests/unittests/cli/utils/test_cli_deploy.py::test_agent_deps_install_layer_copies_requirements_before_pip tests/unittests/cli/utils/test_cli_deploy.py::test_agent_deps_install_layer_without_requirements tests/unittests/cli/utils/test_cli_deploy.py::test_to_gke_happy_path tests/unittests/cli/utils/test_cli_deploy_to_cloud_run.py

24 passed

Asserts that COPY requirements.txt comes before RUN pip install and that both come before the full agent COPY.

Manual End-to-End (E2E) Tests:

Generate a Cloud Run Dockerfile with adk deploy cloud_run for an agent that has requirements.txt and confirm the instruction order is: copy requirements, pip install, copy agent source.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

#6928 attempted the same cache-order fix and was closed unmerged. This reapplies it on current _DOCKERFILE_TEMPLATE for all three deploy targets.

Copying the full agent tree first made every source change rebuild the
pip layer. Copy requirements.txt on its own, install, then copy the rest
so Cloud Run, Agent Engine, and GKE keep the dependency cache.

Fixes google#6923
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dockerfile should first copy requirements.txt and install dependencies before copying agent code

2 participants