Skip to content

Commit a881362

Browse files
committed
Enable s390x support for runtime-datascience (Python 3.11 & 3.12)
Signed-off-by: Nishan Acharya <[email protected]>
1 parent bdfd827 commit a881362

File tree

4 files changed

+233
-12
lines changed

4 files changed

+233
-12
lines changed

runtimes/datascience/ubi9-python-3.11/Dockerfile.cpu

Lines changed: 110 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,40 @@ WORKDIR /opt/app-root/bin
88
# OS Packages needs to be installed as root
99
USER 0
1010

11-
# Install useful OS packages
12-
RUN dnf install -y mesa-libGL skopeo && dnf clean all && rm -rf /var/cache/yum
11+
ARG TARGETARCH
12+
13+
# Install useful OS packages (and dev tools for s390x only)
14+
RUN --mount=type=cache,target=/var/cache/dnf \
15+
echo "Building for architecture: ${TARGETARCH}" && \
16+
if [ "$TARGETARCH" = "s390x" ]; then \
17+
PACKAGES="mesa-libGL skopeo gcc gcc-c++ make openssl-devel autoconf automake libtool cmake python3-devel pybind11-devel openblas-devel unixODBC-devel openssl c-ares-devel zlib-devel"; \
18+
else \
19+
PACKAGES="mesa-libGL skopeo"; \
20+
fi && \
21+
echo "Installing: $PACKAGES" && \
22+
dnf install -y --nogpgcheck --allowerasing --nobest $PACKAGES && \
23+
dnf clean all && rm -rf /var/cache/yum
24+
25+
# Install Rust and set environment variables (s390x only)
26+
RUN if [ "$TARGETARCH" = "s390x" ]; then \
27+
mkdir -p /opt/.cargo && \
28+
export HOME=/root && \
29+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup-init.sh && \
30+
chmod +x rustup-init.sh && \
31+
CARGO_HOME=/opt/.cargo ./rustup-init.sh -y --no-modify-path && \
32+
rm -f rustup-init.sh && \
33+
chown -R 1001:0 /opt/.cargo && \
34+
echo 'export PATH=/opt/.cargo/bin:$PATH' >> /etc/profile.d/cargo.sh && \
35+
echo 'export CARGO_HOME=/opt/.cargo' >> /etc/profile.d/cargo.sh && \
36+
echo 'export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1' >> /etc/profile.d/cargo.sh; \
37+
fi
38+
39+
# Set python alternatives for s390x only
40+
RUN if [ "$TARGETARCH" = "s390x" ]; then \
41+
alternatives --install /usr/bin/python python /usr/bin/python3.11 1 && \
42+
alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 && \
43+
python --version && python3 --version; \
44+
fi
1345

1446
# Other apps and tools installed as default user
1547
USER 1001
@@ -23,11 +55,62 @@ RUN curl -L https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/oc
2355
tar -xzvf /tmp/openshift-client-linux.tar.gz oc && \
2456
rm -f /tmp/openshift-client-linux.tar.gz
2557

58+
##############################
59+
# wheel-builder stage #
60+
##############################
61+
FROM base AS s390x-builder
62+
63+
USER 0
64+
WORKDIR /tmp/build-wheels
65+
ARG TARGETARCH
66+
67+
RUN echo "s390x-builder stage TARGETARCH: ${TARGETARCH}"
68+
69+
RUN --mount=type=cache,target=/root/.cache/pip \
70+
--mount=type=cache,target=/root/.cache/dnf \
71+
if [ "$TARGETARCH" = "s390x" ]; then \
72+
echo "Building pyarrow wheel for s390x..." && \
73+
dnf install -y cmake make gcc-c++ pybind11-devel wget && \
74+
dnf clean all && \
75+
git clone --depth 1 https://github.com/apache/arrow.git && \
76+
cd arrow/cpp && \
77+
mkdir release && cd release && \
78+
cmake -DCMAKE_BUILD_TYPE=Release \
79+
-DCMAKE_INSTALL_PREFIX=/usr/local \
80+
-DARROW_PYTHON=ON \
81+
-DARROW_PARQUET=ON \
82+
-DARROW_ORC=ON \
83+
-DARROW_FILESYSTEM=ON \
84+
-DARROW_JSON=ON \
85+
-DARROW_CSV=ON \
86+
-DARROW_DATASET=ON \
87+
-DARROW_DEPENDENCY_SOURCE=BUNDLED \
88+
-DCMAKE_CXX_FLAGS="-O3 -march=z14 -mtune=z14" \
89+
-DCMAKE_C_FLAGS="-O3 -march=z14 -mtune=z14" \
90+
.. && \
91+
make -j$(nproc) && \
92+
make install && \
93+
cd ../../python && \
94+
pip install --no-cache-dir -U pip wheel setuptools && \
95+
pip install --no-cache-dir -r requirements-build.txt && \
96+
export PYARROW_PARALLEL=$(nproc) && \
97+
export ARROW_BUILD_TYPE=release && \
98+
CFLAGS="-O3 -march=z14 -mtune=z14" \
99+
CXXFLAGS="-O3 -march=z14 -mtune=z14" \
100+
python setup.py build_ext --build-type=release --bundle-arrow-cpp bdist_wheel && \
101+
mkdir -p /tmp/wheels && \
102+
cp dist/pyarrow-*.whl /tmp/wheels/ && \
103+
ls -la /tmp/wheels/; \
104+
else \
105+
echo "Not s390x, skipping wheel build" && mkdir -p /tmp/wheels; \
106+
fi
107+
26108
#######################
27109
# runtime-datascience #
28110
#######################
29-
FROM base AS runtime-datascience
111+
FROM base AS runtime-datascience
30112

