Update update.sh
This commit is contained in:
@@ -5,12 +5,33 @@ set -Eeuo pipefail
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
|
||||
SCRIPT_PATH="${SCRIPT_DIR}/$(basename -- "${BASH_SOURCE[0]}")"
|
||||
|
||||
COLOR_RESET=''
|
||||
COLOR_RED=''
|
||||
COLOR_GREEN=''
|
||||
COLOR_CYAN=''
|
||||
ERROR_RESET=''
|
||||
ERROR_RED=''
|
||||
ERROR_YELLOW=''
|
||||
if [[ -z "${NO_COLOR:-}" ]]; then
|
||||
if [[ -t 1 ]]; then
|
||||
COLOR_RESET=$'\033[0m'
|
||||
COLOR_RED=$'\033[1;31m'
|
||||
COLOR_GREEN=$'\033[1;32m'
|
||||
COLOR_CYAN=$'\033[1;36m'
|
||||
fi
|
||||
if [[ -t 2 ]]; then
|
||||
ERROR_RESET=$'\033[0m'
|
||||
ERROR_RED=$'\033[1;31m'
|
||||
ERROR_YELLOW=$'\033[1;33m'
|
||||
fi
|
||||
fi
|
||||
|
||||
fail() {
|
||||
printf 'ERROR: %s\n' "$*" >&2
|
||||
printf '%sERROR:%s %s\n' "$ERROR_RED" "$ERROR_RESET" "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
trap 'printf "ERROR: broker update failed at line %d.\n" "$LINENO" >&2' ERR
|
||||
trap 'printf "%sERROR:%s broker update failed at line %d.\n" "$ERROR_RED" "$ERROR_RESET" "$LINENO" >&2' ERR
|
||||
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
@@ -49,13 +70,14 @@ deploy_local_broker() {
|
||||
status="$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$container_id")"
|
||||
case "$status" in
|
||||
healthy)
|
||||
printf ' healthy.\n'
|
||||
printf ' %shealthy%s.\n' "$COLOR_GREEN" "$COLOR_RESET"
|
||||
docker compose ps broker
|
||||
printf 'Local TAPM Deployment Broker update completed successfully.\n'
|
||||
printf '%sLocal TAPM Deployment Broker update completed successfully.%s\n' \
|
||||
"$COLOR_GREEN" "$COLOR_RESET"
|
||||
return 0
|
||||
;;
|
||||
exited | dead | unhealthy)
|
||||
printf ' %s.\n' "$status"
|
||||
printf ' %s%s%s.\n' "$COLOR_RED" "$status" "$COLOR_RESET"
|
||||
docker compose logs --tail=100 broker
|
||||
fail "broker failed its health check"
|
||||
;;
|
||||
@@ -117,16 +139,19 @@ update_peer_broker() {
|
||||
peer_host="${peer_host%"${peer_host##*[![:space:]]}"}"
|
||||
[[ -n "$peer_host" ]] || continue
|
||||
|
||||
printf 'Checking peer broker at %s...\n' "$peer_host"
|
||||
printf 'Checking peer broker at %s%s%s...\n' \
|
||||
"$COLOR_CYAN" "$peer_host" "$COLOR_RESET"
|
||||
if ! ssh "${ssh_options[@]}" "${ssh_user}@${peer_host}" true; then
|
||||
printf 'WARNING: peer %s is unavailable over SSH; its update was skipped.\n' "$peer_host" >&2
|
||||
printf '%sWARNING:%s peer %s is unavailable over SSH; its update was skipped.\n' \
|
||||
"$ERROR_YELLOW" "$ERROR_RESET" "$peer_host" >&2
|
||||
continue
|
||||
fi
|
||||
if ! ssh "${ssh_options[@]}" "${ssh_user}@${peer_host}" \
|
||||
"TAPM_UPDATE_LOCAL_ONLY=1 ${remote_update_path} --local-only"; then
|
||||
fail "peer ${peer_host} is reachable, but its broker update failed"
|
||||
fi
|
||||
printf 'Peer broker at %s completed successfully.\n' "$peer_host"
|
||||
printf '%sSUCCESS:%s Peer broker at %s%s%s completed successfully.\n' \
|
||||
"$COLOR_GREEN" "$COLOR_RESET" "$COLOR_CYAN" "$peer_host" "$COLOR_RESET"
|
||||
done
|
||||
}
|
||||
|
||||
@@ -146,7 +171,8 @@ if ((POST_PULL == 0)); then
|
||||
local_commit="$(git rev-parse HEAD)"
|
||||
upstream_commit="$(git rev-parse '@{upstream}')"
|
||||
if [[ "$local_commit" == "$upstream_commit" ]]; then
|
||||
printf 'Local TAPM Deployment Broker is already up to date.\n'
|
||||
printf '%sLocal TAPM Deployment Broker is already up to date.%s\n' \
|
||||
"$COLOR_GREEN" "$COLOR_RESET"
|
||||
elif git merge-base --is-ancestor "$local_commit" "$upstream_commit"; then
|
||||
printf 'Updating TAPM Deployment Broker from %s...\n' "$upstream"
|
||||
git merge --quiet --ff-only "$upstream_commit"
|
||||
@@ -169,4 +195,5 @@ if ((LOCAL_ONLY == 0)); then
|
||||
update_peer_broker
|
||||
fi
|
||||
|
||||
printf 'TAPM Deployment Broker update check completed.\n'
|
||||
printf '%sTAPM Deployment Broker update check completed.%s\n' \
|
||||
"$COLOR_GREEN" "$COLOR_RESET"
|
||||
|
||||
Reference in New Issue
Block a user