Add app ... ps command, and some comments

This commit is contained in:
3wc 2020-11-16 17:27:50 +02:00
parent 89d530a553
commit 946a527baa

125
abra
View File

@ -21,9 +21,10 @@ Usage:
abra [options] app <domain> multilogs
abra [options] app <domain> cp <src> <dst>
abra [options] app <domain> check
abra [options] app <domain> ps
abra [options] app <domain> run [--user=<user>] <service> <args>...
abra [options] app <domain> run <service> <args>...
abra [options] app <domain> secret auto
abra [options] app <domain> secret auto [--pass]
abra [options] app <domain> secret generate <secret> <version> [<cmd>] [--pass]
abra [options] app <domain> secret insert <secret> <version> <data> [--pass]
abra [options] app <domain> secret (delete|rm) (<secret>|--all) [--pass] [--force]
@ -142,11 +143,11 @@ 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:1407}
usage=${DOC:40:1099}; digest=53ae1; shorts=(-s -e -h -v '' '' '' '' '' '' '' '')
longs=(--stack --env --help --version --server --domain --pass --auto --status --force --user --all)
argcounts=(1 1 0 0 1 1 0 0 0 0 1 0); node_0(){ value __stack 0; }; node_1(){
value __env 1; }; node_2(){ switch __help 2; }; node_3(){ switch __version 3; }
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1449}
usage=${DOC:40:1141}; digest=2bcee; shorts=(-s -h -e -v '' '' '' '' '' '' '' '')
longs=(--stack --help --env --version --server --domain --pass --auto --status --force --user --all)
argcounts=(1 0 1 0 1 1 0 0 0 0 1 0); node_0(){ value __stack 0; }; node_1(){
switch __help 1; }; node_2(){ value __env 2; }; node_3(){ switch __version 3; }
node_4(){ value __server 4; }; node_5(){ value __domain 5; }; node_6(){
switch __pass 6; }; node_7(){ switch __auto 7; }; node_8(){ switch __status 8; }
node_9(){ switch __force 9; }; node_10(){ value __user 10; }; node_11(){
@ -160,55 +161,57 @@ _command new; }; node_27(){ _command list; }; node_28(){ _command ls; }
node_29(){ _command deploy; }; node_30(){ _command undeploy; }; node_31(){
_command config; }; node_32(){ _command delete; }; node_33(){ _command rm; }
node_34(){ _command logs; }; node_35(){ _command multilogs; }; node_36(){
_command cp; }; node_37(){ _command check; }; node_38(){ _command run; }
node_39(){ _command secret; }; node_40(){ _command auto; }; node_41(){
_command generate; }; node_42(){ _command insert; }; node_43(){ _command server
}; node_44(){ _command add; }; node_45(){ _command use; }; node_46(){
_command init; }; node_47(){ _command upgrade; }; node_48(){ optional 0 1 2 3; }
node_49(){ optional 48; }; node_50(){ optional 4; }; node_51(){ optional 5; }
node_52(){ optional 6; }; node_53(){ optional 7; }; node_54(){
required 49 25 26 50 51 52 53 12; }; node_55(){ either 27 28; }; node_56(){
required 55; }; node_57(){ optional 8; }; node_58(){ required 49 25 56 57; }
node_59(){ required 49 25 13 29; }; node_60(){ required 49 25 13 30; }
node_61(){ required 49 25 13 31; }; node_62(){ either 32 33; }; node_63(){
required 62; }; node_64(){ optional 9; }; node_65(){ required 49 25 13 63 64; }
node_66(){ optional 14; }; node_67(){ required 49 25 13 34 66; }; node_68(){
required 49 25 13 35; }; node_69(){ required 49 25 13 36 15 16; }; node_70(){
required 49 25 13 37; }; node_71(){ optional 10; }; node_72(){ oneormore 17; }
node_73(){ required 49 25 13 38 71 14 72; }; node_74(){
required 49 25 13 38 14 72; }; node_75(){ required 49 25 13 39 40; }; node_76(){
optional 20; }; node_77(){ required 49 25 13 39 41 18 19 76 52; }; node_78(){
required 49 25 13 39 42 18 19 21 52; }; node_79(){ either 18 11; }; node_80(){
required 79; }; node_81(){ required 49 25 13 39 63 80 52 64; }; node_82(){
optional 23; }; node_83(){ optional 24; }; node_84(){ required 49 43 44 22 82 83
}; node_85(){ required 49 43 56; }; node_86(){ required 49 43 33 22; }
node_87(){ required 49 43 45 22; }; node_88(){ required 49 43 46 22; }
node_89(){ required 49 47; }; node_90(){
either 54 58 59 60 61 65 67 68 69 70 73 74 75 77 78 81 84 85 86 87 88 89; }
node_91(){ required 90; }; cat <<<' docopt_exit() {
[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1099}" >&2
exit 1; }'; unset var___stack var___env var___help var___version var___server \
_command cp; }; node_37(){ _command check; }; node_38(){ _command ps; }
node_39(){ _command run; }; node_40(){ _command secret; }; node_41(){
_command auto; }; node_42(){ _command generate; }; node_43(){ _command insert; }
node_44(){ _command server; }; node_45(){ _command add; }; node_46(){
_command use; }; node_47(){ _command init; }; node_48(){ _command upgrade; }
node_49(){ optional 0 1 2 3; }; node_50(){ optional 49; }; node_51(){ optional 4
}; node_52(){ optional 5; }; node_53(){ optional 6; }; node_54(){ optional 7; }
node_55(){ required 50 25 26 51 52 53 54 12; }; node_56(){ either 27 28; }
node_57(){ required 56; }; node_58(){ optional 8; }; node_59(){
required 50 25 57 58; }; node_60(){ required 50 25 13 29; }; node_61(){
required 50 25 13 30; }; node_62(){ required 50 25 13 31; }; node_63(){
either 32 33; }; node_64(){ required 63; }; node_65(){ optional 9; }; node_66(){
required 50 25 13 64 65; }; node_67(){ optional 14; }; node_68(){
required 50 25 13 34 67; }; node_69(){ required 50 25 13 35; }; node_70(){
required 50 25 13 36 15 16; }; node_71(){ required 50 25 13 37; }; node_72(){
required 50 25 13 38; }; node_73(){ optional 10; }; node_74(){ oneormore 17; }
node_75(){ required 50 25 13 39 73 14 74; }; node_76(){
required 50 25 13 39 14 74; }; node_77(){ required 50 25 13 40 41 53; }
node_78(){ optional 20; }; node_79(){ required 50 25 13 40 42 18 19 78 53; }
node_80(){ required 50 25 13 40 43 18 19 21 53; }; node_81(){ either 18 11; }
node_82(){ required 81; }; node_83(){ required 50 25 13 40 64 82 53 65; }
node_84(){ optional 23; }; node_85(){ optional 24; }; node_86(){
required 50 44 45 22 84 85; }; node_87(){ required 50 44 57; }; node_88(){
required 50 44 33 22; }; node_89(){ required 50 44 46 22; }; node_90(){
required 50 44 47 22; }; node_91(){ required 50 48; }; node_92(){
either 55 59 60 61 62 66 68 69 70 71 72 75 76 77 79 80 83 86 87 88 89 90 91; }
node_93(){ required 92; }; cat <<<' docopt_exit() {
[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:1141}" >&2
exit 1; }'; unset var___stack var___help var___env var___version var___server \
var___domain var___pass var___auto var___status var___force var___user \
var___all var__app_ var__domain_ var__service_ var__src_ var__dst_ var__args_ \
var__secret_ var__version_ var__cmd_ var__data_ var__host_ var__user_ \
var__port_ var_app var_new var_list var_ls var_deploy var_undeploy var_config \
var_delete var_rm var_logs var_multilogs var_cp var_check var_run var_secret \
var_auto var_generate var_insert var_server var_add var_use var_init var_upgrade
parse 91 "$@"; local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__stack" \
"${prefix}__env" "${prefix}__help" "${prefix}__version" "${prefix}__server" \
"${prefix}__domain" "${prefix}__pass" "${prefix}__auto" "${prefix}__status" \
"${prefix}__force" "${prefix}__user" "${prefix}__all" "${prefix}_app_" \
"${prefix}_domain_" "${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" \
"${prefix}_args_" "${prefix}_secret_" "${prefix}_version_" "${prefix}_cmd_" \
"${prefix}_data_" "${prefix}_host_" "${prefix}_user_" "${prefix}_port_" \
"${prefix}app" "${prefix}new" "${prefix}list" "${prefix}ls" "${prefix}deploy" \
"${prefix}undeploy" "${prefix}config" "${prefix}delete" "${prefix}rm" \
"${prefix}logs" "${prefix}multilogs" "${prefix}cp" "${prefix}check" \
var_delete var_rm var_logs var_multilogs var_cp var_check var_ps var_run \
var_secret var_auto var_generate var_insert var_server var_add var_use \
var_init var_upgrade; parse 93 "$@"; local prefix=${DOCOPT_PREFIX:-''}
unset "${prefix}__stack" "${prefix}__help" "${prefix}__env" \
"${prefix}__version" "${prefix}__server" "${prefix}__domain" "${prefix}__pass" \
"${prefix}__auto" "${prefix}__status" "${prefix}__force" "${prefix}__user" \
"${prefix}__all" "${prefix}_app_" "${prefix}_domain_" "${prefix}_service_" \
"${prefix}_src_" "${prefix}_dst_" "${prefix}_args_" "${prefix}_secret_" \
"${prefix}_version_" "${prefix}_cmd_" "${prefix}_data_" "${prefix}_host_" \
"${prefix}_user_" "${prefix}_port_" "${prefix}app" "${prefix}new" \
"${prefix}list" "${prefix}ls" "${prefix}deploy" "${prefix}undeploy" \
"${prefix}config" "${prefix}delete" "${prefix}rm" "${prefix}logs" \
"${prefix}multilogs" "${prefix}cp" "${prefix}check" "${prefix}ps" \
"${prefix}run" "${prefix}secret" "${prefix}auto" "${prefix}generate" \
"${prefix}insert" "${prefix}server" "${prefix}add" "${prefix}use" \
"${prefix}init" "${prefix}upgrade"; eval "${prefix}"'__stack=${var___stack:-}'
eval "${prefix}"'__env=${var___env:-}'
eval "${prefix}"'__help=${var___help:-false}'
eval "${prefix}"'__env=${var___env:-}'
eval "${prefix}"'__version=${var___version:-false}'
eval "${prefix}"'__server=${var___server:-}'
eval "${prefix}"'__domain=${var___domain:-}'
@ -240,7 +243,7 @@ eval "${prefix}"'rm=${var_rm:-false}'; eval "${prefix}"'logs=${var_logs:-false}'
eval "${prefix}"'multilogs=${var_multilogs:-false}'
eval "${prefix}"'cp=${var_cp:-false}'
eval "${prefix}"'check=${var_check:-false}'
eval "${prefix}"'run=${var_run:-false}'
eval "${prefix}"'ps=${var_ps:-false}'; eval "${prefix}"'run=${var_run:-false}'
eval "${prefix}"'secret=${var_secret:-false}'
eval "${prefix}"'auto=${var_auto:-false}'
eval "${prefix}"'generate=${var_generate:-false}'
@ -250,7 +253,7 @@ eval "${prefix}"'add=${var_add:-false}'; eval "${prefix}"'use=${var_use:-false}'
eval "${prefix}"'init=${var_init:-false}'
eval "${prefix}"'upgrade=${var_upgrade:-false}'; local docopt_i=1
[[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do
declare -p "${prefix}__stack" "${prefix}__env" "${prefix}__help" \
declare -p "${prefix}__stack" "${prefix}__help" "${prefix}__env" \
"${prefix}__version" "${prefix}__server" "${prefix}__domain" "${prefix}__pass" \
"${prefix}__auto" "${prefix}__status" "${prefix}__force" "${prefix}__user" \
"${prefix}__all" "${prefix}_app_" "${prefix}_domain_" "${prefix}_service_" \
@ -259,10 +262,10 @@ declare -p "${prefix}__stack" "${prefix}__env" "${prefix}__help" \
"${prefix}_user_" "${prefix}_port_" "${prefix}app" "${prefix}new" \
"${prefix}list" "${prefix}ls" "${prefix}deploy" "${prefix}undeploy" \
"${prefix}config" "${prefix}delete" "${prefix}rm" "${prefix}logs" \
"${prefix}multilogs" "${prefix}cp" "${prefix}check" "${prefix}run" \
"${prefix}secret" "${prefix}auto" "${prefix}generate" "${prefix}insert" \
"${prefix}server" "${prefix}add" "${prefix}use" "${prefix}init" \
"${prefix}upgrade"; done; }
"${prefix}multilogs" "${prefix}cp" "${prefix}check" "${prefix}ps" \
"${prefix}run" "${prefix}secret" "${prefix}auto" "${prefix}generate" \
"${prefix}insert" "${prefix}server" "${prefix}add" "${prefix}use" \
"${prefix}init" "${prefix}upgrade"; done; }
# docopt parser above, complete command for generating this parser is `docopt.sh abra`
PROGRAM_NAME=$(basename "$0")
@ -624,6 +627,7 @@ sub_app_check (){
APP_ENV=$(grep -v '^#' "$ENV_FILE" | sed 's/^.* \([^=]\+\)=.*/\1/' | sort)
STACK_ENV=$(grep -v '^#' "$APP_DIR/.envrc.sample" | sed 's/^.* \([^=]\+\)=.*/\1/' | sort)
# Only show "1", items in STACK_ENV which aren't in APP_ENV
MISSING_VARS=$(comm -23 <(echo "$STACK_ENV") <(echo "$APP_ENV"))
if [ -z "$MISSING_VARS" ]; then
@ -634,6 +638,14 @@ sub_app_check (){
error "Found missing variables: $MISSING_VARS"
}
###### .. app ps
sub_app_ps (){
load_instance
load_instance_env
docker stack ps "$STACK_NAME"
}
###### .. app <domain> delete
sub_app_rm (){
sub_app_delete
@ -730,7 +742,7 @@ sub_app_secret_generate(){
success "Password: $PW"
# FIXME 3wc: this is a little janky, might be better to make a
# TODO 3wc: this is a little janky, might be better to make a
# util_secret_insert function which this and sub_secret_insert can call
abra__data_="$PW"
@ -769,6 +781,8 @@ sub_app_run(){
exit
fi
# 3wc: we want the "splitting" that shellcheck warns us about, so that -u and
# $RUN_USER aren't treated as a single argument:
# shellcheck disable=SC2086
docker exec $RUN_USER -it "$CONTAINER" "$@"
@ -834,6 +848,7 @@ sub_app_cp() {
SOURCE="${abra__src_}"
DEST="${abra__dst_}"
# Get the service name from either SOURCE or DEST
SERVICE=$(echo "$SOURCE" | grep -o '^[^:]\+:' || echo "$DEST" | grep -o '^[^:]\+:')
SERVICE=$(echo "$SERVICE" | tr -d ':')
@ -852,7 +867,9 @@ sub_app_cp() {
exit
fi
# Replace $SERVICE with $CONTAINER in the original args
CP_ARGS=$(echo "$SOURCE $DEST" | sed "s/$SERVICE:/$CONTAINER:/")
# FIXME 3wc: this might cause problems for filenames with spaces..
# shellcheck disable=SC2086
docker cp ${CP_ARGS}