sbt / sbt-native-packager

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

How to building native image for ARM #1443

Open ghost opened 3 years ago

ghost commented 3 years ago

I would like to build GraalVM native image for ARM architecture from my AMD machine. It such feature currently supported by native-packager ?

As for now I have tried to use docker image with hash in GraalVMNativeImagePlugin.generateContainerBuildImage() what should allow me to pull ARM based docker image.

Ex: GraalVMNativeImagePlugin.generateContainerBuildImage("ghcr.io/graalvm/graalvm-ce:latest@sha256:94a029ea80df5d66e5f49d30a1a4348b654e2cb8ccc7a26ec209691943a2ee8e")

Unfortunately it results in error Error response from daemon: build tag cannot contain a digest

Information

f0o commented 2 years ago

@muuki88 Is there any news regarding this? We might be facing a similar issue where we want to provide multi-arch Docker Images

muuki88 commented 2 years ago

I'm happy to help you with implementing this feature😊, but I don't have the time nor the experience or setup to build this 😃

dswiecki commented 2 years ago

@muuki88 Can you describe the steps needed to implement this feature here ? It looks as if there need to extend FROM directive with platform parameter but you are probably aware of other places that should be changed ;)

muuki88 commented 2 years ago

I have no real experience with graal + docker and especially not ARM 😅

However the concept for all formats in native packager is always the same

  1. Layout the files on disc as required for the packaging tool ( e.g. Docker / stage puts all files along with a Dockerfile in the target/docker folder
  2. Execute the packaging command with the desired parameters

Step 1 should already be available, so it's only part 2. I'll check later what SBT tasks and settings are available.

What would the packaging command look like?

kyri-petrou commented 2 years ago

I'm not an expert on GraalVM's native-image, but from what I understand is that the resulting executable is both OS and CPU architecture specific. I've been able to build linux/arm64 binaries successfully using this setting on my ARM64 Macbook: graalVMNativeImageGraalVersion := Some("22.0.0.2"). I can then containerise the native-image using a Dockerfile such as:

FROM oraclelinux:8-slim
COPY ./target/graal-native-image/my-application ./app/

CMD ./app/my-application

Assuming my understanding is correct of how native-image builds work, if you want to build a macos/arm64 binary instead that you can run locally and not in a container, you're out of luck until there is a macos/arm64 version of GraalVM/native-image. You can keep an eye out for new GraalVM releases here, and look out for something tagged darwin-aarch64-XXXX.tar.gz

I hope that helps!