@@ -8,6 +8,8 @@ ARG BASE_IMAGE
88####################
99FROM ${BASE_IMAGE} AS cpu-base
1010
11+ ARG TARGETARCH
12+
1113WORKDIR /opt/app-root/bin
1214
1315# OS Packages needs to be installed as root
@@ -19,7 +21,40 @@ RUN dnf -y upgrade --refresh --best --nodocs --noplugins --setopt=install_weak_d
1921# upgrade first to avoid fixable vulnerabilities end
2022
2123# Install useful OS packages
22- RUN dnf install -y mesa-libGL skopeo libxcrypt-compat && dnf clean all && rm -rf /var/cache/yum
24+ RUN --mount=type=cache,target=/var/cache/dnf \
25+ echo "Building for architecture: ${TARGETARCH}" && \
26+ PACKAGES="mesa-libGL skopeo libxcrypt-compat" && \
27+ # Additional dev tools only for s390x
28+ if [ "$TARGETARCH" = "s390x" ]; then \
29+ PACKAGES="$PACKAGES gcc gcc-c++ make openssl-devel autoconf automake libtool cmake python3-devel pybind11-devel openblas-devel unixODBC-devel openssl zlib-devel"; \
30+ fi && \
31+ if [ -n "$PACKAGES" ]; then \
32+ dnf install -y $PACKAGES && \
33+ dnf clean all && rm -rf /var/cache/yum; \
34+ fi
35+
36+ # For s390x only, set ENV vars and install Rust
37+ RUN if [ "$TARGETARCH" = "s390x" ]; then \
38+ # Install Rust and set up environment
39+ mkdir -p /opt/.cargo && \
40+ export HOME=/root && \
41+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup-init.sh && \
42+ chmod +x rustup-init.sh && \
43+ CARGO_HOME=/opt/.cargo HOME=/root ./rustup-init.sh -y --no-modify-path && \
44+ rm -f rustup-init.sh && \
45+ chown -R 1001:0 /opt/.cargo && \
46+ # Set environment variables
47+ echo 'export PATH=/opt/.cargo/bin:$PATH' >> /etc/profile.d/cargo.sh && \
48+ echo 'export CARGO_HOME=/opt/.cargo' >> /etc/profile.d/cargo.sh && \
49+ echo 'export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1' >> /etc/profile.d/cargo.sh; \
50+ fi
51+
52+ # Set python alternatives only for s390x (not needed for other arches)
53+ RUN if [ "$TARGETARCH" = "s390x" ]; then \
54+ alternatives --install /usr/bin/python python /usr/bin/python3.12 1 && \
55+ alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 && \
56+ python --version && python3 --version; \
57+ fi
2358
2459# Other apps and tools installed as default user
2560USER 1001
@@ -35,11 +70,69 @@ RUN curl -L https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/oc
3570 rm -f /tmp/openshift-client-linux.tar.gz
3671# Install the oc client end
3772
73+ ##############################
74+ # wheel-builder stage #
75+ # NOTE: Only used in s390x
76+ ##############################
77+ FROM cpu-base AS s390x-builder
78+
79+ ARG TARGETARCH
80+ USER 0
81+ WORKDIR /tmp/build-wheels
82+
83+ # Build pyarrow optimized for s390x
84+ RUN --mount=type=cache,target=/root/.cache/pip \
85+ --mount=type=cache,target=/root/.cache/dnf \
86+ if [ "$TARGETARCH" = "s390x" ]; then \
87+ # Install build dependencies (shared for pyarrow and onnx)
88+ dnf install -y cmake make gcc-c++ pybind11-devel wget && \
89+ dnf clean all && \
90+ # Build and collect pyarrow wheel
91+ git clone --depth 1 https://github.com/apache/arrow.git && \
92+ cd arrow/cpp && \
93+ mkdir release && cd release && \
94+ cmake -DCMAKE_BUILD_TYPE=Release \
95+ -DCMAKE_INSTALL_PREFIX=/usr/local \
96+ -DARROW_PYTHON=ON \
97+ -DARROW_PARQUET=ON \
98+ -DARROW_ORC=ON \
99+ -DARROW_FILESYSTEM=ON \
100+ -DARROW_JSON=ON \
101+ -DARROW_CSV=ON \
102+ -DARROW_DATASET=ON \
103+ -DARROW_DEPENDENCY_SOURCE=BUNDLED \
104+ -DARROW_WITH_LZ4=OFF \
105+ -DARROW_WITH_ZSTD=OFF \
106+ -DARROW_WITH_SNAPPY=OFF \
107+ -DARROW_BUILD_TESTS=OFF \
108+ -DARROW_BUILD_BENCHMARKS=OFF \
109+ .. && \
110+ make -j$(nproc) VERBOSE=1 && \
111+ make install -j$(nproc) && \
112+ cd ../../python && \
113+ pip install --no-cache-dir -r requirements-build.txt && \
114+ PYARROW_WITH_PARQUET=1 \
115+ PYARROW_WITH_DATASET=1 \
116+ PYARROW_WITH_FILESYSTEM=1 \
117+ PYARROW_WITH_JSON=1 \
118+ PYARROW_WITH_CSV=1 \
119+ PYARROW_PARALLEL=$(nproc) \
120+ python setup.py build_ext --build-type=release --bundle-arrow-cpp bdist_wheel && \
121+ mkdir -p /tmp/wheels && \
122+ cp dist/pyarrow-*.whl /tmp/wheels/ && \
123+ # Ensure wheels directory exists and has content
124+ ls -la /tmp/wheels/; \
125+ else \
126+ # Create empty wheels directory for non-s390x
127+ mkdir -p /tmp/wheels; \
128+ fi
129+
38130#######################
39131# runtime-datascience #
40132#######################
41133FROM cpu-base AS runtime-datascience
42134
135+ ARG TARGETARCH
43136ARG DATASCIENCE_SOURCE_CODE=runtimes/datascience/ubi9-python-3.12
44137
45138LABEL name="odh-notebook-runtime-datascience-ubi9-python-3.12" \
@@ -54,17 +147,37 @@ LABEL name="odh-notebook-runtime-datascience-ubi9-python-3.12" \
54147
55148WORKDIR /opt/app-root/bin
56149
57- # Install Python packages from requirements.txt
150+ USER 0
151+ # Copy wheels from build stage (s390x only)
152+ COPY --from=s390x-builder /tmp/wheels /tmp/wheels
153+ RUN if [ "$TARGETARCH" = "s390x" ]; then \
154+ pip install --no-cache-dir /tmp/wheels/*.whl && rm -rf /tmp/wheels; \
155+ else \
156+ echo "Skipping wheel install for $TARGETARCH"; \
157+ fi
158+
159+
160+ # Install Python packages from pylock.toml
58161COPY ${DATASCIENCE_SOURCE_CODE}/pylock.toml ./
59162# Copy Elyra dependencies for air-gapped enviroment
60163COPY ${DATASCIENCE_SOURCE_CODE}/utils ./utils/
61164
62- RUN echo "Installing softwares and packages" && \
63- # This may have to download and compile some dependencies, and as we don't lock requirements from `build-system.requires`,
64- # we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
65- uv pip install --strict --no-deps --no-cache --no-config --no-progress --verify-hashes --compile-bytecode --index-strategy=unsafe-best-match --requirements=./pylock.toml && \
66- # Fix permissions to support pip in Openshift environments \
165+ RUN --mount=type=cache,target=/root/.cache/pip \
166+ echo "Installing softwares and packages" && \
167+ if [ "$TARGETARCH" = "s390x" ]; then \
168+ # For s390x, we need special flags and environment variables for building packages
169+ GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 \
170+ CFLAGS="-O3" CXXFLAGS="-O3" \
171+ uv pip install --strict --no-deps --no-cache --no-config --no-progress --verify-hashes --compile-bytecode --index-strategy=unsafe-best-match --requirements=./pylock.toml; \
172+ else \
173+ # This may have to download and compile some dependencies, and as we don't lock requirements from `build-system.requires`,
174+ # we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
175+ uv pip install --strict --no-deps --no-cache --no-config --no-progress --verify-hashes --compile-bytecode --index-strategy=unsafe-best-match --requirements=./pylock.toml; \
176+ fi && \
177+ # Fix permissions to support pip in Openshift environments
67178 chmod -R g+w /opt/app-root/lib/python3.12/site-packages && \
68179 fix-permissions /opt/app-root -P
69180
181+ USER 1001
182+
70183WORKDIR /opt/app-root/src
0 commit comments