feat: report grouped task progress
This commit is contained in:
1 parent
5895d8f3a3
commit
475434042c
1 file changed
+48
-32
@@ -247,10 +247,15 @@ stack_group() {
|
|||||||
compose() {
|
compose() {
|
||||||
local stack="$1"
|
local stack="$1"
|
||||||
shift
|
shift
|
||||||
|
local -a docker_args=(compose)
|
||||||
|
|
||||||
|
if [[ "${STACKS_QUIET_PROGRESS:-0}" == "1" ]]; then
|
||||||
|
docker_args+=(--progress quiet)
|
||||||
|
fi
|
||||||
|
|
||||||
(
|
(
|
||||||
cd -- "$STACKS_DIR/$stack" || exit 1
|
cd -- "$STACKS_DIR/$stack" || exit 1
|
||||||
docker compose "$@"
|
docker "${docker_args[@]}" "$@"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,10 +290,17 @@ run_group() {
|
|||||||
local action="$2"
|
local action="$2"
|
||||||
local group_name="${GROUP_NAMES[group_index]}"
|
local group_name="${GROUP_NAMES[group_index]}"
|
||||||
local limit="${GROUP_LIMITS[group_index]}"
|
local limit="${GROUP_LIMITS[group_index]}"
|
||||||
local semaphore_dir semaphore_fifo semaphore_fd
|
local stack pid finished_pid status result result_color success_result details
|
||||||
local stack pid i status details
|
local next=0 running=0 completed=0 failed=0
|
||||||
local failed=0
|
local success_color="" failure_color="" color_reset=""
|
||||||
local -a stacks=() pids=() pid_stacks=()
|
local -a stacks=()
|
||||||
|
local -A pid_stacks=()
|
||||||
|
|
||||||
|
if [[ -t 1 && -z "${NO_COLOR:-}" ]]; then
|
||||||
|
success_color=$'\033[32m'
|
||||||
|
failure_color=$'\033[31m'
|
||||||
|
color_reset=$'\033[0m'
|
||||||
|
fi
|
||||||
|
|
||||||
read -r -a stacks <<<"${GROUP_STACKS[group_index]}"
|
read -r -a stacks <<<"${GROUP_STACKS[group_index]}"
|
||||||
((${#stacks[@]} > 0)) || return 0
|
((${#stacks[@]} > 0)) || return 0
|
||||||
@@ -308,46 +320,50 @@ run_group() {
|
|||||||
echo
|
echo
|
||||||
echo "==> Group $group_name: $action ($details)"
|
echo "==> Group $group_name: $action ($details)"
|
||||||
|
|
||||||
semaphore_dir="$(mktemp -d "${TMPDIR:-/tmp}/stacks-manage.XXXXXX")" ||
|
case "$action" in
|
||||||
die "cannot create semaphore directory"
|
up | start) success_result="Started" ;;
|
||||||
semaphore_fifo="$semaphore_dir/tokens"
|
restart) success_result="Restarted" ;;
|
||||||
mkfifo "$semaphore_fifo" || die "cannot create semaphore"
|
stop) success_result="Stopped" ;;
|
||||||
exec {semaphore_fd}<>"$semaphore_fifo" || die "cannot open semaphore"
|
down) success_result="Removed" ;;
|
||||||
|
pull) success_result="Pulled" ;;
|
||||||
|
update) success_result="Updated" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
for ((i = 0; i < limit; i++)); do
|
while ((next < ${#stacks[@]} || running > 0)); do
|
||||||
printf '\n' >&"$semaphore_fd"
|
while ((next < ${#stacks[@]} && running < limit)); do
|
||||||
|
stack="${stacks[next]}"
|
||||||
|
STACKS_QUIET_PROGRESS=1 run_stack "$stack" "$action" 0 &
|
||||||
|
pid="$!"
|
||||||
|
pid_stacks["$pid"]="$stack"
|
||||||
|
((next += 1, running += 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
for stack in "${stacks[@]}"; do
|
finished_pid=""
|
||||||
IFS= read -r -u "$semaphore_fd"
|
|
||||||
|
|
||||||
(
|
|
||||||
status=0
|
status=0
|
||||||
run_stack "$stack" "$action" 0 || status=$?
|
wait -n -p finished_pid || status=$?
|
||||||
printf '\n' >&"$semaphore_fd"
|
[[ -n "$finished_pid" ]] || die "cannot identify completed stack"
|
||||||
exit "$status"
|
|
||||||
) &
|
|
||||||
|
|
||||||
pids+=("$!")
|
stack="${pid_stacks[$finished_pid]}"
|
||||||
pid_stacks+=("$stack")
|
unset 'pid_stacks[$finished_pid]'
|
||||||
done
|
((running -= 1))
|
||||||
|
|
||||||
for ((i = 0; i < ${#pids[@]}; i++)); do
|
if ((status == 0)); then
|
||||||
pid="${pids[i]}"
|
result="$success_result"
|
||||||
stack="${pid_stacks[i]}"
|
result_color="$success_color"
|
||||||
|
|
||||||
if wait "$pid"; then
|
|
||||||
((RUN_SUCCESS += 1))
|
((RUN_SUCCESS += 1))
|
||||||
else
|
else
|
||||||
|
result="Failed"
|
||||||
|
result_color="$failure_color"
|
||||||
((RUN_FAILED += 1))
|
((RUN_FAILED += 1))
|
||||||
RUN_FAILED_STACKS+=("$stack")
|
RUN_FAILED_STACKS+=("$stack")
|
||||||
((failed += 1))
|
((failed += 1))
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
exec {semaphore_fd}>&-
|
((completed += 1))
|
||||||
rm -f -- "$semaphore_fifo"
|
printf '[%d/%d] %s: %s%s%s\n' \
|
||||||
rmdir -- "$semaphore_dir"
|
"$completed" "${#stacks[@]}" "$stack" \
|
||||||
|
"$result_color" "$result" "$color_reset"
|
||||||
|
done
|
||||||
|
|
||||||
((failed == 0))
|
((failed == 0))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user