Share the target filter, fix cd-status branch, record deploy status
- enabled_targets/names_for: one implementation of 'a host acts only on its own targets'; --host s5 and --host s5.fisher.hu now select the same targets - shell_value: JSON booleans reach shell consumers as true/false - cd-status: capture before eval, so the unconfigured-host branch is reachable - cd-deploy writes a .status record; cd-status reads it instead of grepping the log's prose - cd-render-hooks --list-urls replaces two inline JSON readers
This commit is contained in:
+13
-11
@@ -17,7 +17,10 @@ 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
|
||||
# Capture first: `eval ""` succeeds, so evaluating the failed call inline made
|
||||
# the branch below unreachable and tripped `set -u` instead.
|
||||
if host_config="$("${REPO_ROOT}/bin/cd-target" host-config 2>/dev/null)"; then
|
||||
eval "$host_config"
|
||||
printf ' %s, receiver on %s:%s\n' "$CD_HOST" "$CD_BIND" "$CD_PORT"
|
||||
else
|
||||
printf ' %s is not configured in targets.json\n' "$(hostname)"
|
||||
@@ -41,12 +44,8 @@ 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
|
||||
"${REPO_ROOT}/bin/cd-render-hooks" --list-urls \
|
||||
--output "${CONFIG_DIR}/hooks.json" | sed 's/^/ /'
|
||||
fi
|
||||
|
||||
bold "Targets on this host"
|
||||
@@ -55,10 +54,13 @@ 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}"
|
||||
# cd-deploy writes this on every terminal outcome. Reading a record
|
||||
# beats grepping the log for phrases the log is free to reword.
|
||||
status_file="${STATE_DIR}/${target}.status"
|
||||
if [[ -f "$status_file" ]]; then
|
||||
IFS=$'\t' read -r when result sha message < "$status_file" || true
|
||||
printf ' %-22s %s %-4s %s %s\n' \
|
||||
"$target" "$when" "$result" "$sha" "$message"
|
||||
else
|
||||
printf ' %-22s %s\n' "$target" "never deployed from this host"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user