Skip to content

Commit 8d1d399

Browse files
committed
update Dockerfile.cpu to enable ppc64le architecture
Signed-off-by: Md. Shafi Hussain <[email protected]>
1 parent c2cad07 commit 8d1d399

File tree

3 files changed

+209
-9
lines changed

3 files changed

+209
-9
lines changed

codeserver/ubi9-python-3.12/Dockerfile.cpu

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,55 @@
1+
####################
2+
# rpm-base #
3+
####################
4+
FROM registry.access.redhat.com/ubi9/python-312:latest AS rpm-base
5+
6+
USER root
7+
WORKDIR /root
8+
9+
ENV HOME=/root
10+
11+
ARG CODESERVER_SOURCE_CODE=codeserver/ubi9-python-3.12
12+
13+
ARG NODE_VERSION=20
14+
15+
ARG CODESERVER_VERSION=v4.98.0
16+
17+
COPY ${CODESERVER_SOURCE_CODE}/get_code_server_rpm.sh .
18+
19+
# create dummy file to ensure this stage is awaited before installing rpm
20+
RUN ./get_code_server_rpm.sh && touch /tmp/control
21+
22+
#######################
23+
# wheel caching stage #
24+
#######################
25+
FROM registry.access.redhat.com/ubi9/python-312:latest AS whl-cache
26+
27+
USER root
28+
WORKDIR /root
29+
30+
ENV HOME=/root
31+
32+
ARG CODESERVER_SOURCE_CODE=codeserver/ubi9-python-3.12
33+
34+
# copy requirements and scripts
35+
COPY ${CODESERVER_SOURCE_CODE}/pylock.toml ./
36+
COPY ${CODESERVER_SOURCE_CODE}/devel_env_setup.sh ./
37+
38+
# This stage installs (builds) all the packages needed and caches it in uv-cache
39+
# Important: Since HOME & USER for the python-312 has been changed,
40+
# we need to ensure the same cache directory is mounted in
41+
# the final stage with the necessary permissions to consume from cache
42+
RUN --mount=type=cache,target=/root/.cache/uv \
43+
pip install --no-cache uv && \
44+
# the devel script is ppc64le specific - sets up build-time dependencies
45+
source ./devel_env_setup.sh && \
46+
# This may have to download and compile some dependencies, and as we don't lock requirements from `build-system.requires`,
47+
# we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
48+
uv pip install --strict --no-deps --refresh --no-config --no-progress --verify-hashes --compile-bytecode --index-strategy=unsafe-best-match --requirements=./pylock.toml
49+
50+
# dummy file to make image build wait for this stage
51+
RUN touch /tmp/control
52+
153
####################
254
# base #
355
####################
@@ -16,6 +68,15 @@ RUN dnf -y upgrade --refresh --best --nodocs --noplugins --setopt=install_weak_d
1668
# Install useful OS packages
1769
RUN dnf install -y mesa-libGL skopeo && dnf clean all && rm -rf /var/cache/yum
1870

71+
# (ARCH-ppc64le): since wheels are compiled from source, we need shared libs available at runtime
72+
RUN --mount=type=cache,from=whl-cache,source=/root/OpenBLAS,target=/OpenBlas,rw \
73+
bash -c ' \
74+
if [[ $(uname -m) == "ppc64le" ]]; then \
75+
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm; \
76+
dnf install -y lcms2 libraqm libimagequant openjpeg2; \
77+
PREFIX=/usr/ make install -C /OpenBlas; \
78+
fi '
79+
1980
# Other apps and tools installed as default user
2081
USER 1001
2182

@@ -58,8 +119,13 @@ WORKDIR /opt/app-root/bin
58119
# Install useful OS packages
59120
RUN dnf install -y jq git-lfs libsndfile && dnf clean all && rm -rf /var/cache/yum
60121

122+
# wait for rpm-base stage (rpm builds for ppc64le)
123+
COPY --from=rpm-base /tmp/control /dev/null
124+
61125
# Install code-server
62-
RUN dnf install -y "https://github.com/coder/code-server/releases/download/${CODESERVER_VERSION}/code-server-${CODESERVER_VERSION/v/}-${TARGETARCH}.rpm" && \
126+
# Note: Use cache mounts, bind mounts fail on konflux
127+
RUN --mount=type=cache,from=rpm-base,source=/tmp/,target=/code-server-rpm/,rw \
128+
dnf install -y "/code-server-rpm/code-server-${CODESERVER_VERSION/v/}-${TARGETARCH}.rpm" && \
63129
dnf -y clean all --enablerepo='*'
64130

