Skip to content

Commit 112c3d0

Browse files
committed
RHAIENG-2645: add loop to retry package installation when it fails
1 parent e1df047 commit 112c3d0

File tree

5 files changed

+419
-127
lines changed

5 files changed

+419
-127
lines changed

codeserver/ubi9-python-3.12/Dockerfile.cpu

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,28 @@ RUN dnf -y upgrade --refresh --nobest --skip-broken --nodocs --noplugins --setop
8585
# upgrade first to avoid fixable vulnerabilities end
8686

8787
# Install useful OS packages
88-
RUN dnf install -y perl mesa-libGL skopeo && dnf clean all && rm -rf /var/cache/yum
88+
RUN --mount=type=cache,target=/var/cache/dnf /bin/bash <<'EOF'
89+
set -Eeuxo pipefail
90+
91+
MAX_RETRIES=3
92+
RETRY_COUNT=0
93+
94+
until dnf install -y perl mesa-libGL skopeo || [ $RETRY_COUNT -ge $MAX_RETRIES ]; do
95+
RETRY_COUNT=$((RETRY_COUNT + 1))
96+
echo "dnf install failed (attempt $RETRY_COUNT/$MAX_RETRIES), retrying in 30 seconds..."
97+
dnf clean metadata
98+
sleep 30
99+
done
100+
101+
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
102+
echo "ERROR: dnf install failed after $MAX_RETRIES attempts"
103+
exit 1
104+
fi
105+
106+
dnf clean all
107+
rm -rf /var/cache/yum
108+
109+
EOF
89110

90111
# (ARCH-ppc64le): since wheels are compiled from source, we need shared libs available at runtime
91112
RUN --mount=type=cache,from=whl-cache,source=/root/OpenBLAS,target=/OpenBlas,rw \
@@ -136,7 +157,28 @@ USER 0
136157
WORKDIR /opt/app-root/bin
137158

138159
# Install useful OS packages
139-
RUN dnf install -y jq git-lfs libsndfile && dnf clean all && rm -rf /var/cache/yum
160+
RUN --mount=type=cache,target=/var/cache/dnf /bin/bash <<'EOF'
161+
set -Eeuxo pipefail
162+
163+
MAX_RETRIES=3
164+
RETRY_COUNT=0
165+
166+
until dnf install -y jq git-lfs libsndfile || [ $RETRY_COUNT -ge $MAX_RETRIES ]; do
167+
RETRY_COUNT=$((RETRY_COUNT + 1))
168+
echo "dnf install failed (attempt $RETRY_COUNT/$MAX_RETRIES), retrying in 30 seconds..."
169+
dnf clean metadata
170+
sleep 30
171+
done
172+
173+
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
174+
echo "ERROR: dnf install failed after $MAX_RETRIES attempts"
175+
exit 1
176+
fi
177+
178+
dnf clean all
179+
rm -rf /var/cache/yum
180+
181+
EOF
140182

141183
# wait for rpm-base stage (rpm builds for ppc64le)
142184
COPY --from=rpm-base /tmp/control /dev/null
@@ -175,10 +217,31 @@ ENV NGINX_CONFIGURATION_PATH=${APP_ROOT}/etc/nginx.d \
175217
NGINX_PERL_MODULE_PATH=${APP_ROOT}/etc/perl
176218

177219
# Modules does not exist
178-
RUN INSTALL_PKGS="bind-utils nginx nginx-mod-stream nginx-mod-http-perl httpd" && \
179-
dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
180-
rpm -V $INSTALL_PKGS && \
181-
dnf -y clean all --enablerepo='*'
220+
RUN --mount=type=cache,target=/var/cache/dnf /bin/bash <<'EOF'
221+
set -Eeuxo pipefail
222+
223+
MAX_RETRIES=3
224+
RETRY_COUNT=0
225+
INSTALL_PKGS="bind-utils nginx nginx-mod-stream nginx-mod-http-perl httpd"
226+
227+
echo "Installing: $INSTALL_PKGS"
228+
until dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS || [ $RETRY_COUNT -ge $MAX_RETRIES ]; do
229+
RETRY_COUNT=$((RETRY_COUNT + 1))
230+
echo "DNF install failed (attempt $RETRY_COUNT/$MAX_RETRIES), retrying in 30 seconds..."
231+
dnf clean metadata
232+
sleep 30
233+
done
234+
235+
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
236+
echo "ERROR: dnf install failed after $MAX_RETRIES attempts"
237+
exit 1
238+
fi
239+
240+
rpm -V $INSTALL_PKGS
241+
dnf -y clean all --enablerepo='*'
242+
rm -rf /var/cache/yum
243+
244+
EOF
182245

183246
# Configure httpd for CGI processing
184247
COPY --chown=1001:0 ${CODESERVER_SOURCE_CODE}/httpd/httpd.conf /etc/httpd/conf/httpd.conf

codeserver/ubi9-python-3.12/Dockerfile.konflux.cpu

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,28 @@ RUN dnf -y upgrade --refresh --nobest --skip-broken --nodocs --noplugins --setop
8585
# upgrade first to avoid fixable vulnerabilities end
8686