113+
ARG TARGETARCH
31114
ARG DATASCIENCE_SOURCE_CODE=runtimes/datascience/ubi9-python-3.11
32115

33116
LABEL name="odh-notebook-runtime-datascience-ubi9-python-3.11" \
@@ -41,16 +124,37 @@ LABEL name="odh-notebook-runtime-datascience-ubi9-python-3.11" \
41124
io.openshift.build.image="quay.io/opendatahub/workbench-images:runtime-datascience-ubi9-python-3.11"
42125

43126
WORKDIR /opt/app-root/bin
127+
USER 0
128+
129+
# Install s390x-built wheels if available
130+
COPY --from=s390x-builder /tmp/wheels /tmp/wheels
131+
RUN if [ "$TARGETARCH" = "s390x" ]; then \
132+
echo "Installing s390x wheels..." && \
133+
WHEELS=$(find /tmp/wheels/ -name "pyarrow-*.whl") && \
134+
if [ -n "$WHEELS" ]; then \
135+
pip install --no-cache-dir $WHEELS && \
136+
echo "Wheel install complete"; \
137+
else \
138+
echo "No pyarrow wheel found!" && exit 1; \
139+
fi && rm -rf /tmp/wheels; \
140+
else \
141+
echo "Skipping wheel install on non-s390x (${TARGETARCH})"; \
142+
fi
44143

45144
# Install Python packages from Pipfile.lock
46145
COPY ${DATASCIENCE_SOURCE_CODE}/Pipfile.lock ./
47146
# Copy Elyra dependencies for air-gapped enviroment
48147
COPY ${DATASCIENCE_SOURCE_CODE}/utils ./utils/
49148

50-
RUN echo "Installing softwares and packages" && \
51-
micropipenv install && \
149+
RUN --mount=type=cache,target=/root/.cache/pip \
150+
echo "Installing softwares and packages" && \
151+
if [ "$TARGETARCH" = "s390x" ]; then \
152+
GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 CFLAGS="-O3" CXXFLAGS="-O3" micropipenv install; \
153+
else \
154+
micropipenv install; \
155+
fi && \
52156
rm -f ./Pipfile.lock && \
53-
# Fix permissions to support pip in Openshift environments \
157+
# Fix permissions to support pip in Openshift environments
54158
chmod -R g+w /opt/app-root/lib/python3.11/site-packages && \
55159
fix-permissions /opt/app-root -P
56160

runtimes/datascience/ubi9-python-3.11/Pipfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ scikit-learn = "~=1.6.1"
1717
scipy = "~=1.15.2"
1818
skl2onnx = "~=1.18.0"
1919
onnxconverter-common = "~=1.13.0" # Required for skl2onnx, as upgraded version is not compatible with protobuf
20-
codeflare-sdk = "~=0.30.0"
20+
21+
# Exclude these packages on s390x architecture due to compatibility
22+
codeflare-sdk = {version = "~=0.30.0", markers = "platform_machine != 's390x'"}
23+
py-spy = {version = "~=0.4.0", markers = "platform_machine != 's390x'"}
24+
ray = {version = "~=2.47.1", markers = "platform_machine != 's390x'", extras = ["data", "default"]}
25+
pyarrow = {version = "~=21.0.0", markers = "platform_machine != 's390x'"}
2126