65131
COPY --chown=1001:0 ${CODESERVER_SOURCE_CODE}/utils utils/
@@ -138,18 +204,28 @@ ENV SHELL=/bin/bash
138204

139205
ENV PYTHONPATH=/opt/app-root/bin/python3
140206

141-
USER 1001
142-
143207
# Install useful packages from requirements.txt
144208
COPY ${CODESERVER_SOURCE_CODE}/pylock.toml ./
145209

210+
# wait for whl-cache stage (builds uv cache)
211+
COPY --from=whl-cache /tmp/control /dev/null
212+
146213
# Install packages and cleanup
147-
RUN echo "Installing softwares and packages" && \
148-
# This may have to download and compile some dependencies, and as we don't lock requirements from `build-system.requires`,
149-
# we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
150-
uv pip install --strict --no-deps --no-cache --no-config --no-progress --verify-hashes --compile-bytecode --index-strategy=unsafe-best-match --requirements=./pylock.toml && \
151-
# Fix permissions to support pip in Openshift environments \
152-
chmod -R g+w /opt/app-root/lib/python3.12/site-packages && \
214+
# install packages as USER 0 (this will allow us to consume uv cache)
215+
RUN --mount=type=cache,target=/root/.cache/uv \
216+
echo "Installing softwares and packages" && \
217+
# we can ensure wheels are consumed from the cache only by restricting internet access for uv install with '--offline' flag
218+
uv pip install --offline --cache-dir /root/.cache/uv --requirements=./pylock.toml && \
219+
# Note: debugpy wheel availabe on pypi (in uv cache) is none-any but bundles amd64.so files
220+
# Build debugpy from source instead
221+
uv pip install --no-cache git+https://github.com/microsoft/debugpy.git@v$(grep -A1 '\"debugpy\"' ./pylock.toml | grep -Eo '\b[0-9\.]+\b') && \
222+
# change ownership to default user (all packages were installed as root and has root:root ownership \
223+
chown -R 1001:0 /opt/app-root/lib
224+
225+
USER 1001
226+
227+
# Fix permissions to support pip in Openshift environments
228+
RUN chmod -R g+w /opt/app-root/lib/python3.12/site-packages && \
153229
fix-permissions /opt/app-root -P
154230

