Support target platform for container builds#140
Conversation
Add an optional Platform field to ContainerBuildContext that DCP forwards to docker/podman build via --platform. This lets Aspire (and other DCP clients) request a specific build target architecture for Dockerfile builds during local dev, instead of always defaulting to the host architecture. The change is additive and opt-in: existing workloads have Platform="" which is omitted from the build command, preserving today's behavior exactly. The Equal method and GetLifecycleKey hash both include the new field so spec changes propagate correctly: changing Platform on a persistent container will trigger a rebuild. Context: microsoft/aspire#16699 / microsoft/aspire#16700. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds support for specifying a target build platform in DCP’s container build spec and forwards it through the Docker/Podman CLI orchestrators, ensuring lifecycle keys change when platform changes so persistent containers rebuild appropriately.
Changes:
- Add optional
platformtoContainerBuildContext, include it inEqual, and incorporate it intoContainerSpec.GetLifecycleKey(). - Forward
--platform <value>todocker buildandpodman buildwhen set. - Regenerate OpenAPI and add tests for build-context equality and lifecycle-key platform sensitivity.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| api/v1/container_types.go | Adds Platform, compares it in Equal, and hashes it into lifecycle key. |
| api/v1/container_types_test.go | Adds unit tests for Platform equality and lifecycle-key impact. |
| internal/docker/cli_orchestrator.go | Appends --platform to Docker build args when provided. |
| internal/podman/cli_orchestrator.go | Appends --platform to Podman build args when provided. |
| pkg/generated/openapi/zz_generated.openapi.go | Updates generated OpenAPI schema to include platform. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address PR review: writing Stage and Platform as adjacent raw byte slices made the boundary ambiguous (e.g., Stage="ab",Platform="c" hashed the same as Stage="a",Platform="bc"). Encode Platform via gob (length-framed) and only when non-empty, both to disambiguate the hash and to preserve the legacy lifecycle-key value for existing workloads where Platform is unset. Add a test asserting the boundary case produces distinct keys. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
While addressing the Stage/Platform ambiguity flagged in review, I noticed the same kind of adjacency exists today between Pre-existing, not caused by this PR — and worth flagging separately because fixing it would change lifecycle keys for all existing workloads (forcing a rebuild on upgrade). Happy to file a follow-up issue if you'd like, or leave it for the team to schedule. |
@McDonaldSean thank you for this contribution and yes, a follow-up PR for the Docker context ambiguity wrt/lifecycle key would be fantastic. |
|
I don't think I have permissions to complete the merge, but will raise another PR with the fixes mentioned above. |
|
I've merged it; we likely won't get a new DCP build inserted into Aspire until after the upcoming 13.3 release ships in a few days, but once we do you'll be able to pickup your PR there where you left off. |
Summary
Adds an optional
Platformfield toContainerBuildContextthat DCP forwards todocker/podman buildvia--platform. This lets Aspire (and other DCP clients) request a specific build target architecture for Dockerfile builds during local dev, instead of always defaulting to the host architecture.Motivation
Aspire's
AddDockerfileresource attaches aContainerBuildOptionsCallbackAnnotationwhoseTargetPlatformis honored by the publishing path (DockerContainerRuntime.RunDockerBuildAsync) but not the local-dev DCP path, because DCP's build spec had no field to carry the platform value. On hosts whose architecture differs from the resource's target platform (e.g. arm64 hosts with alinux/amd64target), the build defaulted to the host arch and could produce images for the wrong platform.Context: microsoft/aspire#16699, microsoft/aspire#16700.
Changes
api/v1/container_types.go: addPlatformfield toContainerBuildContext; update theEqualmethod to compare it.api/v1/container_types.go: includeBuild.PlatforminGetLifecycleKeyso persistent containers rebuild when their platform changes.internal/docker/cli_orchestrator.goandinternal/podman/cli_orchestrator.go: append--platform <value>when set.pkg/generated/openapi/zz_generated.openapi.go: regenerated viamake generate.api/v1/container_types_test.go: newTestContainerBuildContextEqualcovering platform-equality semantics, andTestGetLifecycleKeyIncludesBuildPlatformcovering the lifecycle-key hash.Compatibility
The change is additive and opt-in. Existing workloads have
Platform=""which is omitted from JSON (omitempty) and skipped by the orchestrators (if options.Platform != ""), so today's behavior is preserved bit-for-bit, including the FNV lifecycle-key value (writing a zero-length slice is a no-op).Test plan
make generateclean (only pre-existing API rule warnings)go test -count 1 -parallel 32 ./...— all packages pass, including integration testsmake lint— 0 issues🤖 Generated with Claude Code