Skip to content

Add multi-platform build support to cloud-build-docker module#32

Closed
jwbron wants to merge 1 commit into
mainfrom
jwies-cloud-build-docker-multiplatform
Closed

Add multi-platform build support to cloud-build-docker module#32
jwbron wants to merge 1 commit into
mainfrom
jwies-cloud-build-docker-multiplatform

Conversation

@jwbron
Copy link
Copy Markdown
Contributor

@jwbron jwbron commented Feb 4, 2026

Summary

  • Add platforms variable for multi-architecture builds
  • Add cloudbuild-buildx.yml for multi-platform builds using docker buildx
  • Automatically select buildx config when multiple platforms specified

Context

This is needed to support multi-platform builds in the webapp service-image-build module (see PR #37501).

Changes

  • variables.tf: Add platforms variable (default: ["linux/amd64"])
  • main.tf: Pass platforms to external data source
  • build_image.py: Handle platforms parameter, select buildx config for multi-platform
  • cloudbuild-buildx.yml: New Cloud Build config using docker buildx
  • README.md: Document multi-platform build usage

How it works

When a single platform is specified (default), the existing cloudbuild.yml with BuildKit is used.

When multiple platforms are specified (e.g., ["linux/amd64", "linux/arm64"]), the new cloudbuild-buildx.yml is used which:

  1. Sets up docker buildx with docker buildx create --name multiarch-builder --use
  2. Builds and pushes directly with docker buildx build --platform=... --push

For Go services with multi-stage Dockerfiles using TARGETARCH/TARGETOS build 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

  • Test single-platform build (backwards compatibility)
  • Test multi-platform build with ["linux/amd64", "linux/arm64"]
  • Verify manifest includes both architectures

🤖 Generated with Claude Code

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>
@jwbron jwbron marked this pull request as draft February 4, 2026 21:59
@jwbron jwbron closed this Apr 10, 2026
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.

1 participant