Skip to content

fix(gcp): set HOME so the CD uses the providers baked into its image - #2232

Open
defangdevs wants to merge 1 commit into
mainfrom
fix/gcp-cd-home
Open

fix(gcp): set HOME so the CD uses the providers baked into its image#2232
defangdevs wants to merge 1 commit into
mainfrom
fix/gcp-cd-home

Conversation

@defangdevs

@defangdevs defangdevs commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

The bug

Cloud Build replaces a build step's HOME. The GCP CD image sets ENV HOME=/root and ships its Pulumi plugins in /root/.pulumi/plugins, but that env is overridden, so Pulumi looks somewhere else, finds no plugins, and downloads them at deploy time instead.

Verified against real Cloud Builds running the CD image, same image both times:

step env pulumi plugin ls
Cloud Build default TOTAL plugin cache size: 0 B
HOME=/root 369 MBdefang-gcp, gcp 9.34.1

The Pulumi state confirms where the provider came from instead:

urn:pulumi:beta::cdtest-cli::pulumi:providers:defang-gcp::default_github_/api.github.com/DefangLabs/pulumi-defang

That is the pluginDownloadURL the generated SDK carries (sdk/v2/go/defang-gcp/internal/pulumiUtilities.go), which resolves to the latest GitHub release.

Why it matters

  • Every GCP deploy re-downloads ~370 MB of providers and depends on github.com and the Pulumi CDN being reachable, while the copy baked into the image goes unused. In a restricted customer network it fails outright.
  • DEFANG_CD_IMAGE pins only the cd binary. The provider floats to whatever was released last, so a deployment pinned to an older CD image silently runs newer provider code. That is a reproducibility hole in the part of the system we tell people to pin.
  • It makes a custom CD image untestable, which is how this surfaced: a CD image built from a provider branch deployed released code instead, and the only visible symptom was resources named by the old code.

The fix

Set HOME=/root in the Cloud Build step env, alongside the other CD variables.

Testing

TestRunCdCommandSetsHome captures the submitted build steps through the existing gcpDriver interface and asserts the env pins HOME. It fails on main and passes with the fix.

make lint clean for the changed files (the gosec hits in byoc/aws are pre-existing on main), go test -short ./... green.

Scope

GCP only. AWS runs its CD as a CodeBuild project and Azure as a container instance; neither goes through this path, and I have not checked whether they have an equivalent problem.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Google Cloud deployment commands to use the bundled provider plugins, avoiding unnecessary plugin downloads and helping deployments run more reliably.
  • Tests

    • Added coverage to verify the deployment environment is configured correctly.

Cloud Build replaces a build step's HOME, so Pulumi looked for its plugin
cache outside the /root/.pulumi/plugins the CD image ships. It found nothing
and downloaded both providers at deploy time instead: pulumi-gcp from the CDN,
and defang-gcp from the pluginDownloadURL the generated SDK carries, which
resolves to the latest GitHub release.

Two consequences, the second worse than the first:

  - Every GCP deploy re-downloaded ~370 MB of providers and depended on
    github.com and the Pulumi CDN being reachable, while the copy in the image
    went unused.
  - Pinning DEFANG_CD_IMAGE pinned only the cd binary. The provider floated to
    whatever was released last, so a deploy pinned to an old CD image silently
    ran new provider code — and a custom CD image could not be tested at all,
    which is how this was found.

Verified against real builds: `pulumi plugin ls` in a Cloud Build step running
the CD image reports "TOTAL plugin cache size: 0 B", and 369 MB once HOME is
set. The state confirms the fallback, recording the provider as
"default_github_/api.github.com/DefangLabs/pulumi-defang".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T3WmpdY3zc555sNdkY9dzQ
@defangdevs
defangdevs requested a review from lionello as a code owner August 22, 2026 18:21
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 35bb518a-337d-4d34-9b5d-e0a57b1df827

📥 Commits

Reviewing files that changed from the base of the PR and between bd55787 and 31511fd.

📒 Files selected for processing (2)
  • src/pkg/cli/client/byoc/gcp/byoc.go
  • src/pkg/cli/client/byoc/gcp/byoc_test.go

Included review availability: 4 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.


📝 Walkthrough

Walkthrough

The GCP CD command sets HOME=/root in the Cloud Build environment. A regression test captures the generated steps and verifies this setting.

Changes

GCP CD environment

Layer / File(s) Summary
Configure and validate Cloud Build HOME
src/pkg/cli/client/byoc/gcp/byoc.go, src/pkg/cli/client/byoc/gcp/byoc_test.go
The CD Cloud Build step sets HOME=/root. The test captures the submitted steps and verifies the setting.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 31511

This change sets the expected HOME directory for GCP deployments so the image-baked providers are used; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: lionello

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main GCP fix: setting HOME so the CD uses providers bundled in its image.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

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.

2 participants