sbt-native-packager icon indicating copy to clipboard operation
sbt-native-packager copied to clipboard

Cross building docker images on M1

Open johanandren opened this issue 2 years ago • 0 comments

For the Akka Serverless/Kalix Scala SDK we have the need for users to be able to build amd64 docker images from other cpu architectures (in practice it's probably only Apple arm64).

We are currently considering doing this with a small config change (or well, hack) for the native plugin like so:

dockerBuildCommand := {
   if (sys.props("os.arch") != "amd64") {
     // use buildx with platform to build supported amd64 images on other CPU architectures
     // this may require that you have first run 'docker buildx create' to set docker buildx up
     dockerExecCommand.value ++ Seq("buildx", "build", "--platform=linux/amd64", "--load") ++ dockerBuildOptions.value :+ "."
   } else dockerBuildCommand.value
 }

But it would be neat if there was something built into the plugin, like a setting for target docker image CPU architecture. For reference the docker-maven-plugin has such a platform attribute: https://github.com/lightbend/kalix-jvm-sdk/pull/904/files#diff-b0a4b8103a7a2702f37b74133ac07b36b18ec5dfe4fa77ceede96708bfddb911R126

johanandren avatar Apr 21 '22 09:04 johanandren