[9.3] (backport #12363) Allow locally building multiplatform docker images #12411
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.
What does this PR do?
It allows building cross-platform docker images. We can already cross-build agent binaries, but for docker images we had a check specifically limiting them to the host architecture. However, buildx makes this pretty straightforward. This PR adds a check for buildx platform availability, and uses it if the host arch doesn't match the requested container image arch.
The cross-built container images gets the arch appended to the tag, so when building
mainfor arm64 on a amd64 host, we get the9.0.0-SNAPSHOT-arm64tag. The native image gets a tag without the suffix, which is a bit inconsistent, but preserves the current behaviour.This doesn't change anything for our CI, which builds arm images on arm hosts, but it makes cross-building locally much simpler.
This is a resubmission of #6256, which ended up having to be reverted due to unexpected breakage in unified release. We're now much better at testing that workflow in our PR CI, so this should be much safer.
Why is it important?
It's useful sometimes to be able to locally create a cross-platform manifest. I was troubleshooting some issues in our internal clusters, and wanted the SRE team to test a custom image I built, and had to hack around the build system to make it work.
Checklist
How to test this PR locally
Should build two docker images.
This is an automatic backport of pull request #12363 done by [Mergify](https://mergify.com).