From 2af334606f0b5b7d6058ce5ebce0fae1e2e47a13 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Mon, 9 Mar 2026 10:51:22 +0100 Subject: [PATCH 1/4] Remove `set -e` flag from the script This cause that in case of docker build failed, then it is not send to logdetective. Remove function _parse_output_inner and parse_output that are not used anymore. Signed-off-by: Petr "Stone" Hracek --- build.sh | 57 +------------------------------------------------------- 1 file changed, 1 insertion(+), 56 deletions(-) diff --git a/build.sh b/build.sh index 926a27c..3565f8e 100755 --- a/build.sh +++ b/build.sh @@ -7,7 +7,7 @@ # SINGLE_VERSION - Specifies the image version - (must match with subdirectory in repo) # VERSIONS - Must be set to a list with possible versions (subdirectories) -set -eE +set -E [ -n "${DEBUG:-}" ] && set -x # shellcheck shell=bash @@ -22,53 +22,6 @@ error() { echo "ERROR: $*" ; false ; } trap 'echo "errexit on line $LINENO, $0" >&2' ERR -# _parse_output_inner -# ------------------- -# Helper function for 'parse_output'. -# We need to avoid case statements in $() for older Bash versions (per issue -# postgresql-container#35, mac ships with 3.2). -# Example of problematic statement: echo $(case i in i) echo i;; esac) -_parse_output_inner () -{ - set -o pipefail - { - case $stream in - stdout|1|"") - eval "$command" | tee >(cat - >&"$stdout_fd") - ;; - stderr|2) - set +x # avoid stderr pollution - eval "$command" {free_fd}>&1 1>&"$stdout_fd" 2>&"$free_fd" | tee >(cat - >&"$stderr_fd") - ;; - esac - # Inherit correct exit status. - (exit "${PIPESTATUS[0]}") - } | eval "$filter" -} - - -# parse_output COMMAND FILTER_COMMAND OUTVAR [STREAM={stderr|stdout}] -# ------------------------------------------------------------------- -# Parse standard (error) output of COMMAND with FILTER_COMMAND and store the -# output into variable named OUTVAR. STREAM might be 'stdout' or 'stderr', -# defaults to 'stdout'. The filtered output stays (live) printed to terminal. -# This method doesn't create any explicit temporary files. -# Defines: -# ${$OUTVAR}: Set to FILTER_COMMAND output. -parse_output () -{ - local command=$1 filter=$2 var=$3 stream=$4 - echo "-> building using $command" - local raw_output='' rc=0 - { - # shellcheck disable=SC2034 - raw_output=$(_parse_output_inner) - } {stdout_fd}>&1 {stderr_fd}>&2 - rc=$? - eval "$var=\$raw_output" - (exit $rc) -} - # "best-effort" cleanup of image function clean_image { for id_file in .image-id .image-id-from; do @@ -209,9 +162,7 @@ function docker_build_with_version { if [[ $ret_code != "0" ]]; then if [[ "${OS}" == "rhel8" ]] || [[ "${OS}" == "rhel9" ]] || [[ "${OS}" == "rhel10" ]]; then # Do not fail in case of sending log to pastebin or logdetective fails. - set +e analyze_logs_by_logdetective "${tmp_file}" - set -e fi else # Structure of log build is as follows: @@ -226,12 +177,6 @@ function docker_build_with_version { rm -f "$tmp_file" - # shellcheck disable=SC2016 - -# parse_output 'docker build '"$BUILD_OPTIONS"' -f "$dockerfile" "${DOCKER_BUILD_CONTEXT}"' \ -# "tail -n 1 | awk '/Successfully built|(^--> )?(Using cache )?[a-fA-F0-9]+$/{print \$NF}'" \ -# IMAGE_ID -# analyze_logs_by_logdetective "$?" "${tmp_file}" echo "$IMAGE_ID" > .image-id tag_image } From 0014520c47aef14dd4a671e63485a42ecbbf743f Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Mon, 9 Mar 2026 11:04:42 +0100 Subject: [PATCH 2/4] 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 --- build.sh | 66 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/build.sh b/build.sh index 3565f8e..d0d950c 100755 --- a/build.sh +++ b/build.sh @@ -149,36 +149,48 @@ function docker_build_with_version { if [[ "$SKIP_SQUASH" -eq 0 ]] && [[ "$is_podman" -eq 1 ]]; then BUILD_OPTIONS+=" --squash" fi - - command="docker build ${BUILD_OPTIONS} -f $dockerfile ${DOCKER_BUILD_CONTEXT}" - echo "-> building using $command" - set +x -o pipefail - tmp_file=$(mktemp "/tmp/${dir}-${OS}.XXXXXX") - $command 2>&1 | tee "$tmp_file" - ret_code=$? - set -x +o pipefail - echo "Return code from docker build is '$ret_code'." - last_row=$(< "$tmp_file" tail -n 1) - if [[ $ret_code != "0" ]]; then - if [[ "${OS}" == "rhel8" ]] || [[ "${OS}" == "rhel9" ]] || [[ "${OS}" == "rhel10" ]]; then - # Do not fail in case of sending log to pastebin or logdetective fails. - analyze_logs_by_logdetective "${tmp_file}" - fi - else - # Structure of log build is as follows: - # COMMIT - # --> e191d12b5928 - # e191d12b5928360dd6024fe80d31e08f994d42577f76b9b143e014749afc8ab4 - # shellcheck disable=SC2016 - if [[ "$last_row" =~ (^-->)?(Using cache )?[a-fA-F0-9]+$ ]]; then - IMAGE_ID="$last_row" + i=1 + while [ $i -le 2 ]; do + command="docker build ${BUILD_OPTIONS} -f $dockerfile ${DOCKER_BUILD_CONTEXT}" + echo "-> building using $command" + set +x -o pipefail + tmp_file=$(mktemp "/tmp/${dir}-${OS}.XXXXXX") + $command 2>&1 | tee "$tmp_file" + ret_code=$? + set -x +o pipefail + echo "Return code from docker build is '$ret_code'." + last_row=$(< "$tmp_file" tail -n 1) + if [[ $ret_code != "0" ]]; then + # In case of failure, we want to analyze the logs and send them to pastebin or logdetective. + # The failure can be ethel issue like network failure or registry failure. + # 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:// [Received HTTP code 503 from proxy after CONNECT] + # Error: Failed to download metadata for repo 'rhel-9-for-x86_64-appstream-rpms': + if [[ "${OS}" == "rhel8" ]] || [[ "${OS}" == "rhel9" ]] || [[ "${OS}" == "rhel10" ]]; then + # Do not fail in case of sending log to pastebin or logdetective fails. + analyze_logs_by_logdetective "${tmp_file}" + fi + ((i++)) + sleep 5 + echo "Retrying to build image for version $dir, attempt $i of 2." + else + # Structure of log build is as follows: + # COMMIT + # --> e191d12b5928 + # e191d12b5928360dd6024fe80d31e08f994d42577f76b9b143e014749afc8ab4 + # shellcheck disable=SC2016 + if [[ "$last_row" =~ (^-->)?(Using cache )?[a-fA-F0-9]+$ ]]; then + IMAGE_ID="$last_row" + fi + echo "$IMAGE_ID" > .image-id + tag_image + break fi - fi - rm -f "$tmp_file" + rm -f "$tmp_file" + done - echo "$IMAGE_ID" > .image-id - tag_image } function tag_image { From a7a03eb9fe843c0c3f64f2786aa50424eebce184 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Mon, 9 Mar 2026 13:34:30 +0100 Subject: [PATCH 3/4] Disable warning as `set -e` was removed Signed-off-by: Petr "Stone" Hracek --- build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.sh b/build.sh index d0d950c..76def3f 100755 --- a/build.sh +++ b/build.sh @@ -233,7 +233,9 @@ fi echo "Built versions are: $dirs" for dir in ${dirs}; do + # shellcheck disable=SC2164 pushd "${dir}" > /dev/null docker_build_with_version Dockerfile."$OS" + # shellcheck disable=SC2164 popd > /dev/null done From e62deb12c84b89740728103749c9290816489105 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Tue, 10 Mar 2026 07:31:26 +0100 Subject: [PATCH 4/4] The suite has to fail in case second build failed as well. We do not want to continue Signed-off-by: Petr "Stone" Hracek --- build.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/build.sh b/build.sh index 76def3f..406127e 100755 --- a/build.sh +++ b/build.sh @@ -150,6 +150,7 @@ function docker_build_with_version { BUILD_OPTIONS+=" --squash" fi i=1 + build_failed=1 while [ $i -le 2 ]; do command="docker build ${BUILD_OPTIONS} -f $dockerfile ${DOCKER_BUILD_CONTEXT}" echo "-> building using $command" @@ -185,11 +186,16 @@ function docker_build_with_version { fi echo "$IMAGE_ID" > .image-id tag_image + build_failed=0 break fi rm -f "$tmp_file" done + if [[ $build_failed -ne 0 ]]; then + echo "-> Build failed for version $dir and OS $OS after 2 attempts, giving up." + exit 1 + fi }