diff --git a/scripts/easy-docker/lib/app/wizard/common/compose.sh b/scripts/easy-docker/lib/app/wizard/common/compose.sh index abe50ee0..f890efe5 100755 --- a/scripts/easy-docker/lib/app/wizard/common/compose.sh +++ b/scripts/easy-docker/lib/app/wizard/common/compose.sh @@ -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 </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 <&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" \