2227
# DB connectors
2328
pymongo = "~=4.11.2"

runtimes/datascience/ubi9-python-3.12/Dockerfile.cpu

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,48 @@
33
####################
44
FROM registry.access.redhat.com/ubi9/python-312:latest AS base
55

6+
ARG TARGETARCH
7+
68
WORKDIR /opt/app-root/bin
79

810
# OS Packages needs to be installed as root
911
USER 0
1012

1113
# Install useful OS packages
12-
RUN dnf install -y mesa-libGL skopeo libxcrypt-compat && dnf clean all && rm -rf /var/cache/yum
14+
RUN --mount=type=cache,target=/var/cache/dnf \
15+
echo "Building for architecture: ${TARGETARCH}" && \
16+
PACKAGES="mesa-libGL skopeo libxcrypt-compat" && \
17+
# Additional dev tools only for s390x
18+
if [ "$TARGETARCH" = "s390x" ]; then \
19+
PACKAGES="$PACKAGES gcc gcc-c++ make openssl-devel autoconf automake libtool cmake python3-devel pybind11-devel openblas-devel unixODBC-devel openssl c-ares-devel zlib-devel"; \
20+
fi && \
21+
if [ -n "$PACKAGES" ]; then \
22+
dnf install -y --nogpgcheck --allowerasing --nobest $PACKAGES && \
23+
dnf clean all && rm -rf /var/cache/yum; \
24+
fi
25+
26+
# For s390x only, set ENV vars and install Rust
27+
RUN if [ "$TARGETARCH" = "s390x" ]; then \
28+
# Install Rust and set up environment
29+
mkdir -p /opt/.cargo && \
30+
export HOME=/root && \
31+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup-init.sh && \
32+
chmod +x rustup-init.sh && \
33+
CARGO_HOME=/opt/.cargo HOME=/root ./rustup-init.sh -y --no-modify-path && \
34+
rm -f rustup-init.sh && \
35+
chown -R 1001:0 /opt/.cargo && \
36+
# Set environment variables
37+
echo 'export PATH=/opt/.cargo/bin:$PATH' >> /etc/profile.d/cargo.sh && \
38+
echo 'export CARGO_HOME=/opt/.cargo' >> /etc/profile.d/cargo.sh && \
39+
echo 'export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1' >> /etc/profile.d/cargo.sh; \
40+
fi
41+
42+
# Set python alternatives only for s390x (not needed for other arches)
43+
RUN if [ "$TARGETARCH" = "s390x" ]; then \
44+
alternatives --install /usr/bin/python python /usr/bin/python3.12 1 && \
45+
alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 && \
46+
python --version && python3 --version; \
47+
fi
1348

1449
# Other apps and tools installed as default user
1550
USER 1001
@@ -23,11 +58,69 @@ RUN curl -L https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/oc
2358
tar -xzvf /tmp/openshift-client-linux.tar.gz oc && \
2459
rm -f /tmp/openshift-client-linux.tar.gz
2560

