micronaut-gradle-plugin
micronaut-gradle-plugin copied to clipboard
Allow building Docker images for multiple architectures (e.g. amd64, arm64, etc)
It would be nice if there were a built-in, simple, documented mechanism to build docker images (both HotSpot and natively compiled with GraalVM native-image) for multiple target architectures, most importantly amd64 and arm64.
I suppose it is currently possibly with multiple targets, etc. But it would be nice if there were an easy and documented way to do it (so easy that it is the default behavior if possible.)
Apparently this is not supported in the Gradle Docker plugin and is not trivial to add to that plugin since it uses an API and not the command line (which can use the buildx
capability)
But in 2021, I'm sure there are a great number of Micronaut developers who want to be able to build for both linux/amd64 and linux/arm64 with a single build on a single machine.
The plugin actually makes use of bmuschko's Docker plugin so it seems complicated to support this out of the box. I'm not familiar with the buildx
capability, but it's unlikely that the Micronaut plugin would implement such a feature by itself: the idea would be more to rely on other plugins capabilities for things like Docker (or GraalVM), configuring reasonable defaults, and rather focusing on Micronaut specific features in the plugin.
Thanks for the response, @melix.
Here's the (closed 🙁) upstream issue https://github.com/bmuschko/gradle-docker-plugin/issues/967
Looks like (when I have time) I'm going to have to figure out how to do this on my own.
I'm able to build a multi-architecture image using the following task:
task dockerBuildxImage(type:Exec) {
group 'build'
description "Builds multiplatform image using 'docker buildx'"
dependsOn dockerfile, buildLayers
workingDir 'build/docker/main'
executable 'docker'
args = ['buildx', 'build', '--platform', 'linux/amd64,linux/arm64', '-t', "$registry/$jitImageName:$project.version", '-t', "$registry/$jitImageName:latest", '--push', '.']
}
Which is based upon this comment upstream: https://github.com/bmuschko/gradle-docker-plugin/issues/967#issuecomment-1103768609
Is anyone able to translate the above into maven (or otherwise explain how I can build amd64 images on an M1 using maven)?
Any updates on this, please? Is there a proper way of achieving multi-architecture images when using micronaut + gradle?