From 9617b15ad57be854fe799a033abca57f6f118925 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Tue, 3 Dec 2024 15:30:25 +0100 Subject: [PATCH 1/3] Static checks now rebuilds image if run.sh is modified Ticket: ENT-10993 Changelog: None Signed-off-by: Lars Erik Wik --- tests/static-check/run.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/static-check/run.sh b/tests/static-check/run.sh index ba434a655e..56ec0cf563 100755 --- a/tests/static-check/run.sh +++ b/tests/static-check/run.sh @@ -5,6 +5,8 @@ set -eE # include E so that create_image() failures bubble up to the surface trap "echo FAILURE" ERR +SUM_FILE="`basename $0`.sum" + if [ -z "$STATIC_CHECKS_FEDORA_VERSION" ]; then default_f_ver="40" echo "No Fedora version for static checks specified, using the default (Fedora $default_f_ver)" @@ -19,15 +21,32 @@ function create_image() { 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 >/dev/null 2>&1 buildah run $c -- dnf clean all >/dev/null 2>&1 + + # Copy checksum of this file into container + sha256sum $0 > $SUM_FILE + 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 + buildah rm $c >/dev/null + c=$(buildah from cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION) echo $c } set -x -# TODO: check how old the image is and recreate if it's too old 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 + 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') + buildah rmi --force $IMAGE_ID >/dev/null + c=$(create_image) + fi else c=$(create_image) fi From 6cc3890be1b6e98521d2a819831dc7626a6cd533 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 5 Dec 2024 15:05:26 +0100 Subject: [PATCH 2/3] Static checks now also rebuilds image on missing checksum Ticket: ENT-10993 Changelog: None Signed-off-by: Lars Erik Wik --- tests/static-check/run.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/static-check/run.sh b/tests/static-check/run.sh index 56ec0cf563..ea8258b503 100755 --- a/tests/static-check/run.sh +++ b/tests/static-check/run.sh @@ -38,11 +38,18 @@ 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) - # Recreate the image if the checksum of this file has changed - 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..." + # Recreate the image if the checksum of this file has changed + 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') + 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 c=$(create_image) From ace19ac7779a1751535268d785c0071bd1532db8 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 5 Dec 2024 15:09:39 +0100 Subject: [PATCH 3/3] Don't create new container from new image The modified container created from the base image is identical. Ticket: ENT-10993 Changelog: None Signed-off-by: Lars Erik Wik --- tests/static-check/run.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/static-check/run.sh b/tests/static-check/run.sh index ea8258b503..847fff3d1d 100755 --- a/tests/static-check/run.sh +++ b/tests/static-check/run.sh @@ -28,8 +28,6 @@ function create_image() { rm $SUM_FILE buildah commit $c cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION >/dev/null 2>&1 - buildah rm $c >/dev/null - c=$(buildah from cfengine-static-checker-f$STATIC_CHECKS_FEDORA_VERSION) echo $c }