Merge pull request #36 from samply/log_git_errors

Report git errors
This commit is contained in:
Martin Lablans 2022-11-04 16:25:11 +01:00 committed by GitHub
commit e9a2ed05f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 12 deletions

11
lib/functions.sh Executable file → Normal file
View File

@ -119,9 +119,13 @@ fixPermissions() {
source lib/monitoring.sh source lib/monitoring.sh
fail_and_report() { report_error() {
log ERROR "$2" log ERROR "$2"
hc_send $1 "$2" hc_send $1 "$2"
}
fail_and_report() {
report_error $@
exit $1 exit $1
} }
@ -135,8 +139,3 @@ setHostname() {
##Setting Network properties ##Setting Network properties
# currently not needed # currently not needed
#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 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 PRODUCTION="false";
if [ "$(git branch --show-current)" == "main" ]; then
export PRODUCTION="true";
fi

View File

@ -71,7 +71,10 @@ else
exit 1 exit 1
fi fi
log INFO "Success - all prerequisites are met!" COMMIT_ETC=$(git -C /etc/bridgehead rev-parse HEAD | cut -c -8)
hc_send log "Success - all prerequisites are met!" 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 exit 0

View File

@ -36,6 +36,11 @@ CHANGES=""
git_updated="false" git_updated="false"
for DIR in /etc/bridgehead $(pwd); do for DIR in /etc/bridgehead $(pwd); do
log "INFO" "Checking for updates to git repo $DIR ..." 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 if [ "$(git -C $DIR config --get credential.helper)" != "$CREDHELPER" ]; then
log "INFO" "Configuring repo to use bridgehead git credential helper." log "INFO" "Configuring repo to use bridgehead git credential helper."
git -C $DIR config credential.helper "$CREDHELPER" git -C $DIR config credential.helper "$CREDHELPER"
@ -43,13 +48,15 @@ for DIR in /etc/bridgehead $(pwd); do
old_git_hash="$(git -C $DIR rev-parse --verify HEAD)" old_git_hash="$(git -C $DIR rev-parse --verify HEAD)"
if [ -z "$HTTP_PROXY_URL" ]; then if [ -z "$HTTP_PROXY_URL" ]; then
log "INFO" "Git is using no proxy!" log "INFO" "Git is using no proxy!"
git -C $DIR fetch 2>&1 OUT=$(git -C $DIR fetch 2>&1 && git -C $DIR pull 2>&1)
git -C $DIR pull 2>&1
else else
log "INFO" "Git is using proxy ${HTTP_PROXY_URL} from ${CONFFILE}" 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 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)
git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR pull 2>&1
fi 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)" new_git_hash="$(git -C $DIR rev-parse --verify HEAD)"
if [ "$old_git_hash" != "$new_git_hash" ]; then if [ "$old_git_hash" != "$new_git_hash" ]; then
CHANGE="Updated git repository in ${DIR} from commit $old_git_hash to $new_git_hash" CHANGE="Updated git repository in ${DIR} from commit $old_git_hash to $new_git_hash"