MarkusJx / node-java-bridge

A bridge between Node.js and Java
https://markusjx.github.io/node-java-bridge/
MIT License
116 stars 6 forks source link

Create a binary using `musl` instead of `glibc` #93

Closed KangJuO closed 8 months ago

KangJuO commented 8 months ago

Currently, I am using the app after building using a normal node image. When I tried to a multi-stage build due to the image size, I couldn't use the alpine image for the following reasons.

Do you have any support plan? :)

[from description in node image] This variant is useful when final image size being as small as possible is your primary concern. The main caveat to note is that it does use musl libc instead of [glibc and friends], so software will often run into issues depending on the depth of their libc requirements/assumptions.

MarkusJx commented 8 months ago

Well, it wasn't on my to-do list, but I'll take a look at it. I'll probably just have to enable musl and publish a new package for the new binary. Won't take too long, hopefully.

In the meantime, if you are feeling adventurous, you can try building the binary yourself:

FROM node:alpine as build
RUN apk update && apk add git curl build-base clang16-libclang wget &&\
 wget -O /etc/apk/keys/adoptium.rsa.pub\
 https://packages.adoptium.net/artifactory/api/security/keypair/public/repositories/apk &&\
 echo 'https://packages.adoptium.net/artifactory/apk/alpine/main' >> /etc/apk/repositories &&\
 apk add temurin-17-jdk &&\
 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y &&\
 git clone https://github.com/MarkusJx/node-java-bridge /java-bridge
WORKDIR /java-bridge
RUN npm i && export PATH="$PATH:$HOME/.cargo/bin" &&\
 npm run build && npm pack
RUN tar xzvf java-bridge-2.4.0.tgz && cp java.* package/dist/ &&\
 cp dist/JavaBridge.jar package/dist/

FROM node:alpine
RUN apk update && apk add wget &&\
 wget -O /etc/apk/keys/adoptium.rsa.pub\
 https://packages.adoptium.net/artifactory/api/security/keypair/public/repositories/apk &&\
 echo 'https://packages.adoptium.net/artifactory/apk/alpine/main' >> /etc/apk/repositories &&\
 apk add temurin-17-jdk && apk del wget
ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk
COPY --from=build /java-bridge/package /usr/lib/node-java-bridge
WORKDIR /usr/lib/node-java-bridge
RUN npm link
ENV JAVA_HOME="/usr/lib/jvm/java-17-temurin"
ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib/jvm/java-17-temurin/lib/server"
WORKDIR /

I've had some issues with the default openjdk17 package so I've used the eclipse temurin build. The resulting image has a size of 424 MB.

MarkusJx commented 8 months ago

The musl library is now available from version 2.5.0. Sorry for the long delay.

Will close this issue for now, let me know if you encounter any issues.