From 5bce042922ce5e7bf48eb175433f1a839df9a1b0 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Wed, 10 Mar 2021 23:28:59 +0100 Subject: [PATCH] First steps to enable abra-hetzner See https://git.autonomic.zone/coop-cloud/abra/issues/88. --- abra | 233 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 135 insertions(+), 98 deletions(-) diff --git a/abra b/abra index 7c2b0db..57ca1b0 100755 --- a/abra +++ b/abra @@ -33,6 +33,7 @@ Usage: abra [options] app undeploy abra [options] app [...] abra [options] server add [] [] + abra [options] server new abra [options] server (list|ls) abra [options] server rm abra [options] server init @@ -154,103 +155,105 @@ 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:1954} -usage=${DOC:40:1418}; digest=96f0f -shorts=(-s -h -U -e -d -b -v -C '' '' '' '' '' '' '' '' '' '' '' '') -longs=(--stack --help --skip-update --env --debug --branch --verbose --skip-check --status --server --domain --app-name --pass --secrets --all --update --force --volumes --no-tty --user) -argcounts=(1 0 0 1 0 1 0 0 0 1 1 1 0 0 0 0 0 0 0 1); node_0(){ value __stack 0 -}; node_1(){ switch __help 1; }; node_2(){ switch __skip_update 2; }; node_3(){ -value __env 3; }; node_4(){ switch __debug 4; }; node_5(){ value __branch 5; } -node_6(){ switch __verbose 6; }; node_7(){ switch __skip_check 7; }; node_8(){ -switch __status 8; }; node_9(){ value __server 9; }; node_10(){ -value __domain 10; }; node_11(){ value __app_name 11; }; node_12(){ -switch __pass 12; }; node_13(){ switch __secrets 13; }; node_14(){ -switch __all 14; }; node_15(){ switch __update 15; }; node_16(){ -switch __force 16; }; node_17(){ switch __volumes 17; }; node_18(){ -switch __no_tty 18; }; node_19(){ value __user 19; }; node_20(){ value _type_ a -}; node_21(){ value _app_ a; }; node_22(){ value _service_ a; }; node_23(){ -value _src_ a; }; node_24(){ value _dst_ a; }; node_25(){ value _backup_file_ a -}; node_26(){ value _args_ a true; }; node_27(){ value _secret_ a; }; node_28(){ +printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1993} +usage=${DOC:40:1457}; digest=06b80 +shorts=(-C -v -b -e -U -d -s -h '' '' '' '' '' '' '' '' '' '' '' '') +longs=(--skip-check --verbose --branch --env --skip-update --debug --stack --help --status --server --domain --app-name --pass --secrets --all --update --force --volumes --no-tty --user) +argcounts=(0 0 1 1 0 0 1 0 0 1 1 1 0 0 0 0 0 0 0 1); node_0(){ +switch __skip_check 0; }; node_1(){ switch __verbose 1; }; node_2(){ +value __branch 2; }; node_3(){ value __env 3; }; node_4(){ +switch __skip_update 4; }; node_5(){ switch __debug 5; }; node_6(){ +value __stack 6; }; node_7(){ switch __help 7; }; node_8(){ switch __status 8; } +node_9(){ value __server 9; }; node_10(){ value __domain 10; }; node_11(){ +value __app_name 11; }; node_12(){ switch __pass 12; }; node_13(){ +switch __secrets 13; }; node_14(){ switch __all 14; }; node_15(){ +switch __update 15; }; node_16(){ switch __force 16; }; node_17(){ +switch __volumes 17; }; node_18(){ switch __no_tty 18; }; node_19(){ +value __user 19; }; node_20(){ value _type_ a; }; node_21(){ value _app_ a; } +node_22(){ value _service_ a; }; node_23(){ value _src_ a; }; node_24(){ +value _dst_ a; }; node_25(){ value _backup_file_ a; }; node_26(){ +value _args_ a true; }; node_27(){ value _secret_ a; }; node_28(){ value _version_ a; }; node_29(){ value _cmd_ a; }; node_30(){ value _data_ a; } node_31(){ value _command_ a; }; node_32(){ value _host_ a; }; node_33(){ -value _user_ a; }; node_34(){ value _port_ a; }; node_35(){ -value _subcommands_ a true; }; node_36(){ _command app; }; node_37(){ -_command list; }; node_38(){ _command ls; }; node_39(){ _command new; } -node_40(){ _command backup; }; node_41(){ _command deploy; }; node_42(){ -_command check; }; node_43(){ _command config; }; node_44(){ _command cp; } -node_45(){ _command logs; }; node_46(){ _command ps; }; node_47(){ -_command restore; }; node_48(){ _command rm; }; node_49(){ _command delete; } -node_50(){ _command run; }; node_51(){ _command rollback; }; node_52(){ -_command secret; }; node_53(){ _command generate; }; node_54(){ _command insert -}; node_55(){ _command undeploy; }; node_56(){ _command server; }; node_57(){ -_command add; }; node_58(){ _command init; }; node_59(){ _command apps; } -node_60(){ _command upgrade; }; node_61(){ _command version; }; node_62(){ -_command help; }; node_63(){ optional 0 1 2 3 4 5 6 7; }; node_64(){ optional 63 -}; node_65(){ either 37 38; }; node_66(){ required 65; }; node_67(){ optional 8 -}; node_68(){ optional 9; }; node_69(){ required 64 36 66 67 68; }; node_70(){ -optional 10; }; node_71(){ optional 11; }; node_72(){ optional 12; }; node_73(){ -optional 13; }; node_74(){ required 64 36 39 68 70 71 72 73 20; }; node_75(){ -either 22 14; }; node_76(){ required 75; }; node_77(){ required 64 36 21 40 76 -}; node_78(){ optional 15; }; node_79(){ required 64 36 21 41 78; }; node_80(){ -required 64 36 21 42; }; node_81(){ required 64 36 21 43; }; node_82(){ -required 64 36 21 44 23 24; }; node_83(){ optional 22; }; node_84(){ -required 64 36 21 45 83; }; node_85(){ required 64 36 21 46; }; node_86(){ -required 64 36 21 47 76; }; node_87(){ either 48 49; }; node_88(){ required 87 -}; node_89(){ optional 16; }; node_90(){ optional 17; }; node_91(){ -required 64 36 21 88 89 90 73; }; node_92(){ optional 25; }; node_93(){ -required 64 36 21 47 22 92; }; node_94(){ optional 18; }; node_95(){ optional 19 -}; node_96(){ oneormore 26; }; node_97(){ required 64 36 21 50 94 95 22 96; } -node_98(){ required 64 36 21 51 22; }; node_99(){ required 27 28; }; node_100(){ -either 99 14; }; node_101(){ required 100; }; node_102(){ optional 29; } -node_103(){ required 64 36 21 52 53 101 102 72; }; node_104(){ -required 64 36 21 52 54 27 28 30 72; }; node_105(){ either 27 14; }; node_106(){ -required 105; }; node_107(){ required 64 36 21 52 88 106 72 89; }; node_108(){ -required 64 36 21 55; }; node_109(){ optional 96; }; node_110(){ -required 64 36 21 31 109; }; node_111(){ optional 33; }; node_112(){ optional 34 -}; node_113(){ required 64 56 57 32 111 112; }; node_114(){ required 64 56 66; } -node_115(){ required 64 56 32 48; }; node_116(){ required 64 56 32 58; } -node_117(){ required 64 56 32 59 67; }; node_118(){ required 64 60; } -node_119(){ required 64 61; }; node_120(){ oneormore 35; }; node_121(){ -optional 120; }; node_122(){ required 64 62 121; }; node_123(){ required 64; } -node_124(){ -either 69 74 77 79 80 81 82 84 85 86 91 93 97 98 103 104 107 108 110 113 114 115 116 117 118 119 122 123 -}; node_125(){ required 124; }; cat <<<' docopt_exit() { -[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1418}" >&2 -exit 1; }'; unset var___stack var___help var___skip_update var___env \ -var___debug var___branch var___verbose var___skip_check var___status \ -var___server var___domain var___app_name var___pass var___secrets var___all \ -var___update var___force var___volumes var___no_tty var___user 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__subcommands_ var_app var_list var_ls var_new \ +value _user_ a; }; node_34(){ value _port_ a; }; node_35(){ value _provider_ a +}; node_36(){ value _subcommands_ a true; }; node_37(){ _command app; } +node_38(){ _command list; }; node_39(){ _command ls; }; node_40(){ _command new +}; node_41(){ _command backup; }; node_42(){ _command deploy; }; node_43(){ +_command check; }; node_44(){ _command config; }; node_45(){ _command cp; } +node_46(){ _command logs; }; node_47(){ _command ps; }; node_48(){ +_command restore; }; node_49(){ _command rm; }; node_50(){ _command delete; } +node_51(){ _command run; }; node_52(){ _command rollback; }; node_53(){ +_command secret; }; node_54(){ _command generate; }; node_55(){ _command insert +}; node_56(){ _command undeploy; }; node_57(){ _command server; }; node_58(){ +_command add; }; node_59(){ _command init; }; node_60(){ _command apps; } +node_61(){ _command upgrade; }; node_62(){ _command version; }; node_63(){ +_command help; }; node_64(){ optional 0 1 2 3 4 5 6 7; }; node_65(){ optional 64 +}; node_66(){ either 38 39; }; node_67(){ required 66; }; node_68(){ optional 8 +}; node_69(){ optional 9; }; node_70(){ required 65 37 67 68 69; }; node_71(){ +optional 10; }; node_72(){ optional 11; }; node_73(){ optional 12; }; node_74(){ +optional 13; }; node_75(){ required 65 37 40 69 71 72 73 74 20; }; node_76(){ +either 22 14; }; node_77(){ required 76; }; node_78(){ required 65 37 21 41 77 +}; node_79(){ optional 15; }; node_80(){ required 65 37 21 42 79; }; node_81(){ +required 65 37 21 43; }; node_82(){ required 65 37 21 44; }; node_83(){ +required 65 37 21 45 23 24; }; node_84(){ optional 22; }; node_85(){ +required 65 37 21 46 84; }; node_86(){ required 65 37 21 47; }; node_87(){ +required 65 37 21 48 77; }; node_88(){ either 49 50; }; node_89(){ required 88 +}; node_90(){ optional 16; }; node_91(){ optional 17; }; node_92(){ +required 65 37 21 89 90 91 74; }; node_93(){ optional 25; }; node_94(){ +required 65 37 21 48 22 93; }; node_95(){ optional 18; }; node_96(){ optional 19 +}; node_97(){ oneormore 26; }; node_98(){ required 65 37 21 51 95 96 22 97; } +node_99(){ required 65 37 21 52 22; }; node_100(){ required 27 28; } +node_101(){ either 100 14; }; node_102(){ required 101; }; node_103(){ +optional 29; }; node_104(){ required 65 37 21 53 54 102 103 73; }; node_105(){ +required 65 37 21 53 55 27 28 30 73; }; node_106(){ either 27 14; }; node_107(){ +required 106; }; node_108(){ required 65 37 21 53 89 107 73 90; }; node_109(){ +required 65 37 21 56; }; node_110(){ optional 97; }; node_111(){ +required 65 37 21 31 110; }; node_112(){ optional 33; }; node_113(){ optional 34 +}; node_114(){ required 65 57 58 32 112 113; }; node_115(){ required 65 57 40 35 +}; node_116(){ required 65 57 67; }; node_117(){ required 65 57 32 49; } +node_118(){ required 65 57 32 59; }; node_119(){ required 65 57 32 60 68; } +node_120(){ required 65 61; }; node_121(){ required 65 62; }; node_122(){ +oneormore 36; }; node_123(){ optional 122; }; node_124(){ required 65 63 123; } +node_125(){ required 65; }; node_126(){ +either 70 75 78 80 81 82 83 85 86 87 92 94 98 99 104 105 108 109 111 114 115 116 117 118 119 120 121 124 125 +}; node_127(){ required 126; }; cat <<<' docopt_exit() { +[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1457}" >&2 +exit 1; }'; unset var___skip_check var___verbose var___branch var___env \ +var___skip_update var___debug var___stack var___help var___status var___server \ +var___domain var___app_name var___pass var___secrets var___all var___update \ +var___force var___volumes var___no_tty var___user 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_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_version \ -var_help; parse 125 "$@"; local prefix=${DOCOPT_PREFIX:-''} -unset "${prefix}__stack" "${prefix}__help" "${prefix}__skip_update" \ -"${prefix}__env" "${prefix}__debug" "${prefix}__branch" "${prefix}__verbose" \ -"${prefix}__skip_check" "${prefix}__status" "${prefix}__server" \ +var_help; parse 127 "$@"; local prefix=${DOCOPT_PREFIX:-''} +unset "${prefix}__skip_check" "${prefix}__verbose" "${prefix}__branch" \ +"${prefix}__env" "${prefix}__skip_update" "${prefix}__debug" \ +"${prefix}__stack" "${prefix}__help" "${prefix}__status" "${prefix}__server" \ "${prefix}__domain" "${prefix}__app_name" "${prefix}__pass" \ "${prefix}__secrets" "${prefix}__all" "${prefix}__update" "${prefix}__force" \ "${prefix}__volumes" "${prefix}__no_tty" "${prefix}__user" "${prefix}_type_" \ "${prefix}_app_" "${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" \ "${prefix}_backup_file_" "${prefix}_args_" "${prefix}_secret_" \ "${prefix}_version_" "${prefix}_cmd_" "${prefix}_data_" "${prefix}_command_" \ -"${prefix}_host_" "${prefix}_user_" "${prefix}_port_" "${prefix}_subcommands_" \ -"${prefix}app" "${prefix}list" "${prefix}ls" "${prefix}new" "${prefix}backup" \ -"${prefix}deploy" "${prefix}check" "${prefix}config" "${prefix}cp" \ -"${prefix}logs" "${prefix}ps" "${prefix}restore" "${prefix}rm" \ -"${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}version" "${prefix}help"; eval "${prefix}"'__stack=${var___stack:-}' -eval "${prefix}"'__help=${var___help:-false}' -eval "${prefix}"'__skip_update=${var___skip_update:-false}' -eval "${prefix}"'__env=${var___env:-}' -eval "${prefix}"'__debug=${var___debug:-false}' -eval "${prefix}"'__branch=${var___branch:-}' -eval "${prefix}"'__verbose=${var___verbose:-false}' +"${prefix}_host_" "${prefix}_user_" "${prefix}_port_" "${prefix}_provider_" \ +"${prefix}_subcommands_" "${prefix}app" "${prefix}list" "${prefix}ls" \ +"${prefix}new" "${prefix}backup" "${prefix}deploy" "${prefix}check" \ +"${prefix}config" "${prefix}cp" "${prefix}logs" "${prefix}ps" \ +"${prefix}restore" "${prefix}rm" "${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}version" "${prefix}help" eval "${prefix}"'__skip_check=${var___skip_check:-false}' +eval "${prefix}"'__verbose=${var___verbose:-false}' +eval "${prefix}"'__branch=${var___branch:-}' +eval "${prefix}"'__env=${var___env:-}' +eval "${prefix}"'__skip_update=${var___skip_update:-false}' +eval "${prefix}"'__debug=${var___debug:-false}' +eval "${prefix}"'__stack=${var___stack:-}' +eval "${prefix}"'__help=${var___help:-false}' eval "${prefix}"'__status=${var___status:-false}' eval "${prefix}"'__server=${var___server:-}' eval "${prefix}"'__domain=${var___domain:-}' @@ -276,6 +279,7 @@ eval "${prefix}"'_command_=${var__command_:-}' eval "${prefix}"'_host_=${var__host_:-}' eval "${prefix}"'_user_=${var__user_:-}' eval "${prefix}"'_port_=${var__port_:-}' +eval "${prefix}"'_provider_=${var__provider_:-}' if declare -p var__subcommands_ >/dev/null 2>&1; then eval "${prefix}"'_subcommands_=("${var__subcommands_[@]}")'; else eval "${prefix}"'_subcommands_=()'; fi; eval "${prefix}"'app=${var_app:-false}' @@ -304,23 +308,23 @@ eval "${prefix}"'upgrade=${var_upgrade:-false}' eval "${prefix}"'version=${var_version:-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}__stack" "${prefix}__help" "${prefix}__skip_update" \ -"${prefix}__env" "${prefix}__debug" "${prefix}__branch" "${prefix}__verbose" \ -"${prefix}__skip_check" "${prefix}__status" "${prefix}__server" \ +declare -p "${prefix}__skip_check" "${prefix}__verbose" "${prefix}__branch" \ +"${prefix}__env" "${prefix}__skip_update" "${prefix}__debug" \ +"${prefix}__stack" "${prefix}__help" "${prefix}__status" "${prefix}__server" \ "${prefix}__domain" "${prefix}__app_name" "${prefix}__pass" \ "${prefix}__secrets" "${prefix}__all" "${prefix}__update" "${prefix}__force" \ "${prefix}__volumes" "${prefix}__no_tty" "${prefix}__user" "${prefix}_type_" \ "${prefix}_app_" "${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" \ "${prefix}_backup_file_" "${prefix}_args_" "${prefix}_secret_" \ "${prefix}_version_" "${prefix}_cmd_" "${prefix}_data_" "${prefix}_command_" \ -"${prefix}_host_" "${prefix}_user_" "${prefix}_port_" "${prefix}_subcommands_" \ -"${prefix}app" "${prefix}list" "${prefix}ls" "${prefix}new" "${prefix}backup" \ -"${prefix}deploy" "${prefix}check" "${prefix}config" "${prefix}cp" \ -"${prefix}logs" "${prefix}ps" "${prefix}restore" "${prefix}rm" \ -"${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}version" "${prefix}help"; done; } +"${prefix}_host_" "${prefix}_user_" "${prefix}_port_" "${prefix}_provider_" \ +"${prefix}_subcommands_" "${prefix}app" "${prefix}list" "${prefix}ls" \ +"${prefix}new" "${prefix}backup" "${prefix}deploy" "${prefix}check" \ +"${prefix}config" "${prefix}cp" "${prefix}logs" "${prefix}ps" \ +"${prefix}restore" "${prefix}rm" "${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}version" "${prefix}help"; done; } # docopt parser above, complete command for generating this parser is `docopt.sh abra` PROGRAM_NAME=$(basename "$0") @@ -1568,7 +1572,40 @@ sub_server_add() { mkdir -p "$ABRA_DIR/servers/$HOST" } -###### .. server delete +###### .. server new +help_server_new (){ + echo "abra [options] server new + +Use a provider plugin to create an actual new server resource (VPS or +otherwise) which can then be used to house a new Co-op Cloud installation. + +OPTIONS + Provider plugin for creating new server (choices: hetzner)" +} + +sub_server_new() { + require_abra_dir + + PROVIDER="$abra__provider_" + BRANCH="${abra___branch:-master}" + + if [ "$PROVIDER" != "hetzner" ]; then + error "Unknown provider plugin 'abra-${PROVIDER}'" + fi + + if [ ! -d "$ABRA_DIR/plugins/abra-$PROVIDER" ]; then + warning "The 'abra-$PROVIDER' plugin was not found, fetching via Git" + if ! git clone --branch "$BRANCH" "$GIT_URL/abra-$PROVIDER.git" "$ABRA_DIR/plugins/abra-$PROVIDER" > /dev/null 2>&1 ; then + error "Could not retrieve the abra-$PROVIDER plugin, does it exist?" + fi + success "Fetched abra-$PROVIDER plugin via Git (branch: $BRANCH)" + fi + + # shellcheck disable=SC1090 + source "$ABRA_DIR/plugins/abra-$PROVIDER/abra-$PROVIDER" +} + +##host> delete help_server_rm (){ help_server_delete } @@ -1693,7 +1730,7 @@ abra() { abra___secrets abra___status abra___no_tty abra___app_name \ abra__subcommands_ abra___skip_update abra___skip_check \ abra__backup_file_ abra___verbose abra___debug abra___help \ - abra___update abra___branch abra___volumes + abra___update abra___branch abra___volumes abra__provider_ if ! type tput > /dev/null 2>&1; then tput() {