From 3044d9c2eccc8add7a55cf2d7bb9ef235a4e8855 Mon Sep 17 00:00:00 2001 From: Stephane Gourichon Date: Wed, 27 Mar 2024 23:31:16 +0100 Subject: [PATCH] Ensure a rebuild of a container is a verbose event. --- .../containers_check_update_rebuild_switch.sh | 3 ++ tools/run_and_output_only_on_error.sh | 51 +++++++++++++++---- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/tools/containers_check_update_rebuild_switch.sh b/tools/containers_check_update_rebuild_switch.sh index 55bdc0d..9f2f5e3 100755 --- a/tools/containers_check_update_rebuild_switch.sh +++ b/tools/containers_check_update_rebuild_switch.sh @@ -46,6 +46,9 @@ do PATH_OF_CONTAINER="$( docker inspect --format='{{ index .Config.Labels "com.docker.compose.project.working_dir" }}' $CONTAINER_ID )" NAME_OF_CONTAINER="$( docker inspect --format='{{ .Name }}' $CONTAINER_ID )" + + echo "IMPORTANT: updating container $NAME_OF_CONTAINER from $PATH_OF_CONTAINER" + cd $PATH_OF_CONTAINER docker-compose pull || { fail_one "pull" ; continue ; } docker-compose build --no-cache || { fail_one "build" ; continue ; } diff --git a/tools/run_and_output_only_on_error.sh b/tools/run_and_output_only_on_error.sh index 8b75bf6..7da12de 100755 --- a/tools/run_and_output_only_on_error.sh +++ b/tools/run_and_output_only_on_error.sh @@ -1,22 +1,53 @@ #!/bin/bash -set -eu - LOGFILENAME=$(mktemp /tmp/run_and_output_only_on_error_XXXXXX) -# set -xv trap "rm -f ${LOGFILENAME}" EXIT -if - ( - $@ - ) > "${LOGFILENAME}" 2>&1 +REASONS_FOR_OUTPUT=() + +( + set -xv + $@ +) > "${LOGFILENAME}" 2>&1 + +RC=$? + +if [[ "$RC" != 0 ]] then - true -else + REASONS_FOR_OUTPUT+=( "Return code $RC" ) +fi + +if grep -qiw WARNING "${LOGFILENAME}" +then + REASONS_FOR_OUTPUT+=("WARNING appears in output") +fi + +if grep -qiw ERROR "${LOGFILENAME}" +then + REASONS_FOR_OUTPUT+=("ERROR appears in output") +fi + +if grep -qiw FAILURE "${LOGFILENAME}" +then + REASONS_FOR_OUTPUT+=("FAILURE appears in output") +fi + +if grep -qiw IMPORTANT "${LOGFILENAME}" +then + REASONS_FOR_OUTPUT+=("IMPORTANT appears in output") +fi + +if [[ ${#REASONS_FOR_OUTPUT[@]} != 0 ]] +then + echo "Verbose report on running: $@" + echo + echo "${#REASONS_FOR_OUTPUT[@]} reason(s) for verbose output: " + printf '* %s\n' "${REASONS_FOR_OUTPUT[@]}" echo - echo "Error on running: $@" echo echo "Here's the program's output (out and err combined)" + echo ======================================================================== cat "${LOGFILENAME}" + echo ======================================================================== fi