fix(gcp): set HOME so the CD uses the providers baked into its image - #2232
fix(gcp): set HOME so the CD uses the providers baked into its image#2232defangdevs wants to merge 1 commit into
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
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. 📝 WalkthroughWalkthroughThe GCP CD command sets ChangesGCP CD environment
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to 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: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Comment |
The bug
Cloud Build replaces a build step's
HOME. The GCP CD image setsENV HOME=/rootand 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:
pulumi plugin lsTOTAL plugin cache size: 0 BHOME=/root369 MB—defang-gcp,gcp 9.34.1The Pulumi state confirms where the provider came from instead:
That is the
pluginDownloadURLthe generated SDK carries (sdk/v2/go/defang-gcp/internal/pulumiUtilities.go), which resolves to the latest GitHub release.Why it matters
DEFANG_CD_IMAGEpins only thecdbinary. 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.The fix
Set
HOME=/rootin the Cloud Build step env, alongside the other CD variables.Testing
TestRunCdCommandSetsHomecaptures the submitted build steps through the existinggcpDriverinterface and asserts the env pinsHOME. It fails onmainand passes with the fix.make lintclean for the changed files (the gosec hits inbyoc/awsare 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
Tests