8787
# Install useful OS packages
88-
RUN dnf install -y perl mesa-libGL skopeo && dnf clean all && rm -rf /var/cache/yum
88+
RUN --mount=type=cache,target=/var/cache/dnf /bin/bash <<'EOF'
89+
set -Eeuxo pipefail
90+
91+
MAX_RETRIES=3
92+
RETRY_COUNT=0
93+
94+
until dnf install -y perl mesa-libGL skopeo || [ $RETRY_COUNT -ge $MAX_RETRIES ]; do
95+
RETRY_COUNT=$((RETRY_COUNT + 1))
96+
echo "dnf install failed (attempt $RETRY_COUNT/$MAX_RETRIES), retrying in 30 seconds..."
97+
dnf clean metadata
98+
sleep 30
99+
done
100+
101+
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
102+
echo "ERROR: dnf install failed after $MAX_RETRIES attempts"
103+
exit 1
104+
fi
105+
106+
dnf clean all
107+
rm -rf /var/cache/yum
108+
109+
EOF
89110

90111
# (ARCH-ppc64le): since wheels are compiled from source, we need shared libs available at runtime
91112
RUN --mount=type=cache,from=whl-cache,source=/root/OpenBLAS,target=/OpenBlas,rw \
@@ -134,7 +155,28 @@ USER 0
134155
WORKDIR /opt/app-root/bin
135156

136157
# Install useful OS packages
137-
RUN dnf install -y jq git-lfs libsndfile && dnf clean all && rm -rf /var/cache/yum
158+
RUN --mount=type=cache,target=/var/cache/dnf /bin/bash <<'EOF'
159+
set -Eeuxo pipefail
160+
161+
MAX_RETRIES=3
162+
RETRY_COUNT=0
163+
164+
until dnf install -y jq git-lfs libsndfile || [ $RETRY_COUNT -ge $MAX_RETRIES ]; do
165+
RETRY_COUNT=$((RETRY_COUNT + 1))
166+
echo "dnf install failed (attempt $RETRY_COUNT/$MAX_RETRIES), retrying in 30 seconds..."
167+
dnf clean metadata
168+
sleep 30
169+
done
170+
171+
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
172+
echo "ERROR: dnf install failed after $MAX_RETRIES attempts"
173+
exit 1
174+
fi
175+
176+
dnf clean all
177+
rm -rf /var/cache/yum
178+
179+
EOF
138180

139181
# wait for rpm-base stage (rpm builds for ppc64le)
140182
COPY --from=rpm-base /tmp/control /dev/null
@@ -171,10 +213,31 @@ ENV APP_ROOT=/opt/app-root \
171213
NGINX_PERL_MODULE_PATH=${APP_ROOT}/etc/perl
172214

173215
# Modules does not exist
174-
RUN INSTALL_PKGS="bind-utils nginx nginx-mod-stream nginx-mod-http-perl httpd" && \
175-
dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
176-
rpm -V $INSTALL_PKGS && \
177-
dnf -y clean all --enablerepo='*'
216+
RUN --mount=type=cache,target=/var/cache/dnf /bin/bash <<'EOF'
217+
set -Eeuxo pipefail
218+
219+
MAX_RETRIES=3
220+
RETRY_COUNT=0
221+
INSTALL_PKGS="bind-utils nginx nginx-mod-stream nginx-mod-http-perl httpd"
222+
223+
echo "Installing: $INSTALL_PKGS"
224+
until dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS || [ $RETRY_COUNT -ge $MAX_RETRIES ]; do
225+
RETRY_COUNT=$((RETRY_COUNT + 1))
226+
echo "DNF install failed (attempt $RETRY_COUNT/$MAX_RETRIES), retrying in 30 seconds..."
227+
dnf clean metadata
228+
sleep 30
229+
done
230+
231+
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
232+
echo "ERROR: dnf install failed after $MAX_RETRIES attempts"
233+
exit 1
234+
fi
235+
236+
rpm -V $INSTALL_PKGS
237+
dnf -y clean all --enablerepo='*'
238+
rm -rf /var/cache/yum
239+
240+
EOF
178241

179242
# Configure httpd for CGI processing
180243
COPY --chown=1001:0 ${CODESERVER_SOURCE_CODE}/httpd/httpd.conf /etc/httpd/conf/httpd.conf

codeserver/ubi9-python-3.12/get_code_server_rpm.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@ if [[ "$ARCH" == "amd64" || "$ARCH" == "arm64" ||"$ARCH" == "ppc64le" ]]; then
3131
# install build dependencies
3232
# https://access.redhat.com/support/policy/updates/rhel-app-streams-life-cycle
3333
# https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/developing_c_and_cpp_applications_in_rhel_9/assembly_additional-toolsets-for-development-rhel-9_developing-applications#cpp-compatibility-in-gcc-toolset-14_gcc-toolset-14
34-
dnf install -y jq patch libtool rsync gettext gcc-toolset-14 krb5-devel libX11-devel
34+
MAX_RETRIES=3
35+
RETRY_COUNT=0
36+
until dnf install -y jq patch libtool rsync gettext gcc-toolset-14 krb5-devel libX11-devel || [ $RETRY_COUNT -ge $MAX_RETRIES ]; do
37+
RETRY_COUNT=$((RETRY_COUNT + 1))
38+
echo "DNF install failed (attempt $RETRY_COUNT/$MAX_RETRIES). Retrying in 30 seconds..."
39+
dnf clean metadata
40+
sleep 30
41+
done
42+
43+
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
44+
echo "ERROR: dnf install failed after $MAX_RETRIES attempts"
45+
exit 1
46+
fi
3547

3648
# starting with node-22, c++20 is required
3749
. /opt/rh/gcc-toolset-14/enable

0 commit comments

Comments
 (0)