Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Alpine Linux #289

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(J2V8_LIB_PLATFORM_NAME "linux")
set(J2V8_LIB_PREFIX "")
set(J2V8_LIB_ARCH_NAME "x86")

# TODO: This hack could be used to have a different lib filename for alpine, e.g. libj2v8_alpine_x86_64
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that this hack IS required. Otherwise there is no possibility to deploy, since building the alpine version would overwrite the regular linux version!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, the platform + architecture combination should be the primary indicator about the binary compatibility for a shared library. Since the lib for alpine would not be compatible with "default" linux distros, it should have its own identifier here and should also be handled by the java LibraryLoader.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did push a small fix, which is less hacky and actually works :D

# However, this would require java code changes to account for the different filename
# Source: https://github.com/dotnet/coreclr/pull/5731/files
#EXEC_PROGRAM(uname ARGS -v OUTPUT_VARIABLE CMAKE_SYSTEM_KERNEL_VERSION)
#string(FIND "${CMAKE_SYSTEM_KERNEL_VERSION}" "Alpine" PAL_SYSTEM_ALPINE)
#if(PAL_SYSTEM_ALPINE EQUAL -1)
# set(J2V8_LIB_PLATFORM_NAME "alpine")
#endif()
#}
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
#{
Expand Down
3 changes: 3 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from build_system.config_android import android_config
from build_system.config_linux import linux_config
from build_system.config_alpine import alpine_config
from build_system.config_macos import macos_config
from build_system.config_win32 import win32_config

Expand All @@ -34,6 +35,7 @@
avail_targets = {
c.target_android: android_config,
c.target_linux: linux_config,
c.target_alpine: alpine_config,
c.target_macos: macos_config,
c.target_win32: win32_config,
}
Expand All @@ -53,6 +55,7 @@
choices=[
c.target_android,
c.target_linux,
c.target_alpine,
c.target_macos,
c.target_win32,
])
Expand Down
25 changes: 25 additions & 0 deletions build_system/config_alpine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import constants as c
from cross_build import BuildStep, PlatformConfig
from docker_build import DockerBuildSystem
import config_linux as lc

alpine_config = PlatformConfig(c.target_alpine, [c.arch_x86, c.arch_x64], DockerBuildSystem)

alpine_config.cross_config(BuildStep(
name="cross-compile-host",
platform=c.target_alpine,
host_cwd="$CWD/docker",
build_cwd="/j2v8",
))

alpine_config.set_file_abis({
c.arch_x64: "x86_64",
c.arch_x86: "x86"
})

# Alpine build steps are the same as for linux - just the build environment is different
alpine_config.build_step(c.build_node_js, lc.build_node_js)
alpine_config.build_step(c.build_j2v8_cmake, lc.build_j2v8_cmake)
alpine_config.build_step(c.build_j2v8_jni, lc.build_j2v8_jni)
alpine_config.build_step(c.build_j2v8_java, lc.build_j2v8_java)
alpine_config.build_step(c.build_j2v8_junit, lc.build_j2v8_junit)
1 change: 1 addition & 0 deletions build_system/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# target platforms
target_android = 'android'
target_linux = 'linux'
target_alpine = 'alpine'
target_macos = 'macos'
target_win32 = 'win32'

Expand Down
23 changes: 23 additions & 0 deletions docker/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM library/openjdk:8u131-alpine

RUN mkdir -p /temp/docker/shared/
WORKDIR /temp/docker/shared/

# NOTE: copy shared scripts and run them separately
# this helps when changing commands only in a single script,
# since it will not requrie rebuilding all docker image layers
# but just the ones that were affected

COPY ./shared/install.alpine.packages.sh /temp/docker/shared
RUN ./install.alpine.packages.sh

COPY ./shared/install.maven.sh /temp/docker/shared
RUN ./install.maven.sh
ENV PATH "$PATH:/opt/apache-maven-3.5.0/bin"

# download the most critical maven dependencies for the build beforehand
COPY ./shared/pom.xml /temp
WORKDIR /temp
RUN export J2V8_PLATFORM_NAME=temp && \
export J2V8_ARCH_NAME=temp && \
mvn verify -DskipTests || true
16 changes: 16 additions & 0 deletions docker/shared/install.alpine.packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

echo "Preparing Alpine packages..."
apk add --update --no-cache \
git \
unzip \
gcc \
g++ \
curl \
file \
python \
make \
cmake \
wget \
supervisor \
bash \
linux-headers
1 change: 1 addition & 0 deletions docker/shared/install.maven.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

echo "Preparing Maven..."
curl http://www-eu.apache.org/dist/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz -O
mkdir -p /opt
tar xzvf apache-maven-3.5.0-bin.tar.gz -C /opt/
chmod -R 777 /opt/apache-maven-3.5.0