sbt-native-packager
sbt-native-packager copied to clipboard
Cross-compilation with the JLink & Docker plugins
Observed and desired behavior
Using both the JLink an the Docker plugins, when developing on a Mac machine, I'd like to get a Docker image that would run on a Linux machine on a CPU architecture determined by the JDK base image, from which JLink would cherry-pick the required modules.
Right now docker:publishLocal
builds the package locally outside Docker, and then injects the resulting package into the Docker image with the JDK/JRE base image for the target platform. This works fine. And I greatly appreciate it. However, the resulting container image is typically relatively large. I'd like to minimize the target JDK/JRE. This issue had come up already in #1449.
Specifically, running moduleName / docker:publishLocal
performs the JLink instructions (with a lot of missing transitive dependencies, but that's a different story that I need to investigate more thoroughly) against the local JDK given by javaHome0
in JlinkPlugin.scala#L52
.
I need the JLink plugin to run inside a container against the target JDK prior to the copying stage0
.
I imagine there should be a way for cross-compiling with JLink to either
-
provide the path to another local JDK (which isn't good for replication), or
-
add a pre-stage to the resulting Dockerfile that would run either
- the entire sbt build, or
- the JLink plugin
against the target JDK, and then use that stage rather than the baseline image.
At least I can extract the JLink parameter values and pass them on to modified Dockerfile
instructions in my build.sbt
but this would get all messy with a larger CI configuration and doesn't seem ready for full build automation.
Running the entire sbt workflow inside a container would solve this issue but it would break a lot of tooling and complicate the matters, for example IntelliJ IDEA didn't support it in its 2019 versions.
If there's some simple work-around please point me in the right direction.
Information
- sbt-native-packager: 1.9.4
- sbt: 1.6.1
- Build system: macOS aarch64 M1 (local) + Debian (amd64, arm32v7l, arm64v8 / aarch64) targets
- Plugins: Docker & JLink
- Build tool: Docker version 20.10.12
- Target systems: macOS on aarch64 & amd64 (local) and Linux on amd64 & arm32v7l & arm64v8 (remote Docker machines)