From 0bbff9172210091cfd52e023d38422e3b8aff0a1 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Thu, 4 Mar 2021 13:10:51 +0100 Subject: [PATCH] Add service rollback Closes https://git.autonomic.zone/coop-cloud/abra/issues/76. --- abra | 171 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 98 insertions(+), 73 deletions(-) diff --git a/abra b/abra index 36a9872..31bf202 100755 --- a/abra +++ b/abra @@ -26,6 +26,7 @@ Usage: abra [options] app (rm|delete) [--force] abra [options] app restore [] abra [options] app run [--no-tty] [--user=] ... + abra [options] app rollback abra [options] app secret generate ( |--all) [] [--pass] abra [options] app secret insert [--pass] abra [options] app secret (rm|delete) (|--all) [--pass] [--force] @@ -152,15 +153,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:1811} -usage=${DOC:40:1348}; digest=4fa25 -shorts=(-v -s -C -U -h -e -d '' '' '' '' '' '' '' '' '' '' '') -longs=(--verbose --stack --skip-check --skip-update --help --env --debug --status --server --domain --app-name --pass --secrets --all --update --force --no-tty --user) -argcounts=(0 1 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1); node_0(){ switch __verbose 0; } -node_1(){ value __stack 1; }; node_2(){ switch __skip_check 2; }; node_3(){ -switch __skip_update 3; }; node_4(){ switch __help 4; }; node_5(){ value __env 5 -}; node_6(){ switch __debug 6; }; node_7(){ switch __status 7; }; node_8(){ -value __server 8; }; node_9(){ value __domain 9; }; node_10(){ +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(){ @@ -177,74 +178,75 @@ 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 secret; }; node_50(){ -_command generate; }; node_51(){ _command insert; }; node_52(){ -_command undeploy; }; node_53(){ _command server; }; node_54(){ _command add; } -node_55(){ _command init; }; node_56(){ _command apps; }; node_57(){ -_command upgrade; }; node_58(){ _command version; }; node_59(){ _command help; } -node_60(){ optional 0 1 2 3 4 5 6; }; node_61(){ optional 60; }; node_62(){ -either 35 36; }; node_63(){ required 62; }; node_64(){ optional 7; }; node_65(){ -optional 8; }; node_66(){ required 61 34 63 64 65; }; node_67(){ optional 9; } -node_68(){ optional 10; }; node_69(){ optional 11; }; node_70(){ optional 12; } -node_71(){ required 61 34 37 65 67 68 69 70 18; }; node_72(){ either 20 13; } -node_73(){ required 72; }; node_74(){ required 61 34 19 38 73; }; node_75(){ -optional 14; }; node_76(){ required 61 34 19 39 75; }; node_77(){ -required 61 34 19 40; }; node_78(){ required 61 34 19 41; }; node_79(){ -required 61 34 19 42 21 22; }; node_80(){ optional 20; }; node_81(){ -required 61 34 19 43 80; }; node_82(){ required 61 34 19 44; }; node_83(){ -required 61 34 19 45 73; }; node_84(){ either 46 47; }; node_85(){ required 84 -}; node_86(){ optional 15; }; node_87(){ required 61 34 19 85 86; }; node_88(){ -optional 23; }; node_89(){ required 61 34 19 45 20 88; }; node_90(){ optional 16 -}; node_91(){ optional 17; }; node_92(){ oneormore 24; }; node_93(){ -required 61 34 19 48 90 91 20 92; }; node_94(){ required 25 26; }; node_95(){ -either 94 13; }; node_96(){ required 95; }; node_97(){ optional 27; } -node_98(){ required 61 34 19 49 50 96 97 69; }; node_99(){ -required 61 34 19 49 51 25 26 28 69; }; node_100(){ either 25 13; }; node_101(){ -required 100; }; node_102(){ required 61 34 19 49 85 101 69 86; }; node_103(){ -required 61 34 19 52; }; node_104(){ optional 92; }; node_105(){ -required 61 34 19 29 104; }; node_106(){ optional 31; }; node_107(){ optional 32 -}; node_108(){ required 61 53 54 30 106 107; }; node_109(){ required 61 53 63; } -node_110(){ required 61 53 30 46; }; node_111(){ required 61 53 30 55; } -node_112(){ required 61 53 30 56 64; }; node_113(){ required 61 57; } -node_114(){ required 61 58; }; node_115(){ oneormore 33; }; node_116(){ -optional 115; }; node_117(){ required 61 59 116; }; node_118(){ required 61; } -node_119(){ -either 66 71 74 76 77 78 79 81 82 83 87 89 93 98 99 102 103 105 108 109 110 111 112 113 114 117 118 -}; node_120(){ required 119; }; cat <<<' docopt_exit() { -[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1348}" >&2 -exit 1; }'; unset var___verbose var___stack var___skip_check var___skip_update \ -var___help var___env var___debug var___status var___server var___domain \ +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() { +[[ -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_secret var_generate \ -var_insert var_undeploy var_server var_add var_init var_apps var_upgrade \ -var_version var_help; parse 120 "$@"; local prefix=${DOCOPT_PREFIX:-''} -unset "${prefix}__verbose" "${prefix}__stack" "${prefix}__skip_check" \ -"${prefix}__skip_update" "${prefix}__help" "${prefix}__env" "${prefix}__debug" \ -"${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}secret" "${prefix}generate" "${prefix}insert" "${prefix}undeploy" \ -"${prefix}server" "${prefix}add" "${prefix}init" "${prefix}apps" \ -"${prefix}upgrade" "${prefix}version" "${prefix}help" +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_" \ +"${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}"'__verbose=${var___verbose:-false}' -eval "${prefix}"'__stack=${var___stack:-}' -eval "${prefix}"'__skip_check=${var___skip_check:-false}' eval "${prefix}"'__skip_update=${var___skip_update:-false}' +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}"'__status=${var___status:-false}' eval "${prefix}"'__server=${var___server:-}' eval "${prefix}"'__domain=${var___domain:-}' @@ -284,6 +286,7 @@ eval "${prefix}"'restore=${var_restore:-false}' eval "${prefix}"'rm=${var_rm:-false}' eval "${prefix}"'delete=${var_delete:-false}' eval "${prefix}"'run=${var_run:-false}' +eval "${prefix}"'rollback=${var_rollback:-false}' eval "${prefix}"'secret=${var_secret:-false}' eval "${prefix}"'generate=${var_generate:-false}' eval "${prefix}"'insert=${var_insert:-false}' @@ -296,9 +299,9 @@ 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}__stack" "${prefix}__skip_check" \ -"${prefix}__skip_update" "${prefix}__help" "${prefix}__env" "${prefix}__debug" \ -"${prefix}__status" "${prefix}__server" "${prefix}__domain" \ +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_" \ @@ -309,9 +312,9 @@ declare -p "${prefix}__verbose" "${prefix}__stack" "${prefix}__skip_check" \ "${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}secret" "${prefix}generate" "${prefix}insert" "${prefix}undeploy" \ -"${prefix}server" "${prefix}add" "${prefix}init" "${prefix}apps" \ -"${prefix}upgrade" "${prefix}version" "${prefix}help"; done; } +"${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") @@ -1294,6 +1297,28 @@ sub_app_run(){ return } +###### .. app rollback +help_app_rollback (){ + echo "abra [options] app rollback + +Rollback a deployed app service to a previous version. + +EXAMPLES + abra app wordpress rollback app + +POWERED BY + docker service rollback \$CONTAINER_ID ..." +} + +sub_app_rollback(){ + load_instance + load_instance_env + + SERVICE="${abra__service_}" + + docker service rollback "${STACK_NAME}_${SERVICE}" +} + ###### .. app logs help_app_logs (){ echo "abra [options] app logs []