Support Alpine hosts
Cruising by experimenting with this build system :) Project I'm looking at needs scala so I'm looking at mill now… but thought there might be some interest in my efforts to get jeka to run in an Alpine container. I think there's a system property (vendor or similar) you could use to detect Alpine in the TODO section below.
# Required packages (libc6-compat is for `protoc`)
apk add git curl tar zip bash patch openjdk8-jdk libc6-compat
diff --git a/core/src/main/java/dev/jeka/core/api/utils/JkUtilsJdk.java b/core/src/main/java/dev/jeka/core/api/utils/JkUtilsJdk.java
index 493cb3b..969669f 100644
--- a/core/src/main/java/dev/jeka/core/api/utils/JkUtilsJdk.java
+++ b/core/src/main/java/dev/jeka/core/api/utils/JkUtilsJdk.java
@@ -102,7 +102,9 @@ public final class JkUtilsJdk {
final String libcType;
if (JkUtilsSystem.IS_MACOS) {
libcType = "libc";
- } else { // linux
+ } else if (JkUtilsSystem.IS_MUSL) {
+ libcType = "musl";
+ } else { // linux
libcType = "glibc";
}
return jdkDownloadUrlUnix(distrib, libcType, majorVersion, getOS(), getArch());
diff --git a/core/src/main/java/dev/jeka/core/api/utils/JkUtilsSystem.java b/core/src/main/java/dev/jeka/core/api/utils/JkUtilsSystem.java
index c29738c..e4dc7c3 100644
--- a/core/src/main/java/dev/jeka/core/api/utils/JkUtilsSystem.java
+++ b/core/src/main/java/dev/jeka/core/api/utils/JkUtilsSystem.java
@@ -49,6 +49,8 @@ public final class JkUtilsSystem {
public static final boolean IS_LINUX = isLinux();
+ public static final boolean IS_MUSL = isMusl();
+
public static final Console CONSOLE = System.console();
private static final Class UNSAFE_CLASS = JkClassLoader.ofCurrent().loadIfExist("sun.misc.Unsafe");
@@ -68,7 +70,12 @@ public final class JkUtilsSystem {
return osName.contains("nux");
}
-
+ private static boolean isMusl() {
+ if (!isLinux()) {
+ return false;
+ }
+ return true; // TODO: Figure out how to detect musl
+ }
/**
* Returns the classpath of this classloader without mentioning classpath of
diff --git a/core/src/main/shell/jeka b/core/src/main/shell/jeka
index 243879b..d2334e4 100644
--- a/core/src/main/shell/jeka
+++ b/core/src/main/shell/jeka
@@ -849,7 +849,7 @@ get_or_download_jdk() {
exit 1
fi
local download_url="https://api.foojay.io/disco/v3.0/directuris?distro=$JDK_DOWNLOAD_DISTRIB&javafx_bundled=false&libc_type=$JDK_DOWNLOAD_LIBC_TYPE&archive_type=$JDK_DOWNLOAD_FILE_TYPE&operating_system=$JDK_DOWNLOAD_OS&package_type=jdk&version=$JAVA_VERSION&architecture=$JDK_DOWNLOAD_ARCH&latest=available"
- info "Downloading JDK $JDK_DOWNLOAD_DISTRIB $JAVA_VERSION to $jdk_cache_dir. It may take a while..."
+ info "Downloading JDK $JDK_DOWNLOAD_DISTRIB $JAVA_VERSION to $jdk_cache_dir: $download_url. It may take a while..."
download_and_unpack "$download_url" "$jdk_cache_dir" "$JDK_DOWNLOAD_FILE_TYPE"
if [ "tar.gz" == "$JDK_DOWNLOAD_FILE_TYPE" ]; then
pushd "$jdk_cache_dir" > /dev/null 2>&1
@@ -896,6 +896,7 @@ compute_JAVA_CMD() {
JDK_DOWNLOAD_OS="linux"
if [ -f /etc/alpine-release ]; then
JDK_DOWNLOAD_OS=alpine-linux
+ JDK_DOWNLOAD_LIBC_TYPE=musl
fi
;;
Darwin*)
@@ -903,6 +904,11 @@ compute_JAVA_CMD() {
JDK_DOWNLOAD_LIBC_TYPE="libc"; # necessary to download proper JDK
;;
esac
+
+ case "$(ldd --version 2>&1)" in
+ *musl*)
+ JDK_DOWNLOAD_LIBC_TYPE="musl";;
+ esac
case "$(uname -m)" in
i?86)
Thank you for sharing this! I’ll plan to integrate it in a future release.
By the way, do you think adding support for Scala (e.g. via a plugin) would be relevant? Or are Scala developers generally happy with sbt and Mill?
By the way, do you think adding support for Scala (e.g. via a plugin) would be relevant? Or are Scala developers generally happy with sbt and Mill?
Not really a scala developer myself 😞 mostly just trying to help out on the infrastructure side (build tooling and such). A plugin seems reasonable to me? My fantasy for deployables is kind of the all-in-one binary (looking at GraalVM for that part) and tooling that makes it easy to get there.
So far mill seems reasonable and the auto-migrate from gradle functionality is actually very cool. Current biggest gripe is that it seems not possible to build a static mill binary with graalvm to chain into building the real project (mill wants to download and setup a lot of stuff and it's not always obvious what's going on).
Anyway, just my 2¢, thank-you for being a thoughtful maintainer and replying 🙂
Oh, and before I forget, two other references for Alpine detection:
- https://github.com/dmlc/xgboost/pull/7921
- https://github.com/awslabs/aws-crt-java/pull/661