Support Alpine hosts
- Dominant language
- Java
- Stars
- 178
- Forks
- 20
- PR merge metrics
- No merged PRs in 30d
Description
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.
```sh
# Required packages (libc6-compat is for `protoc`)
apk add git curl tar zip bash patch openjdk8-jdk libc6-compat
```
```patch
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)
```
Contributor guide
Assessment
This issue has not been assessed yet.