From 9b3acb48995dee6334929537a3d4e999d9d5a0f3 Mon Sep 17 00:00:00 2001 From: Martin Lablans Date: Fri, 4 Nov 2022 15:26:27 +0100 Subject: [PATCH 1/5] Report git errors --- lib/functions.sh | 6 +++++- lib/update-bridgehead.sh | 9 +++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/functions.sh b/lib/functions.sh index 6c81d7b..bceb34a 100755 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -119,9 +119,13 @@ fixPermissions() { source lib/monitoring.sh -fail_and_report() { +report_error() { log ERROR "$2" hc_send $1 "$2" +} + +fail_and_report() { + report_error $@ exit $1 } diff --git a/lib/update-bridgehead.sh b/lib/update-bridgehead.sh index 7212d13..636c585 100755 --- a/lib/update-bridgehead.sh +++ b/lib/update-bridgehead.sh @@ -43,12 +43,13 @@ for DIR in /etc/bridgehead $(pwd); do old_git_hash="$(git -C $DIR rev-parse --verify HEAD)" if [ -z "$HTTP_PROXY_URL" ]; then log "INFO" "Git is using no proxy!" - git -C $DIR fetch 2>&1 - git -C $DIR pull 2>&1 + OUT=$(git -C $DIR fetch 2>&1 && git -C $DIR pull 2>&1) else log "INFO" "Git is using proxy ${HTTP_PROXY_URL} from ${CONFFILE}" - git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR fetch 2>&1 - git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR pull 2>&1 + OUT=$(git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR fetch 2>&1 && git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR pull 2>&1) + fi + if [ $? -ne 0 ]; then + report_error 1 "Unable to update git $DIR: $OUT" fi new_git_hash="$(git -C $DIR rev-parse --verify HEAD)" if [ "$old_git_hash" != "$new_git_hash" ]; then From ebc1b87dc2b24e01dfac6c0e28ff2c996da82923 Mon Sep 17 00:00:00 2001 From: Torben Brenner Date: Fri, 4 Nov 2022 15:54:08 +0100 Subject: [PATCH 2/5] feature: Added warning for modified working directories --- lib/update-bridgehead.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/update-bridgehead.sh b/lib/update-bridgehead.sh index 636c585..a62f7fa 100755 --- a/lib/update-bridgehead.sh +++ b/lib/update-bridgehead.sh @@ -51,6 +51,11 @@ for DIR in /etc/bridgehead $(pwd); do if [ $? -ne 0 ]; then report_error 1 "Unable to update git $DIR: $OUT" fi + OUT="$(git -C $DIR status --porcelain)" + if [ -n "$OUT" ]; then + report_error 1 "The workingdirectory in $DIR is modified. Following files are changed: $OUT" + fi + new_git_hash="$(git -C $DIR rev-parse --verify HEAD)" if [ "$old_git_hash" != "$new_git_hash" ]; then CHANGE="Updated git repository in ${DIR} from commit $old_git_hash to $new_git_hash" From 8c18426d283545323d73d96145f18ec3255695d8 Mon Sep 17 00:00:00 2001 From: Martin Lablans Date: Fri, 4 Nov 2022 16:12:08 +0100 Subject: [PATCH 3/5] Move warning up --- lib/update-bridgehead.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/update-bridgehead.sh b/lib/update-bridgehead.sh index a62f7fa..69b3887 100755 --- a/lib/update-bridgehead.sh +++ b/lib/update-bridgehead.sh @@ -36,6 +36,11 @@ CHANGES="" git_updated="false" for DIR in /etc/bridgehead $(pwd); do log "INFO" "Checking for updates to git repo $DIR ..." + OUT="$(git -C $DIR status --porcelain)" + if [ -n "$OUT" ]; then + log WARN "The working directory $DIR is modified. Changed files: $OUT" + report_error 1 "The working directory $DIR is modified. Changed files: $OUT" + fi if [ "$(git -C $DIR config --get credential.helper)" != "$CREDHELPER" ]; then log "INFO" "Configuring repo to use bridgehead git credential helper." git -C $DIR config credential.helper "$CREDHELPER" @@ -51,10 +56,6 @@ for DIR in /etc/bridgehead $(pwd); do if [ $? -ne 0 ]; then report_error 1 "Unable to update git $DIR: $OUT" fi - OUT="$(git -C $DIR status --porcelain)" - if [ -n "$OUT" ]; then - report_error 1 "The workingdirectory in $DIR is modified. Following files are changed: $OUT" - fi new_git_hash="$(git -C $DIR rev-parse --verify HEAD)" if [ "$old_git_hash" != "$new_git_hash" ]; then From ceda942731361772f88eb4d890cd01a6e32a317e Mon Sep 17 00:00:00 2001 From: Martin Lablans Date: Fri, 4 Nov 2022 16:12:24 +0100 Subject: [PATCH 4/5] Remove errors in old git versions --- lib/functions.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/functions.sh b/lib/functions.sh index bceb34a..b308abb 100755 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -134,8 +134,3 @@ fail_and_report() { #export HOSTIP=$(MSYS_NO_PATHCONV=1 docker run --rm --add-host=host.docker.internal:host-gateway ubuntu cat /etc/hosts | grep 'host.docker.internal' | awk '{print $1}'); export HOST=$(hostname -f) - -export PRODUCTION="false"; -if [ "$(git branch --show-current)" == "main" ]; then - export PRODUCTION="true"; -fi From 3234a81aa216b400d7db0beb7885148e5489ee8b Mon Sep 17 00:00:00 2001 From: Martin Lablans Date: Fri, 4 Nov 2022 16:18:30 +0100 Subject: [PATCH 5/5] Report current git commits --- lib/prerequisites.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/prerequisites.sh b/lib/prerequisites.sh index 859b690..c2a4e34 100755 --- a/lib/prerequisites.sh +++ b/lib/prerequisites.sh @@ -71,7 +71,10 @@ else exit 1 fi -log INFO "Success - all prerequisites are met!" -hc_send log "Success - all prerequisites are met!" +COMMIT_ETC=$(git -C /etc/bridgehead rev-parse HEAD | cut -c -8) +COMMIT_SRV=$(git -C /srv/docker/bridgehead rev-parse HEAD | cut -c -8) + +log INFO "Success - all prerequisites are met! Git commits: etc:$COMMIT_ETC srv:$COMMIT_SRV" +hc_send log "Success - all prerequisites are met! Git commits: etc:$COMMIT_ETC srv:$COMMIT_SRV" exit 0