From 6025893ab2f58d1b5871615033389f75f3fa370f Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 17 Jul 2025 16:34:00 +0200 Subject: [PATCH 1/2] enable debug logging for buildah commit It often fails. And it's hard to debug, since the output has to be silenced. However, now we get to see the output (but only when it fails.) Ticket: ENT-13079 Signed-off-by: Lars Erik Wik --- tests/static-check/run.sh | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/static-check/run.sh b/tests/static-check/run.sh index 913a65688f..0bf56311ed 100755 --- a/tests/static-check/run.sh +++ b/tests/static-check/run.sh @@ -16,6 +16,28 @@ else BASE_IMG="fedora:$STATIC_CHECKS_FEDORA_VERSION" fi +# Use this function on verbose commands to silence the output unless it returns +# a non-zero exit code +run_and_print_on_failure() +{ + local exit_code + local temp_output_file + temp_output_file=$(mktemp) + if "$@" > "$temp_output_file" 2>&1; then + : # NOOP + else + exit_code=$? # Store exit code for later + echo "Error: Failed to run:" "$@" + echo "--- Start of Output ---" + cat "$temp_output_file" + echo "--- End of Output (Error Code: $exit_code) ---" + exit $exit_code + fi + + rm -f "$temp_output_file" + return 0 +} + function create_image() { local c=$(buildah from -q $BASE_IMG) buildah run $c -- dnf -q -y install "@C Development Tools and Libraries" clang cppcheck which diffutils file >/dev/null 2>&1 @@ -28,7 +50,8 @@ function create_image() { buildah copy $c $SUM_FILE >/dev/null rm $SUM_FILE - buildah commit $c cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION >/dev/null 2>&1 + # ENT-13079 + run_and_print_on_failure buildah --debug commit $c cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION echo $c } From 022df616ed6bd98acf274d04aa3bcaf1d30f6231 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Fri, 18 Jul 2025 12:37:54 +0200 Subject: [PATCH 2/2] run.sh: Fixed various shellcheck issues Signed-off-by: Lars Erik Wik --- tests/static-check/run.sh | 47 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/tests/static-check/run.sh b/tests/static-check/run.sh index 0bf56311ed..e91ae445b0 100755 --- a/tests/static-check/run.sh +++ b/tests/static-check/run.sh @@ -5,7 +5,7 @@ set -eE # include E so that create_image() failures bubble up to the surface trap "echo FAILURE" ERR -SUM_FILE="`basename $0`.sum" +SUM_FILE="$(basename "$0").sum" if [ -z "$STATIC_CHECKS_FEDORA_VERSION" ]; then default_f_ver="40" @@ -39,51 +39,52 @@ run_and_print_on_failure() } function create_image() { - local c=$(buildah from -q $BASE_IMG) - buildah run $c -- dnf -q -y install "@C Development Tools and Libraries" clang cppcheck which diffutils file >/dev/null 2>&1 - buildah run $c -- dnf -q -y install pcre-devel pcre2-devel openssl-devel libxml2-devel pam-devel lmdb-devel libacl-devel libyaml-devel curl-devel libvirt-devel librsync-devel >/dev/null 2>&1 - buildah run $c -- dnf clean all >/dev/null 2>&1 + local c + c=$(buildah from -q "$BASE_IMG") + buildah run "$c" -- dnf -q -y install "@C Development Tools and Libraries" clang cppcheck which diffutils file >/dev/null 2>&1 + buildah run "$c" -- dnf -q -y install pcre-devel pcre2-devel openssl-devel libxml2-devel pam-devel lmdb-devel libacl-devel libyaml-devel curl-devel libvirt-devel librsync-devel >/dev/null 2>&1 + buildah run "$c" -- dnf clean all >/dev/null 2>&1 # Copy checksum of this file into container. We use the checksum to detect # whether or not this file has changed and we should recreate the image - sha256sum $0 > $SUM_FILE - buildah copy $c $SUM_FILE >/dev/null - rm $SUM_FILE + sha256sum "$0" > "$SUM_FILE" + buildah copy "$c" "$SUM_FILE" >/dev/null + rm "$SUM_FILE" # ENT-13079 - run_and_print_on_failure buildah --debug commit $c cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION - echo $c + run_and_print_on_failure buildah --debug commit "$c" "cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION" + echo "$c" } set -x -if buildah inspect cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION >/dev/null 2>&1; then - c=$(buildah from cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION) +if buildah inspect "cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION" >/dev/null 2>&1; then + c=$(buildah from "cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION") # Recreate the image if the checksum of this file has changed or if the # checksum file is missing from the container - if [[ `buildah run $c ls $SUM_FILE` == $SUM_FILE ]]; then - SUM_A=$(sha256sum $0) - SUM_B=$(buildah run $c cat $SUM_FILE) - if [[ $SUM_A != $SUM_B ]]; then + if [[ $(buildah run "$c" ls "$SUM_FILE") == "$SUM_FILE" ]]; then + SUM_A=$(sha256sum "$0") + SUM_B=$(buildah run "$c" cat "$SUM_FILE") + if [[ "$SUM_A" != "$SUM_B" ]]; then echo "Recreating image due to mismatching checksum..." - IMAGE_ID=$(buildah inspect $c | jq -r '.FromImageID') + IMAGE_ID=$(buildah inspect "$c" | jq -r '.FromImageID') # The --force option will cause Buildah to remove all containers that # are using the image before removing the image from the system. Hence, # there is no need to manually remove these containers - buildah rmi --force $IMAGE_ID >/dev/null + buildah rmi --force "$IMAGE_ID" >/dev/null c=$(create_image) fi else echo "Recreating image due to missing checksum..." - IMAGE_ID=$(buildah inspect $c | jq -r '.FromImageID') - buildah rmi --force $IMAGE_ID >/dev/null + IMAGE_ID=$(buildah inspect "$c" | jq -r '.FromImageID') + buildah rmi --force "$IMAGE_ID" >/dev/null c=$(create_image) fi else c=$(create_image) fi -trap "buildah rm $c >/dev/null" EXIT +trap 'buildah rm $c >/dev/null' EXIT -buildah copy $c "$(dirname $0)/../../" /tmp/core/ >/dev/null 2>&1 -buildah run $c /tmp/core/tests/static-check/run_checks.sh +buildah copy "$c" "$(dirname "$0")/../../" /tmp/core/ >/dev/null 2>&1 +buildah run "$c" /tmp/core/tests/static-check/run_checks.sh