Local server list, more tidying
This commit is contained in:
parent
c5785089d6
commit
b1e8ac4498
148
abra
148
abra
@ -22,10 +22,10 @@ Usage:
|
|||||||
abra [options] app <domain> secret generate <secret> <version> [<cmd>]
|
abra [options] app <domain> secret generate <secret> <version> [<cmd>]
|
||||||
abra [options] app <domain> secret insert <secret> <version> <data>
|
abra [options] app <domain> secret insert <secret> <version> <data>
|
||||||
abra [options] server add <host> [<user>] [<port>]
|
abra [options] server add <host> [<user>] [<port>]
|
||||||
|
abra [options] server (list|ls)
|
||||||
abra [options] server rm <host>
|
abra [options] server rm <host>
|
||||||
abra [options] server use <host>
|
abra [options] server use <host>
|
||||||
abra [options] server init <host>
|
abra [options] server init <host>
|
||||||
abra [options] server ls
|
|
||||||
abra [options] upgrade
|
abra [options] upgrade
|
||||||
abra [options] <command> <args>...
|
abra [options] <command> <args>...
|
||||||
|
|
||||||
@ -137,60 +137,62 @@ 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() {
|
return 1; }; stdout() { printf -- "cat <<'EOM'\n%s\nEOM\n" "$1"; }; stderr() {
|
||||||
printf -- "cat <<'EOM' >&2\n%s\nEOM\n" "$1"; }; error() {
|
printf -- "cat <<'EOM' >&2\n%s\nEOM\n" "$1"; }; error() {
|
||||||
[[ -n $1 ]] && stderr "$1"; stderr "$usage"; _return 1; }; _return() {
|
[[ -n $1 ]] && stderr "$1"; stderr "$usage"; _return 1; }; _return() {
|
||||||
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1097}
|
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1104}
|
||||||
usage=${DOC:40:789}; digest=9b786; shorts=(-e -h -s -v '' '' '')
|
usage=${DOC:40:796}; digest=0e48b; shorts=(-v -e -h -s '' '' '')
|
||||||
longs=(--env --help --stack --version --server --domain --user)
|
longs=(--version --env --help --stack --server --domain --user)
|
||||||
argcounts=(1 0 1 0 1 1 1); node_0(){ value __env 0; }; node_1(){ switch __help 1
|
argcounts=(0 1 0 1 1 1 1); node_0(){ switch __version 0; }; node_1(){
|
||||||
}; node_2(){ value __stack 2; }; node_3(){ switch __version 3; }; node_4(){
|
value __env 1; }; node_2(){ switch __help 2; }; node_3(){ value __stack 3; }
|
||||||
value __server 4; }; node_5(){ value __domain 5; }; node_6(){ value __user 6; }
|
node_4(){ value __server 4; }; node_5(){ value __domain 5; }; node_6(){
|
||||||
node_7(){ value _app_ a; }; node_8(){ value _domain_ a; }; node_9(){
|
value __user 6; }; node_7(){ value _app_ a; }; node_8(){ value _domain_ a; }
|
||||||
value _service_ a; }; node_10(){ value _src_ a; }; node_11(){ value _dst_ a; }
|
node_9(){ value _service_ a; }; node_10(){ value _src_ a; }; node_11(){
|
||||||
node_12(){ value _args_ a true; }; node_13(){ value _secret_ a; }; node_14(){
|
value _dst_ a; }; node_12(){ value _args_ a true; }; node_13(){ value _secret_ a
|
||||||
value _version_ a; }; node_15(){ value _cmd_ a; }; node_16(){ value _data_ a; }
|
}; node_14(){ value _version_ a; }; node_15(){ value _cmd_ a; }; node_16(){
|
||||||
node_17(){ value _host_ a; }; node_18(){ value _user_ a; }; node_19(){
|
value _data_ a; }; node_17(){ value _host_ a; }; node_18(){ value _user_ a; }
|
||||||
value _port_ a; }; node_20(){ value _command_ a; }; node_21(){ _command app; }
|
node_19(){ value _port_ a; }; node_20(){ value _command_ a; }; node_21(){
|
||||||
node_22(){ _command new; }; node_23(){ _command list; }; node_24(){ _command ls
|
_command app; }; node_22(){ _command new; }; node_23(){ _command list; }
|
||||||
}; node_25(){ _command deploy; }; node_26(){ _command logs; }; node_27(){
|
node_24(){ _command ls; }; node_25(){ _command deploy; }; node_26(){
|
||||||
_command multilogs; }; node_28(){ _command cp; }; node_29(){ _command run; }
|
_command logs; }; node_27(){ _command multilogs; }; node_28(){ _command cp; }
|
||||||
node_30(){ _command secret; }; node_31(){ _command generate; }; node_32(){
|
node_29(){ _command run; }; node_30(){ _command secret; }; node_31(){
|
||||||
_command insert; }; node_33(){ _command server; }; node_34(){ _command add; }
|
_command generate; }; node_32(){ _command insert; }; node_33(){ _command server
|
||||||
node_35(){ _command rm; }; node_36(){ _command use; }; node_37(){ _command init
|
}; node_34(){ _command add; }; node_35(){ _command rm; }; node_36(){
|
||||||
}; node_38(){ _command upgrade; }; node_39(){ optional 0 1 2 3; }; node_40(){
|
_command use; }; node_37(){ _command init; }; node_38(){ _command upgrade; }
|
||||||
optional 39; }; node_41(){ optional 4 5; }; node_42(){ required 40 21 22 41 7; }
|
node_39(){ optional 0 1 2 3; }; node_40(){ optional 39; }; node_41(){
|
||||||
node_43(){ either 23 24; }; node_44(){ required 43; }; node_45(){
|
optional 4 5; }; node_42(){ required 40 21 22 41 7; }; node_43(){ either 23 24
|
||||||
required 40 21 44; }; node_46(){ required 40 21 8 25; }; node_47(){ optional 9
|
}; node_44(){ required 43; }; node_45(){ required 40 21 44; }; node_46(){
|
||||||
}; node_48(){ required 40 21 8 26 47; }; node_49(){ required 40 21 8 27; }
|
required 40 21 8 25; }; node_47(){ optional 9; }; node_48(){
|
||||||
node_50(){ required 40 21 8 28 10 11; }; node_51(){ optional 6; }; node_52(){
|
required 40 21 8 26 47; }; node_49(){ required 40 21 8 27; }; node_50(){
|
||||||
oneormore 12; }; node_53(){ required 40 21 8 29 51 9 52; }; node_54(){
|
required 40 21 8 28 10 11; }; node_51(){ optional 6; }; node_52(){ oneormore 12
|
||||||
|
}; node_53(){ required 40 21 8 29 51 9 52; }; node_54(){
|
||||||
required 40 21 8 29 9 52; }; node_55(){ optional 15; }; node_56(){
|
required 40 21 8 29 9 52; }; node_55(){ optional 15; }; node_56(){
|
||||||
required 40 21 8 30 31 13 14 55; }; node_57(){ required 40 21 8 30 32 13 14 16
|
required 40 21 8 30 31 13 14 55; }; node_57(){ required 40 21 8 30 32 13 14 16
|
||||||
}; node_58(){ optional 18; }; node_59(){ optional 19; }; node_60(){
|
}; node_58(){ optional 18; }; node_59(){ optional 19; }; node_60(){
|
||||||
required 40 33 34 17 58 59; }; node_61(){ required 40 33 35 17; }; node_62(){
|
required 40 33 34 17 58 59; }; node_61(){ required 40 33 44; }; node_62(){
|
||||||
required 40 33 36 17; }; node_63(){ required 40 33 37 17; }; node_64(){
|
required 40 33 35 17; }; node_63(){ required 40 33 36 17; }; node_64(){
|
||||||
required 40 33 24; }; node_65(){ required 40 38; }; node_66(){ required 40 20 52
|
required 40 33 37 17; }; node_65(){ required 40 38; }; node_66(){
|
||||||
}; node_67(){ either 42 45 46 48 49 50 53 54 56 57 60 61 62 63 64 65 66; }
|
required 40 20 52; }; node_67(){
|
||||||
node_68(){ required 67; }; cat <<<' docopt_exit() {
|
either 42 45 46 48 49 50 53 54 56 57 60 61 62 63 64 65 66; }; node_68(){
|
||||||
[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:789}" >&2; exit 1
|
required 67; }; cat <<<' docopt_exit() { [[ -n $1 ]] && printf "%s\n" "$1" >&2
|
||||||
}'; unset var___env var___help var___stack var___version var___server \
|
printf "%s\n" "${DOC:40:796}" >&2; exit 1; }'; unset var___version var___env \
|
||||||
var___domain var___user var__app_ var__domain_ var__service_ var__src_ \
|
var___help var___stack var___server var___domain var___user var__app_ \
|
||||||
var__dst_ var__args_ var__secret_ var__version_ var__cmd_ var__data_ \
|
var__domain_ var__service_ var__src_ var__dst_ var__args_ var__secret_ \
|
||||||
var__host_ var__user_ var__port_ var__command_ var_app var_new var_list var_ls \
|
var__version_ var__cmd_ var__data_ var__host_ var__user_ var__port_ \
|
||||||
var_deploy var_logs var_multilogs var_cp var_run var_secret var_generate \
|
var__command_ var_app var_new var_list var_ls var_deploy var_logs \
|
||||||
var_insert var_server var_add var_rm var_use var_init var_upgrade; parse 68 "$@"
|
var_multilogs var_cp var_run var_secret var_generate var_insert var_server \
|
||||||
local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__env" "${prefix}__help" \
|
var_add var_rm var_use var_init var_upgrade; parse 68 "$@"
|
||||||
"${prefix}__stack" "${prefix}__version" "${prefix}__server" \
|
local prefix=${DOCOPT_PREFIX:-''}; unset "${prefix}__version" "${prefix}__env" \
|
||||||
"${prefix}__domain" "${prefix}__user" "${prefix}_app_" "${prefix}_domain_" \
|
"${prefix}__help" "${prefix}__stack" "${prefix}__server" "${prefix}__domain" \
|
||||||
"${prefix}_service_" "${prefix}_src_" "${prefix}_dst_" "${prefix}_args_" \
|
"${prefix}__user" "${prefix}_app_" "${prefix}_domain_" "${prefix}_service_" \
|
||||||
"${prefix}_secret_" "${prefix}_version_" "${prefix}_cmd_" "${prefix}_data_" \
|
"${prefix}_src_" "${prefix}_dst_" "${prefix}_args_" "${prefix}_secret_" \
|
||||||
"${prefix}_host_" "${prefix}_user_" "${prefix}_port_" "${prefix}_command_" \
|
"${prefix}_version_" "${prefix}_cmd_" "${prefix}_data_" "${prefix}_host_" \
|
||||||
"${prefix}app" "${prefix}new" "${prefix}list" "${prefix}ls" "${prefix}deploy" \
|
"${prefix}_user_" "${prefix}_port_" "${prefix}_command_" "${prefix}app" \
|
||||||
"${prefix}logs" "${prefix}multilogs" "${prefix}cp" "${prefix}run" \
|
"${prefix}new" "${prefix}list" "${prefix}ls" "${prefix}deploy" "${prefix}logs" \
|
||||||
"${prefix}secret" "${prefix}generate" "${prefix}insert" "${prefix}server" \
|
"${prefix}multilogs" "${prefix}cp" "${prefix}run" "${prefix}secret" \
|
||||||
"${prefix}add" "${prefix}rm" "${prefix}use" "${prefix}init" "${prefix}upgrade"
|
"${prefix}generate" "${prefix}insert" "${prefix}server" "${prefix}add" \
|
||||||
|
"${prefix}rm" "${prefix}use" "${prefix}init" "${prefix}upgrade"
|
||||||
|
eval "${prefix}"'__version=${var___version:-false}'
|
||||||
eval "${prefix}"'__env=${var___env:-}'
|
eval "${prefix}"'__env=${var___env:-}'
|
||||||
eval "${prefix}"'__help=${var___help:-false}'
|
eval "${prefix}"'__help=${var___help:-false}'
|
||||||
eval "${prefix}"'__stack=${var___stack:-}'
|
eval "${prefix}"'__stack=${var___stack:-}'
|
||||||
eval "${prefix}"'__version=${var___version:-false}'
|
|
||||||
eval "${prefix}"'__server=${var___server:-}'
|
eval "${prefix}"'__server=${var___server:-}'
|
||||||
eval "${prefix}"'__domain=${var___domain:-}'
|
eval "${prefix}"'__domain=${var___domain:-}'
|
||||||
eval "${prefix}"'__user=${var___user:-}'; eval "${prefix}"'_app_=${var__app_:-}'
|
eval "${prefix}"'__user=${var___user:-}'; eval "${prefix}"'_app_=${var__app_:-}'
|
||||||
@ -221,8 +223,8 @@ eval "${prefix}"'use=${var_use:-false}'
|
|||||||
eval "${prefix}"'init=${var_init:-false}'
|
eval "${prefix}"'init=${var_init:-false}'
|
||||||
eval "${prefix}"'upgrade=${var_upgrade:-false}'; local docopt_i=1
|
eval "${prefix}"'upgrade=${var_upgrade:-false}'; local docopt_i=1
|
||||||
[[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do
|
[[ $BASH_VERSION =~ ^4.3 ]] && docopt_i=2; for ((;docopt_i>0;docopt_i--)); do
|
||||||
declare -p "${prefix}__env" "${prefix}__help" "${prefix}__stack" \
|
declare -p "${prefix}__version" "${prefix}__env" "${prefix}__help" \
|
||||||
"${prefix}__version" "${prefix}__server" "${prefix}__domain" "${prefix}__user" \
|
"${prefix}__stack" "${prefix}__server" "${prefix}__domain" "${prefix}__user" \
|
||||||
"${prefix}_app_" "${prefix}_domain_" "${prefix}_service_" "${prefix}_src_" \
|
"${prefix}_app_" "${prefix}_domain_" "${prefix}_service_" "${prefix}_src_" \
|
||||||
"${prefix}_dst_" "${prefix}_args_" "${prefix}_secret_" "${prefix}_version_" \
|
"${prefix}_dst_" "${prefix}_args_" "${prefix}_secret_" "${prefix}_version_" \
|
||||||
"${prefix}_cmd_" "${prefix}_data_" "${prefix}_host_" "${prefix}_user_" \
|
"${prefix}_cmd_" "${prefix}_data_" "${prefix}_host_" "${prefix}_user_" \
|
||||||
@ -260,10 +262,6 @@ if [ -z "$COMPOSE_FILE" ]; then
|
|||||||
COMPOSE_FILE="compose.yml"
|
COMPOSE_FILE="compose.yml"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$ABRA_STACK_DIR" ]; then
|
|
||||||
ABRA_STACK_DIR="stacks/$SERVICE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
###### Safety checks
|
###### Safety checks
|
||||||
|
|
||||||
require_multitail() {
|
require_multitail() {
|
||||||
@ -282,13 +280,6 @@ require_stack() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
require_stack_dir() {
|
|
||||||
# FIXME 3wc: replace with APP_DIR
|
|
||||||
if [ -z "$ABRA_STACK_DIR" ] || [ ! -d "$ABRA_STACK_DIR" ]; then
|
|
||||||
error "can't find \$ABRA_STACK_DIR '$ABRA_STACK_DIR'"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# FIXME 3wc: update or remove
|
# FIXME 3wc: update or remove
|
||||||
if [ -z "$ABRA_ENV" ] && [ -f .envrc ] && type direnv > /dev/null 2>&1 && ! direnv status | grep -q 'Found RC allowed true'; then
|
if [ -z "$ABRA_ENV" ] && [ -f .envrc ] && type direnv > /dev/null 2>&1 && ! direnv status | grep -q 'Found RC allowed true'; then
|
||||||
error "direnv is blocked, run direnv allow"
|
error "direnv is blocked, run direnv allow"
|
||||||
@ -302,12 +293,20 @@ load_custom_commands() {
|
|||||||
source abra-commands.sh
|
source abra-commands.sh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "$ABRA_STACK_DIR/abra-commands.sh" ]; then
|
if [ -f "$APP_DIR/abra-commands.sh" ]; then
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$ABRA_STACK_DIR/abra-commands.sh"
|
source "$APP_DIR/abra-commands.sh"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
###### FIXME 3wc: name this section
|
||||||
|
|
||||||
|
get_servers() {
|
||||||
|
shopt -s nullglob dotglob
|
||||||
|
SERVERS=(~/.abra/servers/*)
|
||||||
|
shopt -u nullglob dotglob
|
||||||
|
}
|
||||||
|
|
||||||
load_instance() {
|
load_instance() {
|
||||||
DOMAIN="$abra__domain_"
|
DOMAIN="$abra__domain_"
|
||||||
ENV_FILE=$(find ~/.abra -name "$DOMAIN.env")
|
ENV_FILE=$(find ~/.abra -name "$DOMAIN.env")
|
||||||
@ -357,14 +356,12 @@ sub_app_list (){
|
|||||||
printf "%s lovely apps:\n\n" "${#ENV_FILES[@]}"
|
printf "%s lovely apps:\n\n" "${#ENV_FILES[@]}"
|
||||||
|
|
||||||
for i in "${!ENV_FILES[@]}"; do
|
for i in "${!ENV_FILES[@]}"; do
|
||||||
local PARTS
|
|
||||||
|
|
||||||
# Do this inside the loop to include in pipe to `column`
|
# Do this inside the loop to include in pipe to `column`
|
||||||
if [ "$i" == 0 ]; then
|
if [ "$i" == 0 ]; then
|
||||||
printf " DOMAIN\tAPP\tSERVER\n --\t--\t--\n"
|
printf " DOMAIN\tAPP\tSERVER\n --\t--\t--\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ENV_FILE="${ENV_FILES[$i]}"
|
local ENV_FILE="${ENV_FILES[$i]}"
|
||||||
|
|
||||||
IFS='/' read -r -a PARTS <<< "$ENV_FILE"
|
IFS='/' read -r -a PARTS <<< "$ENV_FILE"
|
||||||
|
|
||||||
@ -375,22 +372,19 @@ sub_app_list (){
|
|||||||
APP="$(source "$ENV_FILE" && echo "$APP")"
|
APP="$(source "$ENV_FILE" && echo "$APP")"
|
||||||
printf " %s\t%s\t%s\n" "$DOMAIN" "$APP" "$SERVER"
|
printf " %s\t%s\t%s\n" "$DOMAIN" "$APP" "$SERVER"
|
||||||
done | column -s' ' -t
|
done | column -s' ' -t
|
||||||
# Align table `-t` based on tab characters -s`^V<Tab>`
|
# Align table `-t` based on tab characters -s`^V<Tab>`
|
||||||
}
|
}
|
||||||
|
|
||||||
###### .. app new [--domain=<domain> --server=<server>]
|
###### .. app new [--domain=<domain> --server=<server>]
|
||||||
sub_app_new (){
|
sub_app_new (){
|
||||||
require_abra_dir
|
require_abra_dir
|
||||||
|
get_servers
|
||||||
|
|
||||||
APP=$abra__app_
|
APP=$abra__app_
|
||||||
SERVER=$abra___server
|
SERVER=$abra___server
|
||||||
DOMAIN=$abra___domain
|
DOMAIN=$abra___domain
|
||||||
|
|
||||||
if [ -z "$SERVER" ]; then
|
if [ -z "$SERVER" ]; then
|
||||||
shopt -s nullglob dotglob
|
|
||||||
SERVERS=(~/.abra/servers/*)
|
|
||||||
shopt -u nullglob dotglob
|
|
||||||
|
|
||||||
echo "Where would you like to put $APP?"
|
echo "Where would you like to put $APP?"
|
||||||
|
|
||||||
echo -n "$(tput setaf 4)"
|
echo -n "$(tput setaf 4)"
|
||||||
@ -677,7 +671,15 @@ sub_server_use() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub_server_ls() {
|
sub_server_ls() {
|
||||||
docker context ls
|
sub_server_list
|
||||||
|
}
|
||||||
|
|
||||||
|
sub_server_list() {
|
||||||
|
get_servers
|
||||||
|
printf "%s servers:\n\n" "${#SERVERS[@]}"
|
||||||
|
for SERVER in "${SERVERS[@]}"; do
|
||||||
|
echo " ${SERVER##*/}"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
|
Loading…
Reference in New Issue
Block a user