feat(easy-docker): show stack runtime status in manage header

This commit is contained in:
RocketQuack 2026-03-01 20:23:14 +01:00
parent 32136ac6fd
commit d2ee473c68
3 changed files with 122 additions and 3 deletions

View file

@ -190,6 +190,119 @@ EOF
return 0
}
get_stack_compose_runtime_status_label() {
local result_var="${1}"
local stack_dir="${2}"
local metadata_path=""
local env_path=""
local stack_topology=""
local compose_files_lines=""
local compose_file=""
local source_compose_path=""
local env_erpnext_version=""
local fallback_erpnext_version=""
local running_services_lines=""
local compose_status=0
local running_services_count=0
local repo_root=""
local status_label=""
local -a compose_args=()
metadata_path="${stack_dir}/metadata.json"
env_path="$(get_stack_env_path "${stack_dir}")"
if [ ! -f "${metadata_path}" ]; then
printf -v "${result_var}" "%s" "Unknown (metadata missing)"
return 0
fi
stack_topology="$(get_stack_topology "${stack_dir}" || true)"
if [ -z "${stack_topology}" ]; then
printf -v "${result_var}" "%s" "Unknown (topology missing)"
return 0
fi
case "${stack_topology}" in
"single-host") ;;
*)
printf -v "${result_var}" "%s" "N/A (${stack_topology})"
return 0
;;
esac
if [ ! -f "${env_path}" ]; then
printf -v "${result_var}" "%s" "Unknown (env missing)"
return 0
fi
env_erpnext_version="$(get_env_file_key_value "${env_path}" "ERPNEXT_VERSION" || true)"
if [ -z "${env_erpnext_version}" ]; then
fallback_erpnext_version="$(get_default_erpnext_version || true)"
fi
compose_files_lines="$(get_metadata_compose_files_lines "${metadata_path}" || true)"
if [ -z "${compose_files_lines}" ]; then
printf -v "${result_var}" "%s" "Unknown (compose files missing)"
return 0
fi
repo_root="$(get_easy_docker_repo_root)"
while IFS= read -r compose_file; do
if [ -z "${compose_file}" ]; then
continue
fi
source_compose_path="${repo_root}/${compose_file}"
if [ ! -f "${source_compose_path}" ]; then
printf -v "${result_var}" "%s" "Unknown (missing file: ${compose_file})"
return 0
fi
compose_args+=(-f "${source_compose_path}")
done <<EOF
${compose_files_lines}
EOF
if [ "${#compose_args[@]}" -eq 0 ]; then
printf -v "${result_var}" "%s" "Unknown (compose files missing)"
return 0
fi
if [ -n "${fallback_erpnext_version}" ]; then
running_services_lines="$(
ERPNEXT_VERSION="${fallback_erpnext_version}" docker compose --env-file "${env_path}" "${compose_args[@]}" ps --status running --services 2>/dev/null
)"
compose_status=$?
else
running_services_lines="$(
docker compose --env-file "${env_path}" "${compose_args[@]}" ps --status running --services 2>/dev/null
)"
compose_status=$?
fi
if [ "${compose_status}" -ne 0 ]; then
printf -v "${result_var}" "%s" "Unknown (docker compose status failed)"
return 0
fi
while IFS= read -r compose_file; do
if [ -n "${compose_file}" ]; then
running_services_count=$((running_services_count + 1))
fi
done <<EOF
${running_services_lines}
EOF
if [ "${running_services_count}" -gt 0 ]; then
status_label="Running (${running_services_count} services)"
else
status_label="Not running"
fi
printf -v "${result_var}" "%s" "${status_label}"
return 0
}
build_stack_custom_image() {
local stack_dir="${1}"
local metadata_path=""

View file

@ -14,6 +14,7 @@ handle_manage_selected_stack_flow() {
local build_image_status=0
local compose_start_status=0
local generated_compose_path=""
local stack_runtime_status=""
stack_dir="$(get_stack_dir_by_name "${stack_name}" || true)"
if [ -z "${stack_dir}" ]; then
@ -22,7 +23,8 @@ handle_manage_selected_stack_flow() {
fi
while true; do
stack_action="$(show_manage_stack_actions_menu "${stack_name}" "${stack_dir}" || true)"
get_stack_compose_runtime_status_label stack_runtime_status "${stack_dir}"
stack_action="$(show_manage_stack_actions_menu "${stack_name}" "${stack_dir}" "${stack_runtime_status}" || true)"
case "${stack_action}" in
"Apps")
while true; do

View file

@ -356,17 +356,21 @@ show_manage_stacks_placeholder() {
show_manage_stack_actions_menu() {
local stack_name="${1}"
local stack_dir="${2}"
local stack_runtime_status="${3:-Unknown}"
local menu_header=""
local status_text=""
render_main_screen 1 >&2
status_text="$(printf "Manage stack\n\nStack: %s\nDirectory: %s\n\nChoose an action for this stack." "${stack_name}" "${stack_dir}")"
status_text="$(printf "Manage stack\n\nStack: %s\nDirectory: %s\nRuntime status: %s\n\nChoose an action for this stack." "${stack_name}" "${stack_dir}" "${stack_runtime_status}")"
render_box_message "${status_text}" "0 2" >&2
menu_header="$(printf "Stack actions | %s" "${stack_runtime_status}")"
gum choose \
--height 8 \
--header "Stack actions" \
--header "${menu_header}" \
--cursor.foreground 63 \
--selected.foreground 45 \
"Apps" \