sbt / sbt-native-packager

sbt Native Packager
https://sbt-native-packager.readthedocs.io/en/stable/
BSD 2-Clause "Simplified" License
1.59k stars 439 forks source link

Cross building docker images on M1 #1503

Closed johanandren closed 1 year ago

johanandren commented 2 years ago

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