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
+
1
53
####################
2
54
# base #
3
55
####################
@@ -16,6 +68,15 @@ RUN dnf -y upgrade --refresh --best --nodocs --noplugins --setopt=install_weak_d
16
68
# Install useful OS packages
17
69
RUN dnf install -y mesa-libGL skopeo && dnf clean all && rm -rf /var/cache/yum
18
70
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
+
19
80
# Other apps and tools installed as default user
20
81
USER 1001
21
82
@@ -58,8 +119,13 @@ WORKDIR /opt/app-root/bin
58
119
# Install useful OS packages
59
120
RUN dnf install -y jq git-lfs libsndfile && dnf clean all && rm -rf /var/cache/yum
60
121
122
+ # wait for rpm-base stage (rpm builds for ppc64le)
123
+ COPY --from=rpm-base /tmp/control /dev/null
124
+
61
125
# 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" && \
63
129
dnf -y clean all --enablerepo='*'
64
130
65
131
COPY --chown=1001:0 ${CODESERVER_SOURCE_CODE}/utils utils/
@@ -138,18 +204,28 @@ ENV SHELL=/bin/bash
138
204
139
205
ENV PYTHONPATH=/opt/app-root/bin/python3
140
206
141
- USER 1001
142
-
143
207
# Install useful packages from requirements.txt
144
208
COPY ${CODESERVER_SOURCE_CODE}/pylock.toml ./
145
209
210
+ # wait for whl-cache stage (builds uv cache)
211
+ COPY --from=whl-cache /tmp/control /dev/null
212
+
146
213
# 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 && \
153
229
fix-permissions /opt/app-root -P
154
230
155
231
WORKDIR /opt/app-root/src
0 commit comments