Add multi-platform build support to cloud-build-docker module#32
Closed
jwbron wants to merge 1 commit into
Closed
Conversation
Add support for building Docker images for multiple architectures
(e.g., linux/amd64 and linux/arm64) using docker buildx.
Changes:
- Add `platforms` variable (default: ["linux/amd64"])
- Add cloudbuild-buildx.yml for multi-platform builds
- Update build_image.py to select buildx config when multiple platforms
- Update README with multi-platform documentation
When multiple platforms are specified, the module uses docker buildx
which supports efficient cross-compilation. For Go services with
multi-stage Dockerfiles using TARGETARCH/TARGETOS build args, this
is much faster than QEMU emulation.
Example usage:
```hcl
module "my_image" {
source = "..."
platforms = ["linux/amd64", "linux/arm64"]
# ...
}
```
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
platformsvariable for multi-architecture buildscloudbuild-buildx.ymlfor multi-platform builds using docker buildxContext
This is needed to support multi-platform builds in the webapp
service-image-buildmodule (see PR #37501).Changes
variables.tf: Addplatformsvariable (default:["linux/amd64"])main.tf: Pass platforms to external data sourcebuild_image.py: Handle platforms parameter, select buildx config for multi-platformcloudbuild-buildx.yml: New Cloud Build config using docker buildxREADME.md: Document multi-platform build usageHow it works
When a single platform is specified (default), the existing
cloudbuild.ymlwith BuildKit is used.When multiple platforms are specified (e.g.,
["linux/amd64", "linux/arm64"]), the newcloudbuild-buildx.ymlis used which:docker buildx create --name multiarch-builder --usedocker buildx build --platform=... --pushFor Go services with multi-stage Dockerfiles using
TARGETARCH/TARGETOSbuild args, this enables efficient cross-compilation (Go compiler runs natively but produces binaries for each target platform), which is much faster than QEMU emulation.Test plan
["linux/amd64", "linux/arm64"]🤖 Generated with Claude Code