From 9836d2705269aa86db191679ebb53f2f73ebd632 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Fri, 26 Mar 2021 00:26:34 +0100 Subject: [PATCH] Add abra doctor command Closes https://git.autonomic.zone/coop-cloud/abra/issues/119. --- CHANGELOG.md | 1 + abra | 176 +++++++++++++++++++++++++++++---------------------- 2 files changed, 103 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d277f0..91752d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - Use [docker-stack-wait-deploy](https://github.com/vitalets/docker-stack-wait-deploy) inspired logic to deploy apps ([#116](https://git.autonomic.zone/coop-cloud/abra/issues/116)) - Add a domain polling check when deploying apps ([#113](https://git.autonomic.zone/coop-cloud/abra/issues/113)) - Recognise when apps are already undeployed with `abra app undeploy` ([#123](https://git.autonomic.zone/coop-cloud/abra/issues/123)) +- Add `abra doctor` command to help diagnose setup issues ([#119](https://git.autonomic.zone/coop-cloud/abra/issues/119)) # abra 0.6.0 (2021-03-17) diff --git a/abra b/abra index 939da4c..e8064e0 100755 --- a/abra +++ b/abra @@ -43,6 +43,7 @@ Usage: abra [options] server apps [--status] abra [options] upgrade [--dev] abra [options] version + abra [options] doctor abra [options] help [...] abra [options] @@ -159,15 +160,15 @@ eval "var_$1+=($value)"; else eval "var_$1=$value"; fi; return 0; fi; done return 1; }; stdout() { printf -- "cat <<'EOM'\n%s\nEOM\n" "$1"; }; stderr() { printf -- "cat <<'EOM' >&2\n%s\nEOM\n" "$1"; }; error() { [[ -n $1 ]] && stderr "$1"; stderr "$usage"; _return 1; }; _return() { -printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:2105} -usage=${DOC:40:1496}; digest=664f6 -shorts=(-U -s -b -C -e -h -v -n -d '' '' '' '' '' '' '' '' '' '' '' '' '') -longs=(--skip-update --stack --branch --skip-check --env --help --verbose --no-prompt --debug --status --server --type --domain --app-name --pass --secrets --all --update --volumes --no-tty --user --dev) -argcounts=(0 1 1 0 1 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 0); node_0(){ -switch __skip_update 0; }; node_1(){ value __stack 1; }; node_2(){ -value __branch 2; }; node_3(){ switch __skip_check 3; }; node_4(){ value __env 4 -}; node_5(){ switch __help 5; }; node_6(){ switch __verbose 6; }; node_7(){ -switch __no_prompt 7; }; node_8(){ switch __debug 8; }; node_9(){ +printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:2129} +usage=${DOC:40:1520}; digest=a0f64 +shorts=(-h -d -e -U -C -s -n -b -v '' '' '' '' '' '' '' '' '' '' '' '' '') +longs=(--help --debug --env --skip-update --skip-check --stack --no-prompt --branch --verbose --status --server --type --domain --app-name --pass --secrets --all --update --volumes --no-tty --user --dev) +argcounts=(0 0 1 0 0 1 0 1 0 0 1 1 1 1 0 0 0 0 0 0 1 0); node_0(){ +switch __help 0; }; node_1(){ switch __debug 1; }; node_2(){ value __env 2; } +node_3(){ switch __skip_update 3; }; node_4(){ switch __skip_check 4; } +node_5(){ value __stack 5; }; node_6(){ switch __no_prompt 6; }; node_7(){ +value __branch 7; }; node_8(){ switch __verbose 8; }; node_9(){ switch __status 9; }; node_10(){ value __server 10; }; node_11(){ value __type 11; }; node_12(){ value __domain 12; }; node_13(){ value __app_name 13; }; node_14(){ switch __pass 14; }; node_15(){ @@ -191,53 +192,55 @@ _command delete; }; node_54(){ _command run; }; node_55(){ _command rollback; } node_56(){ _command secret; }; node_57(){ _command generate; }; node_58(){ _command insert; }; node_59(){ _command undeploy; }; node_60(){ _command server }; node_61(){ _command add; }; node_62(){ _command init; }; node_63(){ -_command apps; }; node_64(){ _command upgrade; }; node_65(){ _command help; } -node_66(){ optional 0 1 2 3 4 5 6 7 8; }; node_67(){ optional 66; }; node_68(){ -either 40 41; }; node_69(){ required 68; }; node_70(){ optional 9; }; node_71(){ -optional 10; }; node_72(){ optional 11; }; node_73(){ required 67 39 69 70 71 72 -}; node_74(){ optional 12; }; node_75(){ optional 13; }; node_76(){ optional 14 -}; node_77(){ optional 15; }; node_78(){ required 67 39 42 71 74 75 76 77 22; } -node_79(){ either 24 16; }; node_80(){ required 79; }; node_81(){ -required 67 39 23 43 80; }; node_82(){ optional 17; }; node_83(){ -required 67 39 23 44 82; }; node_84(){ required 67 39 23 45; }; node_85(){ -required 67 39 23 46; }; node_86(){ required 67 39 23 47; }; node_87(){ -required 67 39 23 48 25 26; }; node_88(){ optional 24; }; node_89(){ -required 67 39 23 49 88; }; node_90(){ required 67 39 23 50; }; node_91(){ -required 67 39 23 51 80; }; node_92(){ either 52 53; }; node_93(){ required 92 -}; node_94(){ optional 18; }; node_95(){ required 67 39 23 93 94 77; } -node_96(){ optional 27; }; node_97(){ required 67 39 23 51 24 96; }; node_98(){ -optional 19; }; node_99(){ optional 20; }; node_100(){ oneormore 28; } -node_101(){ required 67 39 23 54 98 99 24 100; }; node_102(){ -required 67 39 23 55 24; }; node_103(){ required 29 30; }; node_104(){ -either 103 16; }; node_105(){ required 104; }; node_106(){ optional 31; } -node_107(){ required 67 39 23 56 57 105 106 76; }; node_108(){ -required 67 39 23 56 58 29 30 32 76; }; node_109(){ either 29 16; }; node_110(){ -required 109; }; node_111(){ required 67 39 23 56 93 110 76; }; node_112(){ -required 67 39 23 59; }; node_113(){ optional 100; }; node_114(){ -required 67 39 23 33 113; }; node_115(){ optional 35; }; node_116(){ optional 36 -}; node_117(){ required 67 60 61 34 115 116; }; node_118(){ required 67 60 42 37 -}; node_119(){ required 67 60 69; }; node_120(){ required 67 60 34 52; } -node_121(){ required 67 60 34 62; }; node_122(){ required 67 60 34 63 70; } -node_123(){ optional 21; }; node_124(){ required 67 64 123; }; node_125(){ -required 67 46; }; node_126(){ oneormore 38; }; node_127(){ optional 126; } -node_128(){ required 67 65 127; }; node_129(){ required 67; }; node_130(){ -either 73 78 81 83 84 85 86 87 89 90 91 95 97 101 102 107 108 111 112 114 117 118 119 120 121 122 124 125 128 129 -}; node_131(){ required 130; }; cat <<<' docopt_exit() { -[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1496}" >&2 -exit 1; }'; unset var___skip_update var___stack var___branch var___skip_check \ -var___env var___help var___verbose var___no_prompt var___debug var___status \ -var___server var___type var___domain var___app_name var___pass var___secrets \ -var___all var___update var___volumes var___no_tty var___user var___dev \ -var__type_ var__app_ var__service_ var__src_ var__dst_ var__backup_file_ \ -var__args_ var__secret_ var__version_ var__cmd_ var__data_ var__command_ \ -var__host_ var__user_ var__port_ var__provider_ var__subcommands_ var_app \ -var_list var_ls var_new var_backup var_deploy var_check var_version var_config \ -var_cp var_logs var_ps var_restore var_rm var_delete var_run var_rollback \ -var_secret var_generate var_insert var_undeploy var_server var_add var_init \ -var_apps var_upgrade var_help; parse 131 "$@"; local prefix=${DOCOPT_PREFIX:-''} -unset "${prefix}__skip_update" "${prefix}__stack" "${prefix}__branch" \ -"${prefix}__skip_check" "${prefix}__env" "${prefix}__help" \ -"${prefix}__verbose" "${prefix}__no_prompt" "${prefix}__debug" \ +_command apps; }; node_64(){ _command upgrade; }; node_65(){ _command doctor; } +node_66(){ _command help; }; node_67(){ optional 0 1 2 3 4 5 6 7 8; } +node_68(){ optional 67; }; node_69(){ either 40 41; }; node_70(){ required 69; } +node_71(){ optional 9; }; node_72(){ optional 10; }; node_73(){ optional 11; } +node_74(){ required 68 39 70 71 72 73; }; node_75(){ optional 12; }; node_76(){ +optional 13; }; node_77(){ optional 14; }; node_78(){ optional 15; }; node_79(){ +required 68 39 42 72 75 76 77 78 22; }; node_80(){ either 24 16; }; node_81(){ +required 80; }; node_82(){ required 68 39 23 43 81; }; node_83(){ optional 17; } +node_84(){ required 68 39 23 44 83; }; node_85(){ required 68 39 23 45; } +node_86(){ required 68 39 23 46; }; node_87(){ required 68 39 23 47; } +node_88(){ required 68 39 23 48 25 26; }; node_89(){ optional 24; }; node_90(){ +required 68 39 23 49 89; }; node_91(){ required 68 39 23 50; }; node_92(){ +required 68 39 23 51 81; }; node_93(){ either 52 53; }; node_94(){ required 93 +}; node_95(){ optional 18; }; node_96(){ required 68 39 23 94 95 78; } +node_97(){ optional 27; }; node_98(){ required 68 39 23 51 24 97; }; node_99(){ +optional 19; }; node_100(){ optional 20; }; node_101(){ oneormore 28; } +node_102(){ required 68 39 23 54 99 100 24 101; }; node_103(){ +required 68 39 23 55 24; }; node_104(){ required 29 30; }; node_105(){ +either 104 16; }; node_106(){ required 105; }; node_107(){ optional 31; } +node_108(){ required 68 39 23 56 57 106 107 77; }; node_109(){ +required 68 39 23 56 58 29 30 32 77; }; node_110(){ either 29 16; }; node_111(){ +required 110; }; node_112(){ required 68 39 23 56 94 111 77; }; node_113(){ +required 68 39 23 59; }; node_114(){ optional 101; }; node_115(){ +required 68 39 23 33 114; }; node_116(){ optional 35; }; node_117(){ optional 36 +}; node_118(){ required 68 60 61 34 116 117; }; node_119(){ required 68 60 42 37 +}; node_120(){ required 68 60 70; }; node_121(){ required 68 60 34 52; } +node_122(){ required 68 60 34 62; }; node_123(){ required 68 60 34 63 71; } +node_124(){ optional 21; }; node_125(){ required 68 64 124; }; node_126(){ +required 68 46; }; node_127(){ required 68 65; }; node_128(){ oneormore 38; } +node_129(){ optional 128; }; node_130(){ required 68 66 129; }; node_131(){ +required 68; }; node_132(){ +either 74 79 82 84 85 86 87 88 90 91 92 96 98 102 103 108 109 112 113 115 118 119 120 121 122 123 125 126 127 130 131 +}; node_133(){ required 132; }; cat <<<' docopt_exit() { +[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1520}" >&2 +exit 1; }'; unset var___help var___debug var___env var___skip_update \ +var___skip_check var___stack var___no_prompt var___branch var___verbose \ +var___status var___server var___type var___domain var___app_name var___pass \ +var___secrets var___all var___update var___volumes var___no_tty var___user \ +var___dev var__type_ var__app_ var__service_ var__src_ var__dst_ \ +var__backup_file_ var__args_ var__secret_ var__version_ var__cmd_ var__data_ \ +var__command_ var__host_ var__user_ var__port_ var__provider_ \ +var__subcommands_ var_app var_list var_ls var_new var_backup var_deploy \ +var_check var_version var_config var_cp var_logs var_ps var_restore var_rm \ +var_delete var_run var_rollback var_secret var_generate var_insert \ +var_undeploy var_server var_add var_init var_apps var_upgrade var_doctor \ +var_help; parse 133 "$@"; local prefix=${DOCOPT_PREFIX:-''} +unset "${prefix}__help" "${prefix}__debug" "${prefix}__env" \ +"${prefix}__skip_update" "${prefix}__skip_check" "${prefix}__stack" \ +"${prefix}__no_prompt" "${prefix}__branch" "${prefix}__verbose" \ "${prefix}__status" "${prefix}__server" "${prefix}__type" "${prefix}__domain" \ "${prefix}__app_name" "${prefix}__pass" "${prefix}__secrets" "${prefix}__all" \ "${prefix}__update" "${prefix}__volumes" "${prefix}__no_tty" "${prefix}__user" \ @@ -252,15 +255,15 @@ unset "${prefix}__skip_update" "${prefix}__stack" "${prefix}__branch" \ "${prefix}delete" "${prefix}run" "${prefix}rollback" "${prefix}secret" \ "${prefix}generate" "${prefix}insert" "${prefix}undeploy" "${prefix}server" \ "${prefix}add" "${prefix}init" "${prefix}apps" "${prefix}upgrade" \ -"${prefix}help"; eval "${prefix}"'__skip_update=${var___skip_update:-false}' -eval "${prefix}"'__stack=${var___stack:-}' -eval "${prefix}"'__branch=${var___branch:-}' -eval "${prefix}"'__skip_check=${var___skip_check:-false}' -eval "${prefix}"'__env=${var___env:-}' -eval "${prefix}"'__help=${var___help:-false}' -eval "${prefix}"'__verbose=${var___verbose:-false}' -eval "${prefix}"'__no_prompt=${var___no_prompt:-false}' +"${prefix}doctor" "${prefix}help"; eval "${prefix}"'__help=${var___help:-false}' eval "${prefix}"'__debug=${var___debug:-false}' +eval "${prefix}"'__env=${var___env:-}' +eval "${prefix}"'__skip_update=${var___skip_update:-false}' +eval "${prefix}"'__skip_check=${var___skip_check:-false}' +eval "${prefix}"'__stack=${var___stack:-}' +eval "${prefix}"'__no_prompt=${var___no_prompt:-false}' +eval "${prefix}"'__branch=${var___branch:-}' +eval "${prefix}"'__verbose=${var___verbose:-false}' eval "${prefix}"'__status=${var___status:-false}' eval "${prefix}"'__server=${var___server:-}' eval "${prefix}"'__type=${var___type:-}' @@ -314,11 +317,12 @@ eval "${prefix}"'add=${var_add:-false}' eval "${prefix}"'init=${var_init:-false}' eval "${prefix}"'apps=${var_apps:-false}' eval "${prefix}"'upgrade=${var_upgrade:-false}' +eval "${prefix}"'doctor=${var_doctor:-false}' eval "${prefix}"'help=${var_help:-false}'; local docopt_i=1 [[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do -declare -p "${prefix}__skip_update" "${prefix}__stack" "${prefix}__branch" \ -"${prefix}__skip_check" "${prefix}__env" "${prefix}__help" \ -"${prefix}__verbose" "${prefix}__no_prompt" "${prefix}__debug" \ +declare -p "${prefix}__help" "${prefix}__debug" "${prefix}__env" \ +"${prefix}__skip_update" "${prefix}__skip_check" "${prefix}__stack" \ +"${prefix}__no_prompt" "${prefix}__branch" "${prefix}__verbose" \ "${prefix}__status" "${prefix}__server" "${prefix}__type" "${prefix}__domain" \ "${prefix}__app_name" "${prefix}__pass" "${prefix}__secrets" "${prefix}__all" \ "${prefix}__update" "${prefix}__volumes" "${prefix}__no_tty" "${prefix}__user" \ @@ -333,7 +337,7 @@ declare -p "${prefix}__skip_update" "${prefix}__stack" "${prefix}__branch" \ "${prefix}delete" "${prefix}run" "${prefix}rollback" "${prefix}secret" \ "${prefix}generate" "${prefix}insert" "${prefix}undeploy" "${prefix}server" \ "${prefix}add" "${prefix}init" "${prefix}apps" "${prefix}upgrade" \ -"${prefix}help"; done; } +"${prefix}doctor" "${prefix}help"; done; } # docopt parser above, complete command for generating this parser is `docopt.sh abra` PROGRAM_NAME=$(basename "$0") @@ -524,12 +528,25 @@ require_yq() { } require_docker_version (){ - major_version=$(docker version --format "{{.Server.Version}}" | cut -d'.' -f1) + get_servers - if [[ "$major_version" -lt 20 ]]; then - error "This tool requires Docker v20 or greater. Please upgrade your Docker installation" - exit 1 - fi + MIN_DOCKER_VERSION=19 + + SERVERS+=("default") + + for SERVER in "${SERVERS[@]}"; do + SERVER="${SERVER##*/}" # basename + host=$(docker context inspect "$SERVER" -f "{{.Endpoints.docker.Host}}" 2>/dev/null) + if [[ -n "$host" ]]; then + major_version=$(DOCKER_CONTEXT="$SERVER" docker version --format "{{.Server.Version}}" | cut -d'.' -f1 2>/dev/null) + if [[ "$major_version" -lt "$MIN_DOCKER_VERSION" ]]; then + error "This tool requires Docker v${MIN_DOCKER_VERSION} or greater. Please upgrade your Docker installation on $SERVER" + exit 1 + else + debug "Docker version on $SERVER is sufficient (v${major_version})" + fi + fi + done } # FIXME 3wc: update or remove @@ -1915,6 +1932,18 @@ sub_version() { echo "$ABRA_VERSION${ABRA_DIGEST:+-}${ABRA_DIGEST}" } +###### .. doctor +help_doctor (){ + echo "abra [options] doctor + +Help diagnose setup issues." +} + +sub_doctor() { + require_docker_version + success "Hurrah! Everything is in working order!" +} + ###### .. help help_help (){ echo "HEEEEEELP! 😱" @@ -1966,7 +1995,6 @@ sub_network() { abra() { require_bash_4 - require_docker_version # TODO (3wc): we either need to do this, or add 'shellcheck disable' all over # the place to handle the dynamically-defined vars