33####################
44FROM registry.access.redhat.com/ubi9/python-312:latest AS base
55
6+ ARG TARGETARCH
7+
68WORKDIR /opt/app-root/bin
79
810# OS Packages needs to be installed as root
911USER 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
1550USER 1001
1651
1752# Install micropipenv to deploy packages from Pipfile.lock
18- RUN pip install --no-cache-dir -U "micropipenv[toml]"
53+ RUN --mount=type=cache,target=/root/.cache/pip \
54+ pip install --no-cache-dir -U "micropipenv[toml]"
1955
2056# Install the oc client
2157RUN curl -L https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/ocp/stable/openshift-client-linux.tar.gz \
2258 -o /tmp/openshift-client-linux.tar.gz && \
2359 tar -xzvf /tmp/openshift-client-linux.tar.gz oc && \
2460 rm -f /tmp/openshift-client-linux.tar.gz
2561
62+ ##############################
63+ # wheel-builder stage #
64+ # NOTE: Only used in s390x
65+ ##############################
66+ FROM base AS s390x-builder
67+
68+ ARG TARGETARCH
69+ USER 0
70+ WORKDIR /tmp/build-wheels
71+
72+ # Build pyarrow optimized for s390x
73+ RUN --mount=type=cache,target=/root/.cache/pip \
74+ --mount=type=cache,target=/root/.cache/dnf \
75+ if [ "$TARGETARCH" = "s390x" ]; then \
76+ # Install build dependencies (shared for pyarrow and onnx)
77+ dnf install -y cmake make gcc-c++ pybind11-devel wget && \
78+ dnf clean all && \
79+ # Build and collect pyarrow wheel
80+ git clone --depth 1 https://github.com/apache/arrow.git && \
81+ cd arrow/cpp && \
82+ mkdir release && cd release && \
83+ cmake -DCMAKE_BUILD_TYPE=Release \
84+ -DCMAKE_INSTALL_PREFIX=/usr/local \
85+ -DARROW_PYTHON=ON \
86+ -DARROW_PARQUET=ON \
87+ -DARROW_ORC=ON \
88+ -DARROW_FILESYSTEM=ON \
89+ -DARROW_JSON=ON \
90+ -DARROW_CSV=ON \
91+ -DARROW_DATASET=ON \
92+ -DARROW_DEPENDENCY_SOURCE=BUNDLED \
93+ -DARROW_WITH_LZ4=OFF \
94+ -DARROW_WITH_ZSTD=OFF \
95+ -DARROW_WITH_SNAPPY=OFF \
96+ -DARROW_BUILD_TESTS=OFF \
97+ -DARROW_BUILD_BENCHMARKS=OFF \
98+ .. && \
99+ make -j$(nproc) VERBOSE=1 && \
100+ make install -j$(nproc) && \
101+ cd ../../python && \
102+ pip install --no-cache-dir -r requirements-build.txt && \
103+ PYARROW_WITH_PARQUET=1 \
104+ PYARROW_WITH_DATASET=1 \
105+ PYARROW_WITH_FILESYSTEM=1 \
106+ PYARROW_WITH_JSON=1 \
107+ PYARROW_WITH_CSV=1 \
108+ PYARROW_PARALLEL=$(nproc) \
109+ python setup.py build_ext --build-type=release --bundle-arrow-cpp bdist_wheel && \
110+ mkdir -p /tmp/wheels && \
111+ cp dist/pyarrow-*.whl /tmp/wheels/ && \
112+ # Ensure wheels directory exists and has content
113+ ls -la /tmp/wheels/; \
114+ else \
115+ # Create empty wheels directory for non-s390x
116+ mkdir -p /tmp/wheels; \
117+ fi
118+
26119#######################
27120# runtime-datascience #
28121#######################
29122FROM base AS runtime-datascience
30123
124+ ARG TARGETARCH
31125ARG DATASCIENCE_SOURCE_CODE=runtimes/datascience/ubi9-python-3.12
32126
33127LABEL name="odh-notebook-runtime-datascience-ubi9-python-3.12" \
@@ -42,15 +136,29 @@ LABEL name="odh-notebook-runtime-datascience-ubi9-python-3.12" \
42136
43137WORKDIR /opt/app-root/bin
44138
139+ USER 0
140+ # Copy wheels from build stage (s390x only)
141+ COPY --from=s390x-builder /tmp/wheels /tmp/wheels
142+ RUN if [ "$TARGETARCH" = "s390x" ]; then \
143+ pip install --no-cache-dir /tmp/wheels/*.whl && rm -rf /tmp/wheels; \
144+ else \
145+ echo "Skipping wheel install for $TARGETARCH"; \
146+ fi
147+
45148# Install Python packages from Pipfile.lock
46149COPY ${DATASCIENCE_SOURCE_CODE}/Pipfile.lock ./
47150# Copy Elyra dependencies for air-gapped enviroment
48151COPY ${DATASCIENCE_SOURCE_CODE}/utils ./utils/
49152
50- RUN echo "Installing softwares and packages" && \
51- micropipenv install && \
153+ RUN --mount=type=cache,target=/root/.cache/pip \
154+ echo "Installing softwares and packages" && \
155+ if [ "$TARGETARCH" = "s390x" ]; then \
156+ GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 CFLAGS="-O3" CXXFLAGS="-O3" micropipenv install; \
157+ else \
158+ micropipenv install; \
159+ fi && \
52160 rm -f ./Pipfile.lock && \
53- # Fix permissions to support pip in Openshift environments \
161+ # Fix permissions to support pip in Openshift environments
54162 chmod -R g+w /opt/app-root/lib/python3.12/site-packages && \
55163 fix-permissions /opt/app-root -P
56164
0 commit comments