155231
WORKDIR /opt/app-root/src
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
set -eoux pipefail
3+
4+
#####################################################################################################
5+
# This script is expected to be run on ppc64le hosts as `root` #
6+
# It installs the required build-time dependencies for python wheels #
7+
# OpenBlas is built from source (instead of distro provided) with recommended flags for performance #
8+
#####################################################################################################
9+
10+
if [[ $(uname -m) == "ppc64le" ]]; then
11+
# install development packages
12+
dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
13+
dnf install -y cmake gcc-toolset-13 fribidi-devel lcms2-devel \
14+
libimagequant-devel libraqm-devel openjpeg2-devel tcl-devel tk-devel
15+
16+
# install rust
17+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
18+
19+
source /opt/rh/gcc-toolset-13/enable
20+
source "$HOME/.cargo/env"
21+
22+
export MAX_JOBS=${MAX_JOBS:-$(nproc)}
23+
export OPENBLAS_VERSION=${OPENBLAS_VERSION:-0.3.30}
24+
25+
# Install OpenBlas
26+
# IMPORTANT: Ensure Openblas is installed in the final image
27+
curl -L https://github.com/OpenMathLib/OpenBLAS/releases/download/v${OPENBLAS_VERSION}/OpenBLAS-${OPENBLAS_VERSION}.tar.gz | tar xz
28+
# rename directory for mounting (without knowing version numbers) in multistage builds
29+
mv OpenBLAS-${OPENBLAS_VERSION}/ OpenBLAS/
30+
cd OpenBLAS/
31+
make -j${MAX_JOBS} TARGET=POWER9 BINARY=64 USE_OPENMP=1 USE_THREAD=1 NUM_THREADS=120 DYNAMIC_ARCH=1 INTERFACE64=0
32+
make install
33+
cd ..
34+
35+
# set path for openblas
36+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/OpenBLAS/lib/
37+
export PKG_CONFIG_PATH=$(find / -type d -name "pkgconfig" 2>/dev/null | tr '\n' ':')
38+
39+
else
40+
41+
# only for mounting purposes on non-ppc64le
42+
mkdir -p /root/OpenBLAS/
43+
44+
fi
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
4+
##############################################################################
5+
# This script is expected to be run as `root` #
6+
# It builds code-server rpm for `ppc64le` #
7+
# For other architectures, the rpm is downloaded from the available releases #
8+
##############################################################################
9+
10+
11+
# Mapping of `uname -m` values to equivalent GOARCH values
12+
declare -A UNAME_TO_GOARCH
13+
UNAME_TO_GOARCH["x86_64"]="amd64"
14+
UNAME_TO_GOARCH["aarch64"]="arm64"
15+
UNAME_TO_GOARCH["ppc64le"]="ppc64le"
16+
UNAME_TO_GOARCH["s390x"]="s390x"
17+
18+
ARCH="${UNAME_TO_GOARCH[$(uname -m)]}"
19+
20+
if [[ "$ARCH" == "ppc64le" ]]; then
21+
22+
export MAX_JOBS=${MAX_JOBS:-$(nproc)}
23+
export NODE_VERSION=${NODE_VERSION:-20}
24+
export CODESERVER_VERSION=${CODESERVER_VERSION:-v4.98.0}
25+
26+
export NVM_DIR=/root/.nvm VENV=/opt/.venv
27+
export PATH=${VENV}/bin:$PATH
28+
29+
export ELECTRON_SKIP_BINARY_DOWNLOAD=1 PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
30+
31+
# install build dependencies
32+
dnf install -y jq libtool gcc-toolset-13
33+
34+
source /opt/rh/gcc-toolset-13/enable
35+
36+
# build libxkbfile
37+
git clone https://gitlab.freedesktop.org/xorg/util/macros.git
38+
cd macros/
39+
./autogen.sh && make install -j ${MAX_JOBS}
40+
export ACLOCAL_PATH=/usr/local/share/aclocal/
41+
cd .. && rm -rf macros
42+
git clone https://gitlab.freedesktop.org/xorg/lib/libxkbfile.git
43+
cd libxkbfile/
44+
./autogen.sh && make install -j ${MAX_JOBS}
45+
cd .. && rm -rf libxkbfile
46+
export PKG_CONFIG_PATH=$(find / -type d -name "pkgconfig" 2>/dev/null | tr '\n' ':')
47+
48+
# install nfpm to build rpm
49+
NFPM_VERSION=$(curl -s "https://api.github.com/repos/goreleaser/nfpm/releases/latest" | jq -r '.tag_name') \
50+
&& dnf install -y https://github.com/goreleaser/nfpm/releases/download/${NFPM_VERSION}/nfpm-${NFPM_VERSION:1}-1.$(uname -m).rpm
51+
52+
# install node
53+
NVM_VERSION=$(curl -s "https://api.github.com/repos/nvm-sh/nvm/releases/latest" | jq -r '.tag_name') \
54+
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/${NVM_VERSION}/install.sh | bash \
55+
&& source ${NVM_DIR}/nvm.sh && nvm install ${NODE_VERSION}
56+
57+
# build codeserver
58+
git clone https://github.com/coder/code-server.git
59+
cd code-server
60+
git checkout ${CODESERVER_VERSION}
61+
git submodule update --init
62+
source ${NVM_DIR}/nvm.sh
63+
while IFS= read -r src_patch; do echo "patches/$src_patch"; patch -p1 < "patches/$src_patch"; done < patches/series
64+
nvm use ${NODE_VERSION}
65+
npm install
66+
npm run build
67+
VERSION=${CODESERVER_VERSION/v/} npm run build:vscode
68+
npm run release
69+
npm run release:standalone
70+
71+
# build codeserver rpm
72+
VERSION=${CODESERVER_VERSION/v/} npm run package
73+
cp release-packages/code-server-${CODESERVER_VERSION/v/}-ppc64le.rpm /tmp/
74+
75+
else
76+
77+
# download RPM for other architectures
78+
curl -L "https://github.com/coder/code-server/releases/download/${CODESERVER_VERSION}/code-server-${CODESERVER_VERSION/v/}-${ARCH}.rpm" -o /tmp/code-server-${CODESERVER_VERSION/v/}-${ARCH}.rpm
79+
80+
fi

0 commit comments

Comments
 (0)