log final

This commit is contained in:
2026-09-25 09:32:33 -03:00
parent 782a130bb9
commit fc4cb86f24
3 changed files with 64 additions and 3 deletions
+59 -3
View File
@@ -2,6 +2,8 @@
#
# Run scripts/build-and-push.sh once per service listed in a project file.
# Continues after a failure and prints a summary when the batch finishes.
# That summary is also written to deploy-YYYYMMDD-HHMMSS.log in the directory
# from which the script was launched.
#
# The list path is required (--services). Relative service paths are resolved
# against the directory that contains that file, not the caller's cwd.
@@ -48,6 +50,9 @@ Usage: $(basename "$0") --remote TARGET --services FILE [options]
Run build-and-push.sh once for every service listed in FILE. One list file
per project: pass a different --services path to deploy another project.
A failure does not stop the batch. The exit code is 1 if any service failed.
When the batch finishes, that summary is written to deploy-YYYYMMDD-HHMMSS.log
in the current directory (local start time). If that name already exists, the
process id is appended.
Required:
--remote TARGET SSH destination forwarded to build-and-push.sh
@@ -193,12 +198,60 @@ normalize_path() {
printf '%s' "$joined"
}
# Plain-text summary in the directory from which the batch was launched.
# A write failure is reported and does not change the batch exit code.
write_summary_log() {
local finished="" summary_index=0 note="" path="" status=""
local -a lines=()
finished="$(date '+%Y-%m-%d %H:%M:%S %z')" || {
warn "Could not write log file: ${log_path}"
return 0
}
lines+=("started: ${run_started}")
lines+=("finished: ${finished}")
lines+=("remote: ${REMOTE}")
lines+=("services_file: ${SERVICES_FILE}")
lines+=("")
while [[ "$summary_index" -lt "$total" ]]; do
note="${result_notes[$summary_index]}"
path="${result_paths[$summary_index]}"
if [[ "$note" == "0" ]]; then
status="ok"
else
status="$note"
fi
lines+=("${path} ${status}")
summary_index=$((summary_index + 1))
done
lines+=("")
lines+=("succeeded: ${ok_count}")
lines+=("failed: ${fail_count}")
if ! printf '%s\n' "${lines[@]}" >"$log_path"; then
warn "Could not write log file: ${log_path}"
return 0
fi
log "Log file: ${log_path}"
}
total="${#services[@]}"
index=0
ok_count=0
fail_count=0
result_paths=()
result_notes=()
launch_dir="$(pwd)"
run_started="$(date '+%Y-%m-%d %H:%M:%S %z')"
log_stamp="$(date '+%Y%m%d-%H%M%S')"
log_path="${launch_dir}/deploy-${log_stamp}.log"
if [[ -e "$log_path" ]]; then
log_path="${launch_dir}/deploy-${log_stamp}-$$.log"
fi
log "Services file: ${SERVICES_FILE}"
log "Remote: ${REMOTE}"
@@ -251,10 +304,13 @@ while [[ "$summary_index" -lt "$total" ]]; do
summary_index=$((summary_index + 1))
done
batch_exit=0
if [[ "$fail_count" -gt 0 ]]; then
err "${ok_count} succeeded, ${fail_count} failed."
exit 1
batch_exit=1
else
ok "${ok_count} succeeded, 0 failed."
fi
ok "${ok_count} succeeded, 0 failed."
exit 0
write_summary_log
exit "$batch_exit"