From fd04c5a6e9ed319dd50b1a657611bf74c07a638a Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Thu, 4 Mar 2021 16:01:56 +0100 Subject: [PATCH] Support branch selection for app repo clones Closes https://git.autonomic.zone/coop-cloud/abra/issues/80. --- CHANGELOG.md | 1 + abra | 219 ++++++++++++++++++++++++++------------------------- 2 files changed, 113 insertions(+), 107 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a13f1ee5..4d735852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - New `app-catalogue.sh` script to auto-generate app list for documentation ([f163d4b](https://git.autonomic.zone/coop-cloud/abra/commit/f163d4b0fa920232e9d995a22d20fe78b174b3a9)) - Support app service rollbacks with `abra rollback ` ([#76](https://git.autonomic.zone/coop-cloud/abra/issues/76)) - Detect when latest version is deployed and perform a no-op ([#87](https://git.autonomic.zone/coop-cloud/abra/issues/87)) +- Allow cloning of app repos with different main branches using `-b, --branch=` ([#80](https://git.autonomic.zone/coop-cloud/abra/issues/80)) # abra 0.5.0 (2021-03-01) diff --git a/abra b/abra index cb60b208..65b2ae04 100755 --- a/abra +++ b/abra @@ -43,13 +43,14 @@ Usage: abra [options] Options: - -e, --env= Environment variables to load - -h, --help Show this message and exit - -s, --stack= Name of the target stack - -C, --skip-check Don't verify app variables - -U, --skip-update Don't pull latest app definitions - -v, --verbose Show INFO messages - -d, --debug Show DEBUG messages + -e, --env= Environment variables to load + -h, --help Show this message and exit + -s, --stack= Name of the target stack + -C, --skip-check Don't verify app variables + -U, --skip-update Don't pull latest app definitions + -v, --verbose Show INFO messages + -d, --debug Show DEBUG messages + -b, --branch= Git branch to use while cloning app repos See 'abra help ...' to read about a specific subcommand. " @@ -153,83 +154,85 @@ 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:1857} -usage=${DOC:40:1394}; digest=42e85 -shorts=(-v -U -C -h -e -d -s '' '' '' '' '' '' '' '' '' '' '') -longs=(--verbose --skip-update --skip-check --help --env --debug --stack --status --server --domain --app-name --pass --secrets --all --update --force --no-tty --user) -argcounts=(0 0 0 0 1 0 1 0 1 1 1 0 0 0 0 0 0 1); node_0(){ switch __verbose 0; } -node_1(){ switch __skip_update 1; }; node_2(){ switch __skip_check 2; } -node_3(){ switch __help 3; }; node_4(){ value __env 4; }; node_5(){ -switch __debug 5; }; node_6(){ value __stack 6; }; node_7(){ switch __status 7 -}; node_8(){ value __server 8; }; node_9(){ value __domain 9; }; node_10(){ -value __app_name 10; }; node_11(){ switch __pass 11; }; node_12(){ -switch __secrets 12; }; node_13(){ switch __all 13; }; node_14(){ -switch __update 14; }; node_15(){ switch __force 15; }; node_16(){ -switch __no_tty 16; }; node_17(){ value __user 17; }; node_18(){ value _type_ a -}; node_19(){ value _app_ a; }; node_20(){ value _service_ a; }; node_21(){ -value _src_ a; }; node_22(){ value _dst_ a; }; node_23(){ value _backup_file_ a -}; node_24(){ value _args_ a true; }; node_25(){ value _secret_ a; }; node_26(){ -value _version_ a; }; node_27(){ value _cmd_ a; }; node_28(){ value _data_ a; } -node_29(){ value _command_ a; }; node_30(){ value _host_ a; }; node_31(){ -value _user_ a; }; node_32(){ value _port_ a; }; node_33(){ -value _subcommands_ a true; }; node_34(){ _command app; }; node_35(){ -_command list; }; node_36(){ _command ls; }; node_37(){ _command new; } -node_38(){ _command backup; }; node_39(){ _command deploy; }; node_40(){ -_command check; }; node_41(){ _command config; }; node_42(){ _command cp; } -node_43(){ _command logs; }; node_44(){ _command ps; }; node_45(){ -_command restore; }; node_46(){ _command rm; }; node_47(){ _command delete; } -node_48(){ _command run; }; node_49(){ _command rollback; }; node_50(){ -_command secret; }; node_51(){ _command generate; }; node_52(){ _command insert -}; node_53(){ _command undeploy; }; node_54(){ _command server; }; node_55(){ -_command add; }; node_56(){ _command init; }; node_57(){ _command apps; } -node_58(){ _command upgrade; }; node_59(){ _command version; }; node_60(){ -_command help; }; node_61(){ optional 0 1 2 3 4 5 6; }; node_62(){ optional 61 -}; node_63(){ either 35 36; }; node_64(){ required 63; }; node_65(){ optional 7 -}; node_66(){ optional 8; }; node_67(){ required 62 34 64 65 66; }; node_68(){ -optional 9; }; node_69(){ optional 10; }; node_70(){ optional 11; }; node_71(){ -optional 12; }; node_72(){ required 62 34 37 66 68 69 70 71 18; }; node_73(){ -either 20 13; }; node_74(){ required 73; }; node_75(){ required 62 34 19 38 74 -}; node_76(){ optional 14; }; node_77(){ required 62 34 19 39 76; }; node_78(){ -required 62 34 19 40; }; node_79(){ required 62 34 19 41; }; node_80(){ -required 62 34 19 42 21 22; }; node_81(){ optional 20; }; node_82(){ -required 62 34 19 43 81; }; node_83(){ required 62 34 19 44; }; node_84(){ -required 62 34 19 45 74; }; node_85(){ either 46 47; }; node_86(){ required 85 -}; node_87(){ optional 15; }; node_88(){ required 62 34 19 86 87; }; node_89(){ -optional 23; }; node_90(){ required 62 34 19 45 20 89; }; node_91(){ optional 16 -}; node_92(){ optional 17; }; node_93(){ oneormore 24; }; node_94(){ -required 62 34 19 48 91 92 20 93; }; node_95(){ required 62 34 19 49 20; } -node_96(){ required 25 26; }; node_97(){ either 96 13; }; node_98(){ required 97 -}; node_99(){ optional 27; }; node_100(){ required 62 34 19 50 51 98 99 70; } -node_101(){ required 62 34 19 50 52 25 26 28 70; }; node_102(){ either 25 13; } -node_103(){ required 102; }; node_104(){ required 62 34 19 50 86 103 70 87; } -node_105(){ required 62 34 19 53; }; node_106(){ optional 93; }; node_107(){ -required 62 34 19 29 106; }; node_108(){ optional 31; }; node_109(){ optional 32 -}; node_110(){ required 62 54 55 30 108 109; }; node_111(){ required 62 54 64; } -node_112(){ required 62 54 30 46; }; node_113(){ required 62 54 30 56; } -node_114(){ required 62 54 30 57 65; }; node_115(){ required 62 58; } -node_116(){ required 62 59; }; node_117(){ oneormore 33; }; node_118(){ -optional 117; }; node_119(){ required 62 60 118; }; node_120(){ required 62; } -node_121(){ -either 67 72 75 77 78 79 80 82 83 84 88 90 94 95 100 101 104 105 107 110 111 112 113 114 115 116 119 120 -}; node_122(){ required 121; }; cat <<<' docopt_exit() { +printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1930} +usage=${DOC:40:1394}; digest=b0304 +shorts=(-b -C -d -s -h -U -e -v '' '' '' '' '' '' '' '' '' '' '') +longs=(--branch --skip-check --debug --stack --help --skip-update --env --verbose --status --server --domain --app-name --pass --secrets --all --update --force --no-tty --user) +argcounts=(1 0 0 1 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1); node_0(){ value __branch 0; } +node_1(){ switch __skip_check 1; }; node_2(){ switch __debug 2; }; node_3(){ +value __stack 3; }; node_4(){ switch __help 4; }; node_5(){ +switch __skip_update 5; }; node_6(){ value __env 6; }; node_7(){ +switch __verbose 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 __no_tty 17; }; node_18(){ value __user 18; }; node_19(){ value _type_ a +}; node_20(){ value _app_ a; }; node_21(){ value _service_ a; }; node_22(){ +value _src_ a; }; node_23(){ value _dst_ a; }; node_24(){ value _backup_file_ a +}; node_25(){ value _args_ a true; }; node_26(){ value _secret_ a; }; node_27(){ +value _version_ a; }; node_28(){ value _cmd_ a; }; node_29(){ value _data_ a; } +node_30(){ value _command_ a; }; node_31(){ value _host_ a; }; node_32(){ +value _user_ a; }; node_33(){ value _port_ a; }; node_34(){ +value _subcommands_ a true; }; node_35(){ _command app; }; node_36(){ +_command list; }; node_37(){ _command ls; }; node_38(){ _command new; } +node_39(){ _command backup; }; node_40(){ _command deploy; }; node_41(){ +_command check; }; node_42(){ _command config; }; node_43(){ _command cp; } +node_44(){ _command logs; }; node_45(){ _command ps; }; node_46(){ +_command restore; }; node_47(){ _command rm; }; node_48(){ _command delete; } +node_49(){ _command run; }; node_50(){ _command rollback; }; node_51(){ +_command secret; }; node_52(){ _command generate; }; node_53(){ _command insert +}; node_54(){ _command undeploy; }; node_55(){ _command server; }; node_56(){ +_command add; }; node_57(){ _command init; }; node_58(){ _command apps; } +node_59(){ _command upgrade; }; node_60(){ _command version; }; node_61(){ +_command help; }; node_62(){ optional 0 1 2 3 4 5 6 7; }; node_63(){ optional 62 +}; node_64(){ either 36 37; }; node_65(){ required 64; }; node_66(){ optional 8 +}; node_67(){ optional 9; }; node_68(){ required 63 35 65 66 67; }; node_69(){ +optional 10; }; node_70(){ optional 11; }; node_71(){ optional 12; }; node_72(){ +optional 13; }; node_73(){ required 63 35 38 67 69 70 71 72 19; }; node_74(){ +either 21 14; }; node_75(){ required 74; }; node_76(){ required 63 35 20 39 75 +}; node_77(){ optional 15; }; node_78(){ required 63 35 20 40 77; }; node_79(){ +required 63 35 20 41; }; node_80(){ required 63 35 20 42; }; node_81(){ +required 63 35 20 43 22 23; }; node_82(){ optional 21; }; node_83(){ +required 63 35 20 44 82; }; node_84(){ required 63 35 20 45; }; node_85(){ +required 63 35 20 46 75; }; node_86(){ either 47 48; }; node_87(){ required 86 +}; node_88(){ optional 16; }; node_89(){ required 63 35 20 87 88; }; node_90(){ +optional 24; }; node_91(){ required 63 35 20 46 21 90; }; node_92(){ optional 17 +}; node_93(){ optional 18; }; node_94(){ oneormore 25; }; node_95(){ +required 63 35 20 49 92 93 21 94; }; node_96(){ required 63 35 20 50 21; } +node_97(){ required 26 27; }; node_98(){ either 97 14; }; node_99(){ required 98 +}; node_100(){ optional 28; }; node_101(){ required 63 35 20 51 52 99 100 71; } +node_102(){ required 63 35 20 51 53 26 27 29 71; }; node_103(){ either 26 14; } +node_104(){ required 103; }; node_105(){ required 63 35 20 51 87 104 71 88; } +node_106(){ required 63 35 20 54; }; node_107(){ optional 94; }; node_108(){ +required 63 35 20 30 107; }; node_109(){ optional 32; }; node_110(){ optional 33 +}; node_111(){ required 63 55 56 31 109 110; }; node_112(){ required 63 55 65; } +node_113(){ required 63 55 31 47; }; node_114(){ required 63 55 31 57; } +node_115(){ required 63 55 31 58 66; }; node_116(){ required 63 59; } +node_117(){ required 63 60; }; node_118(){ oneormore 34; }; node_119(){ +optional 118; }; node_120(){ required 63 61 119; }; node_121(){ required 63; } +node_122(){ +either 68 73 76 78 79 80 81 83 84 85 89 91 95 96 101 102 105 106 108 111 112 113 114 115 116 117 120 121 +}; node_123(){ required 122; }; cat <<<' docopt_exit() { [[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1394}" >&2 -exit 1; }'; unset var___verbose var___skip_update var___skip_check var___help \ -var___env var___debug var___stack var___status var___server var___domain \ -var___app_name var___pass var___secrets var___all var___update var___force \ -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 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 122 "$@" -local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__verbose" \ -"${prefix}__skip_update" "${prefix}__skip_check" "${prefix}__help" \ -"${prefix}__env" "${prefix}__debug" "${prefix}__stack" "${prefix}__status" \ -"${prefix}__server" "${prefix}__domain" "${prefix}__app_name" \ -"${prefix}__pass" "${prefix}__secrets" "${prefix}__all" "${prefix}__update" \ -"${prefix}__force" "${prefix}__no_tty" "${prefix}__user" "${prefix}_type_" \ -"${prefix}_app_" "${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" \ +exit 1; }'; unset var___branch var___skip_check var___debug var___stack \ +var___help var___skip_update var___env var___verbose var___status var___server \ +var___domain var___app_name var___pass var___secrets var___all var___update \ +var___force 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 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 123 "$@"; local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__branch" \ +"${prefix}__skip_check" "${prefix}__debug" "${prefix}__stack" \ +"${prefix}__help" "${prefix}__skip_update" "${prefix}__env" \ +"${prefix}__verbose" "${prefix}__status" "${prefix}__server" \ +"${prefix}__domain" "${prefix}__app_name" "${prefix}__pass" \ +"${prefix}__secrets" "${prefix}__all" "${prefix}__update" "${prefix}__force" \ +"${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_" \ @@ -239,14 +242,14 @@ local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__verbose" \ "${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}"'__verbose=${var___verbose:-false}' -eval "${prefix}"'__skip_update=${var___skip_update:-false}' +"${prefix}version" "${prefix}help"; eval "${prefix}"'__branch=${var___branch:-}' eval "${prefix}"'__skip_check=${var___skip_check:-false}' -eval "${prefix}"'__help=${var___help:-false}' -eval "${prefix}"'__env=${var___env:-}' eval "${prefix}"'__debug=${var___debug:-false}' 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}"'__verbose=${var___verbose:-false}' eval "${prefix}"'__status=${var___status:-false}' eval "${prefix}"'__server=${var___server:-}' eval "${prefix}"'__domain=${var___domain:-}' @@ -299,22 +302,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}__verbose" "${prefix}__skip_update" \ -"${prefix}__skip_check" "${prefix}__help" "${prefix}__env" "${prefix}__debug" \ -"${prefix}__stack" "${prefix}__status" "${prefix}__server" "${prefix}__domain" \ -"${prefix}__app_name" "${prefix}__pass" "${prefix}__secrets" "${prefix}__all" \ -"${prefix}__update" "${prefix}__force" "${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; } +declare -p "${prefix}__branch" "${prefix}__skip_check" "${prefix}__debug" \ +"${prefix}__stack" "${prefix}__help" "${prefix}__skip_update" "${prefix}__env" \ +"${prefix}__verbose" "${prefix}__status" "${prefix}__server" \ +"${prefix}__domain" "${prefix}__app_name" "${prefix}__pass" \ +"${prefix}__secrets" "${prefix}__all" "${prefix}__update" "${prefix}__force" \ +"${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; } # docopt parser above, complete command for generating this parser is `docopt.sh abra` PROGRAM_NAME=$(basename "$0") @@ -401,15 +405,16 @@ require_stack() { require_app_latest() { APP="$1" APP_DIR="$ABRA_DIR/apps/$APP" + BRANCH="${abra___branch:-master}" debug "Checking for type '$APP'" if [ ! -d "$APP_DIR" ]; then warning "The app type '$APP' was not found, fetching via Git" - if ! git clone "$GIT_URL/$APP.git" "$ABRA_DIR/apps/$APP" > /dev/null 2>&1 ; then + if ! git clone --branch "$BRANCH" "$GIT_URL/$APP.git" "$ABRA_DIR/apps/$APP" > /dev/null 2>&1 ; then error "Could not retrieve app type '$APP', this app type doesn't exist?" fi - success "Fetched app configuration via Git" + success "Fetched app configuration via Git (branch: $BRANCH)" fi debug "Using $APP_DIR" @@ -1639,7 +1644,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___update abra___branch if ! type tput > /dev/null 2>&1; then tput() {