Skip to content

Commit 0014520

Browse files
committed
Let's try to build container in case of RHEL variants
more time. Sometimes we hit issue with ethel like: Red Hat Enterprise Linux 9 for x86_64 - AppStre 0.0 B/s | 0 B 00:00 Errors during downloading metadata for repository 'rhel-9-for-x86_64-appstream-rpms': - Curl error (56): Failure when receiving data from the peer for https://st....... [Received HTTP code 503 from proxy after CONNECT] Error: Failed to download metadata for repo 'rhel-9-for-x86_64-appstream-rpms': Cannot download repomd.xml Error: building at STEP "RUN yum -y module enable nodejs:$NODEJS_VERSION && MODULE_DEPS="make gcc gcc Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
1 parent 2af3346 commit 0014520

1 file changed

Lines changed: 39 additions & 27 deletions

File tree

build.sh

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -149,36 +149,48 @@ function docker_build_with_version {
149149
if [[ "$SKIP_SQUASH" -eq 0 ]] && [[ "$is_podman" -eq 1 ]]; then
150150
BUILD_OPTIONS+=" --squash"
151151
fi
152-
153-
command="docker build ${BUILD_OPTIONS} -f $dockerfile ${DOCKER_BUILD_CONTEXT}"
154-
echo "-> building using $command"
155-
set +x -o pipefail
156-
tmp_file=$(mktemp "/tmp/${dir}-${OS}.XXXXXX")
157-
$command 2>&1 | tee "$tmp_file"
158-
ret_code=$?
159-
set -x +o pipefail
160-
echo "Return code from docker build is '$ret_code'."
161-
last_row=$(< "$tmp_file" tail -n 1)
162-
if [[ $ret_code != "0" ]]; then
163-
if [[ "${OS}" == "rhel8" ]] || [[ "${OS}" == "rhel9" ]] || [[ "${OS}" == "rhel10" ]]; then
164-
# Do not fail in case of sending log to pastebin or logdetective fails.
165-
analyze_logs_by_logdetective "${tmp_file}"
166-
fi
167-
else
168-
# Structure of log build is as follows:
169-
# COMMIT
170-
# --> e191d12b5928
171-
# e191d12b5928360dd6024fe80d31e08f994d42577f76b9b143e014749afc8ab4
172-
# shellcheck disable=SC2016
173-
if [[ "$last_row" =~ (^-->)?(Using cache )?[a-fA-F0-9]+$ ]]; then
174-
IMAGE_ID="$last_row"
152+
i=1
153+
while [ $i -le 2 ]; do
154+
command="docker build ${BUILD_OPTIONS} -f $dockerfile ${DOCKER_BUILD_CONTEXT}"
155+
echo "-> building using $command"
156+
set +x -o pipefail
157+
tmp_file=$(mktemp "/tmp/${dir}-${OS}.XXXXXX")
158+
$command 2>&1 | tee "$tmp_file"
159+
ret_code=$?
160+
set -x +o pipefail
161+
echo "Return code from docker build is '$ret_code'."
162+
last_row=$(< "$tmp_file" tail -n 1)
163+
if [[ $ret_code != "0" ]]; then
164+
# In case of failure, we want to analyze the logs and send them to pastebin or logdetective.
165+
# The failure can be ethel issue like network failure or registry failure.
166+
# Red Hat Enterprise Linux 9 for x86_64 - AppStre 0.0 B/s | 0 B 00:00
167+
# Errors during downloading metadata for repository 'rhel-9-for-x86_64-appstream-rpms':
168+
# - Curl error (56): Failure when receiving data from the peer for https:// [Received HTTP code 503 from proxy after CONNECT]
169+
# Error: Failed to download metadata for repo 'rhel-9-for-x86_64-appstream-rpms':
170+
if [[ "${OS}" == "rhel8" ]] || [[ "${OS}" == "rhel9" ]] || [[ "${OS}" == "rhel10" ]]; then
171+
# Do not fail in case of sending log to pastebin or logdetective fails.
172+
analyze_logs_by_logdetective "${tmp_file}"
173+
fi
174+
((i++))
175+
sleep 5
176+
echo "Retrying to build image for version $dir, attempt $i of 2."
177+
else
178+
# Structure of log build is as follows:
179+
# COMMIT
180+
# --> e191d12b5928
181+
# e191d12b5928360dd6024fe80d31e08f994d42577f76b9b143e014749afc8ab4
182+
# shellcheck disable=SC2016
183+
if [[ "$last_row" =~ (^-->)?(Using cache )?[a-fA-F0-9]+$ ]]; then
184+
IMAGE_ID="$last_row"
185+
fi
186+
echo "$IMAGE_ID" > .image-id
187+
tag_image
188+
break
175189
fi
176-
fi
177190

178-
rm -f "$tmp_file"
191+
rm -f "$tmp_file"
192+
done
179193

180-
echo "$IMAGE_ID" > .image-id
181-
tag_image
182194
}
183195

184196
function tag_image {

0 commit comments

Comments
 (0)