61+
##############################
62+
# wheel-builder stage #
63+
# NOTE: Only used in s390x
64+
##############################
65+
FROM base AS s390x-builder
66+
67+
ARG TARGETARCH
68+
USER 0
69+
WORKDIR /tmp/build-wheels
70+
71+
# Build pyarrow optimized for s390x
72+
RUN --mount=type=cache,target=/root/.cache/pip \
73+
--mount=type=cache,target=/root/.cache/dnf \
74+
if [ "$TARGETARCH" = "s390x" ]; then \
75+
# Install build dependencies (shared for pyarrow and onnx)
76+
dnf install -y cmake make gcc-c++ pybind11-devel wget && \
77+
dnf clean all && \
78+
# Build and collect pyarrow wheel
79+
git clone --depth 1 https://github.com/apache/arrow.git && \
80+
cd arrow/cpp && \
81+
mkdir release && cd release && \
82+
cmake -DCMAKE_BUILD_TYPE=Release \
83+
-DCMAKE_INSTALL_PREFIX=/usr/local \
84+
-DARROW_PYTHON=ON \
85+
-DARROW_PARQUET=ON \
86+
-DARROW_ORC=ON \
87+
-DARROW_FILESYSTEM=ON \
88+
-DARROW_JSON=ON \
89+
-DARROW_CSV=ON \
90+
-DARROW_DATASET=ON \
91+
-DARROW_DEPENDENCY_SOURCE=BUNDLED \
92+
-DARROW_WITH_LZ4=OFF \
93+
-DARROW_WITH_ZSTD=OFF \
94+
-DARROW_WITH_SNAPPY=OFF \
95+
-DARROW_BUILD_TESTS=OFF \
96+
-DARROW_BUILD_BENCHMARKS=OFF \
97+
.. && \
98+
make -j$(nproc) VERBOSE=1 && \
99+
make install -j$(nproc) && \
100+
cd ../../python && \
101+
pip install --no-cache-dir -r requirements-build.txt && \
102+
PYARROW_WITH_PARQUET=1 \
103+
PYARROW_WITH_DATASET=1 \
104+
PYARROW_WITH_FILESYSTEM=1 \
105+
PYARROW_WITH_JSON=1 \
106+
PYARROW_WITH_CSV=1 \
107+
PYARROW_PARALLEL=$(nproc) \
108+
python setup.py build_ext --build-type=release --bundle-arrow-cpp bdist_wheel && \
109+
mkdir -p /tmp/wheels && \
110+
cp dist/pyarrow-*.whl /tmp/wheels/ && \
111+
# Ensure wheels directory exists and has content
112+
ls -la /tmp/wheels/; \
113+
else \
114+
# Create empty wheels directory for non-s390x
115+
mkdir -p /tmp/wheels; \
116+
fi
117+
26118
#######################
27119
# runtime-datascience #
28120
#######################
29121
FROM base AS runtime-datascience
30122

123+
ARG TARGETARCH
31124
ARG DATASCIENCE_SOURCE_CODE=runtimes/datascience/ubi9-python-3.12
32125

33126
LABEL name="odh-notebook-runtime-datascience-ubi9-python-3.12" \
@@ -42,15 +135,29 @@ LABEL name="odh-notebook-runtime-datascience-ubi9-python-3.12" \
42135

43136
WORKDIR /opt/app-root/bin
44137

138+
USER 0
139+
# Copy wheels from build stage (s390x only)
140+
COPY --from=s390x-builder /tmp/wheels /tmp/wheels
141+
RUN if [ "$TARGETARCH" = "s390x" ]; then \
142+
pip install --no-cache-dir /tmp/wheels/*.whl && rm -rf /tmp/wheels; \
143+
else \
144+
echo "Skipping wheel install for $TARGETARCH"; \
145+
fi
146+
45147
# Install Python packages from Pipfile.lock
46148
COPY ${DATASCIENCE_SOURCE_CODE}/Pipfile.lock ./
47149
# Copy Elyra dependencies for air-gapped enviroment
48150
COPY ${DATASCIENCE_SOURCE_CODE}/utils ./utils/
49151

50-
RUN echo "Installing softwares and packages" && \
51-
micropipenv install && \
152+
RUN --mount=type=cache,target=/root/.cache/pip \
153+
echo "Installing softwares and packages" && \
154+
if [ "$TARGETARCH" = "s390x" ]; then \
155+
GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 CFLAGS="-O3" CXXFLAGS="-O3" micropipenv install; \
156+
else \
157+
micropipenv install; \
158+
fi && \
52159
rm -f ./Pipfile.lock && \
53-
# Fix permissions to support pip in Openshift environments \
160+
# Fix permissions to support pip in Openshift environments
54161
chmod -R g+w /opt/app-root/lib/python3.12/site-packages && \
55162
fix-permissions /opt/app-root -P
56163

runtimes/datascience/ubi9-python-3.12/Pipfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ scikit-learn = "~=1.6.1"
1717
scipy = "~=1.15.2"
1818
skl2onnx = "~=1.18.0"
1919
onnxconverter-common = "~=1.13.0" # Required for skl2onnx, as upgraded version is not compatible with protobuf
20-
codeflare-sdk = "~=0.29.0"
20+
21+
# Exclude these packages on s390x architecture due to compatibility
22+
codeflare-sdk = {version = "~=0.29.0", markers = "platform_machine != 's390x'"}
23+
py-spy = {version = "~=0.4.0", markers = "platform_machine != 's390x'"}
24+
ray = {version = "~=2.46.0", markers = "platform_machine != 's390x'", extras = ["data", "default"]}
25+
pyarrow = {version = "~=21.0.0", markers = "platform_machine != 's390x'"}
2126

2227
# DB connectors
2328
pymongo = "~=4.11.2"

0 commit comments

Comments
 (0)