Skip to content

Commit 12c97e9

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

File tree

5 files changed

+251
-15
lines changed

5 files changed

+251
-15
lines changed

ci/cached-builds/gen_gha_matrix_jobs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
"runtime-minimal-ubi9-python-3.12",
3636
"jupyter-minimal-ubi9-python-3.11",
3737
"jupyter-minimal-ubi9-python-3.12",
38+
"runtime-datascience-ubi9-python-3.11",
39+
"runtime-datascience-ubi9-python-3.12",
3840
# add more here
3941
}
4042

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

Lines changed: 117 additions & 7 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 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
@@ -25,11 +57,62 @@ RUN curl -L https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/oc
2557
rm -f /tmp/openshift-client-linux.tar.gz
2658
# Install the oc client end
2759

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

115+
ARG TARGETARCH
33116
ARG DATASCIENCE_SOURCE_CODE=runtimes/datascience/ubi9-python-3.11
34117

35118
LABEL name="odh-notebook-runtime-datascience-ubi9-python-3.11" \
@@ -43,17 +126,44 @@ LABEL name="odh-notebook-runtime-datascience-ubi9-python-3.11" \
43126
io.openshift.build.image="quay.io/opendatahub/workbench-images:runtime-datascience-ubi9-python-3.11"
44127

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

47146
# Install Python packages from requirements.txt
48147
COPY ${DATASCIENCE_SOURCE_CODE}/requirements.txt ./
49148
# Copy Elyra dependencies for air-gapped enviroment
50149
COPY ${DATASCIENCE_SOURCE_CODE}/utils ./utils/
51150

52-
RUN echo "Installing softwares and packages" && \
53-
# This may have to download and compile some dependencies, and as we don't lock requirements from `build-system.requires`,
54-
# we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
55-
uv pip install --strict --no-deps --no-cache --no-config --no-progress --verify-hashes --compile-bytecode --index-strategy=unsafe-best-match --requirements=./requirements.txt --build-constraints=./requirements.txt && \
56-
# Fix permissions to support pip in Openshift environments \
151+
RUN --mount=type=cache,target=/root/.cache/pip \
152+
echo "Installing softwares and packages" && \
153+
if [ "$TARGETARCH" = "s390x" ]; then \
154+
# For s390x, we need special flags and environment variables for building packages
155+
GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 \
156+
CFLAGS="-O3" CXXFLAGS="-O3" \
157+
uv pip install --strict --no-deps --no-cache --no-config --no-progress \
158+
--verify-hashes --compile-bytecode --index-strategy=unsafe-best-match \
159+
--requirements=./requirements.txt --build-constraints=./requirements.txt; \
160+
else \
161+
# This may have to download and compile some dependencies, and as we don't lock requirements from `build-system.requires`,
162+
# we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
163+
uv pip install --strict --no-deps --no-cache --no-config --no-progress \
164+
--verify-hashes --compile-bytecode --index-strategy=unsafe-best-match \
165+
--requirements=./requirements.txt --build-constraints=./requirements.txt; \
166+
fi && \
57167
chmod -R g+w /opt/app-root/lib/python3.11/site-packages && \
58168
fix-permissions /opt/app-root -P
59169

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: 120 additions & 6 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 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
@@ -25,11 +60,69 @@ RUN curl -L https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/oc
2560
rm -f /tmp/openshift-client-linux.tar.gz
2661
# Install the oc client end
2762

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

125+
ARG TARGETARCH
33126
ARG DATASCIENCE_SOURCE_CODE=runtimes/datascience/ubi9-python-3.12
34127

35128
LABEL name="odh-notebook-runtime-datascience-ubi9-python-3.12" \
@@ -44,16 +137,37 @@ LABEL name="odh-notebook-runtime-datascience-ubi9-python-3.12" \
44137

45138
WORKDIR /opt/app-root/bin
46139

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

52-
RUN echo "Installing softwares and packages" && \
53-
# This may have to download and compile some dependencies, and as we don't lock requirements from `build-system.requires`,
54-
# we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
55-
uv pip install --strict --no-deps --no-cache --no-config --no-progress --verify-hashes --compile-bytecode --index-strategy=unsafe-best-match --requirements=./requirements.txt --build-constraints=./requirements.txt && \
56-
# Fix permissions to support pip in Openshift environments \
154+
RUN --mount=type=cache,target=/root/.cache/pip \
155+
echo "Installing softwares and packages" && \
156+
if [ "$TARGETARCH" = "s390x" ]; then \
157+
# For s390x, we need special flags and environment variables for building packages
158+
GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 \
159+
CFLAGS="-O3" CXXFLAGS="-O3" \
160+
uv pip install --strict --no-deps --no-cache --no-config --no-progress \
161+
--verify-hashes --compile-bytecode --index-strategy=unsafe-best-match \
162+
--requirements=./requirements.txt --build-constraints=./requirements.txt; \
163+
else \
164+
# This may have to download and compile some dependencies, and as we don't lock requirements from `build-system.requires`,
165+
# we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
166+
uv pip install --strict --no-deps --no-cache --no-config --no-progress \
167+
--verify-hashes --compile-bytecode --index-strategy=unsafe-best-match \
168+
--requirements=./requirements.txt --build-constraints=./requirements.txt; \
169+
fi && \
170+
# Fix permissions to support pip in Openshift environments
57171
chmod -R g+w /opt/app-root/lib/python3.12/site-packages && \
58172
fix-permissions /opt/app-root -P
59173

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)