Generic host/repo/branch-aware CD on adnanh/webhook
Replaces the per-project deploy scripts and self-contained webhook receivers with one manifest-driven implementation that lives outside the application repositories and can be updated independently of them. First targets: domaindingo test and prod on s5.
This commit is contained in:
Executable
+71
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# What is this host deploying, and is the receiver actually healthy?
|
||||
#
|
||||
# Written because "the timer is active" was never proof of anything in this
|
||||
# fleet -- the same lesson the uas-ng updater documents. This shows the daemon,
|
||||
# the socket, and the outcome of the last deploy for each target.
|
||||
|
||||
set -Eeuo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
readonly REPO_ROOT="$(cd -- "${SCRIPT_DIR}/.." && pwd)"
|
||||
readonly STATE_DIR="${XDG_STATE_HOME:-${HOME}/.local/state}/cd-webhook"
|
||||
readonly CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}/cd-webhook"
|
||||
readonly UNIT_NAME="cd-webhook.service"
|
||||
|
||||
bold() { printf '\n\033[1m%s\033[0m\n' "$*"; }
|
||||
|
||||
bold "Host"
|
||||
if eval "$("${REPO_ROOT}/bin/cd-target" host-config 2>/dev/null)"; then
|
||||
printf ' %s, receiver on %s:%s\n' "$CD_HOST" "$CD_BIND" "$CD_PORT"
|
||||
else
|
||||
printf ' %s is not configured in targets.json\n' "$(hostname)"
|
||||
printf ' answers to: %s\n' "$("${REPO_ROOT}/bin/cd-target" hostnames)"
|
||||
fi
|
||||
|
||||
bold "Receiver"
|
||||
state="$(systemctl --user is-active "$UNIT_NAME" 2>/dev/null || true)"
|
||||
printf ' %-12s %s\n' "state" "${state:-not installed}"
|
||||
if [[ "$state" == "active" ]]; then
|
||||
printf ' %-12s %s\n' "since" \
|
||||
"$(systemctl --user show "$UNIT_NAME" -p ActiveEnterTimestamp --value)"
|
||||
if command -v ss >/dev/null 2>&1 && [[ -n "${CD_PORT:-}" ]]; then
|
||||
if ss -ltn 2>/dev/null | grep -q ":${CD_PORT}\b"; then
|
||||
printf ' %-12s listening on port %s\n' "socket" "$CD_PORT"
|
||||
else
|
||||
printf ' %-12s \033[31mNOT listening on port %s\033[0m\n' "socket" "$CD_PORT"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -f "${CONFIG_DIR}/hooks.json" ]]; then
|
||||
bold "Hook endpoints"
|
||||
python3 - "${CONFIG_DIR}/hooks.json" <<'PY'
|
||||
import json, sys
|
||||
with open(sys.argv[1]) as fh:
|
||||
for hook in json.load(fh):
|
||||
print(f" /hooks/{hook['id']}")
|
||||
PY
|
||||
fi
|
||||
|
||||
bold "Targets on this host"
|
||||
mapfile -t targets < <("${REPO_ROOT}/bin/cd-target" list 2>/dev/null || true)
|
||||
if [[ ${#targets[@]} -eq 0 ]]; then
|
||||
printf ' none\n'
|
||||
else
|
||||
for target in "${targets[@]}"; do
|
||||
log="${STATE_DIR}/${target}.log"
|
||||
if [[ -f "$log" ]]; then
|
||||
last="$(grep -E '=== deploy succeeded|ERROR|WARN health' "$log" | tail -n1 || true)"
|
||||
printf ' %-22s %s\n' "$target" "${last:-no completed deploy recorded}"
|
||||
else
|
||||
printf ' %-22s %s\n' "$target" "never deployed from this host"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
bold "Recent receiver log"
|
||||
journalctl --user -u "$UNIT_NAME" -n 15 --no-pager 2>/dev/null \
|
||||
|| printf ' (no journal entries)\n'
|
||||
echo
|
||||
Reference in New Issue
Block a user