Add config command
This commit is contained in:
parent
6e38dc35e5
commit
85b8a4f459
145
abra
145
abra
@ -15,6 +15,7 @@ Usage:
|
||||
abra [options] app (list|ls)
|
||||
abra [options] app <domain> deploy
|
||||
abra [options] app <domain> undeploy
|
||||
abra [options] app <domain> config
|
||||
abra [options] app <domain> (delete|rm) [--force]
|
||||
abra [options] app <domain> logs [<service>]
|
||||
abra [options] app <domain> multilogs
|
||||
@ -140,12 +141,12 @@ 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:1237}
|
||||
usage=${DOC:40:929}; digest=03087; shorts=(-h -s -e -v '' '' '' '')
|
||||
longs=(--help --stack --env --version --server --domain --force --user)
|
||||
argcounts=(0 1 1 0 1 1 0 1); node_0(){ switch __help 0; }; node_1(){
|
||||
value __stack 1; }; node_2(){ value __env 2; }; node_3(){ switch __version 3; }
|
||||
node_4(){ value __server 4; }; node_5(){ value __domain 5; }; node_6(){
|
||||
printf -- "exit %d\n" "$1"; exit "$1"; }; set -e; trimmed_doc=${DOC:1:1274}
|
||||
usage=${DOC:40:966}; digest=f3b8b; shorts=(-e -v -s -h '' '' '' '')
|
||||
longs=(--env --version --stack --help --server --domain --force --user)
|
||||
argcounts=(1 0 1 0 1 1 0 1); node_0(){ value __env 0; }; node_1(){
|
||||
switch __version 1; }; node_2(){ value __stack 2; }; node_3(){ switch __help 3
|
||||
}; node_4(){ value __server 4; }; node_5(){ value __domain 5; }; node_6(){
|
||||
switch __force 6; }; node_7(){ value __user 7; }; node_8(){ value _app_ a; }
|
||||
node_9(){ value _domain_ a; }; node_10(){ value _service_ a; }; node_11(){
|
||||
value _src_ a; }; node_12(){ value _dst_ a; }; node_13(){ value _args_ a true; }
|
||||
@ -154,54 +155,55 @@ value _cmd_ a; }; node_17(){ value _data_ a; }; node_18(){ value _host_ a; }
|
||||
node_19(){ value _user_ a; }; node_20(){ value _port_ a; }; node_21(){
|
||||
value _command_ a; }; node_22(){ _command app; }; node_23(){ _command new; }
|
||||
node_24(){ _command list; }; node_25(){ _command ls; }; node_26(){
|
||||
_command deploy; }; node_27(){ _command undeploy; }; node_28(){ _command delete
|
||||
}; node_29(){ _command rm; }; node_30(){ _command logs; }; node_31(){
|
||||
_command multilogs; }; node_32(){ _command cp; }; node_33(){ _command run; }
|
||||
node_34(){ _command secret; }; node_35(){ _command auto; }; node_36(){
|
||||
_command generate; }; node_37(){ _command insert; }; node_38(){ _command server
|
||||
}; node_39(){ _command add; }; node_40(){ _command use; }; node_41(){
|
||||
_command init; }; node_42(){ _command upgrade; }; node_43(){ optional 0 1 2 3; }
|
||||
node_44(){ optional 43; }; node_45(){ optional 4 5; }; node_46(){
|
||||
required 44 22 23 45 8; }; node_47(){ either 24 25; }; node_48(){ required 47; }
|
||||
node_49(){ required 44 22 48; }; node_50(){ required 44 22 9 26; }; node_51(){
|
||||
required 44 22 9 27; }; node_52(){ either 28 29; }; node_53(){ required 52; }
|
||||
node_54(){ optional 6; }; node_55(){ required 44 22 9 53 54; }; node_56(){
|
||||
optional 10; }; node_57(){ required 44 22 9 30 56; }; node_58(){
|
||||
required 44 22 9 31; }; node_59(){ required 44 22 9 32 11 12; }; node_60(){
|
||||
optional 7; }; node_61(){ oneormore 13; }; node_62(){
|
||||
required 44 22 9 33 60 10 61; }; node_63(){ required 44 22 9 33 10 61; }
|
||||
node_64(){ required 44 22 9 34 35; }; node_65(){ optional 16; }; node_66(){
|
||||
required 44 22 9 34 36 14 15 65; }; node_67(){ required 44 22 9 34 37 14 15 17
|
||||
}; node_68(){ optional 19; }; node_69(){ optional 20; }; node_70(){
|
||||
required 44 38 39 18 68 69; }; node_71(){ required 44 38 48; }; node_72(){
|
||||
required 44 38 29 18; }; node_73(){ required 44 38 40 18; }; node_74(){
|
||||
required 44 38 41 18; }; node_75(){ required 44 42; }; node_76(){
|
||||
required 44 21 61; }; node_77(){
|
||||
either 46 49 50 51 55 57 58 59 62 63 64 66 67 70 71 72 73 74 75 76; }
|
||||
node_78(){ required 77; }; cat <<<' docopt_exit() {
|
||||
[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:929}" >&2; exit 1
|
||||
}'; unset var___help var___stack var___env var___version var___server \
|
||||
_command deploy; }; node_27(){ _command undeploy; }; node_28(){ _command config
|
||||
}; node_29(){ _command delete; }; node_30(){ _command rm; }; node_31(){
|
||||
_command logs; }; node_32(){ _command multilogs; }; node_33(){ _command cp; }
|
||||
node_34(){ _command run; }; node_35(){ _command secret; }; node_36(){
|
||||
_command auto; }; node_37(){ _command generate; }; node_38(){ _command insert; }
|
||||
node_39(){ _command server; }; node_40(){ _command add; }; node_41(){
|
||||
_command use; }; node_42(){ _command init; }; node_43(){ _command upgrade; }
|
||||
node_44(){ optional 0 1 2 3; }; node_45(){ optional 44; }; node_46(){
|
||||
optional 4 5; }; node_47(){ required 45 22 23 46 8; }; node_48(){ either 24 25
|
||||
}; node_49(){ required 48; }; node_50(){ required 45 22 49; }; node_51(){
|
||||
required 45 22 9 26; }; node_52(){ required 45 22 9 27; }; node_53(){
|
||||
required 45 22 9 28; }; node_54(){ either 29 30; }; node_55(){ required 54; }
|
||||
node_56(){ optional 6; }; node_57(){ required 45 22 9 55 56; }; node_58(){
|
||||
optional 10; }; node_59(){ required 45 22 9 31 58; }; node_60(){
|
||||
required 45 22 9 32; }; node_61(){ required 45 22 9 33 11 12; }; node_62(){
|
||||
optional 7; }; node_63(){ oneormore 13; }; node_64(){
|
||||
required 45 22 9 34 62 10 63; }; node_65(){ required 45 22 9 34 10 63; }
|
||||
node_66(){ required 45 22 9 35 36; }; node_67(){ optional 16; }; node_68(){
|
||||
required 45 22 9 35 37 14 15 67; }; node_69(){ required 45 22 9 35 38 14 15 17
|
||||
}; node_70(){ optional 19; }; node_71(){ optional 20; }; node_72(){
|
||||
required 45 39 40 18 70 71; }; node_73(){ required 45 39 49; }; node_74(){
|
||||
required 45 39 30 18; }; node_75(){ required 45 39 41 18; }; node_76(){
|
||||
required 45 39 42 18; }; node_77(){ required 45 43; }; node_78(){
|
||||
required 45 21 63; }; node_79(){
|
||||
either 47 50 51 52 53 57 59 60 61 64 65 66 68 69 72 73 74 75 76 77 78; }
|
||||
node_80(){ required 79; }; cat <<<' docopt_exit() {
|
||||
[[ -n $1 ]] && printf "%s\n" "$1" >&2; printf "%s\n" "${DOC:40:966}" >&2; exit 1
|
||||
}'; unset var___env var___version var___stack var___help var___server \
|
||||
var___domain var___force var___user 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__command_ var_app var_new var_list var_ls \
|
||||
var_deploy var_undeploy var_delete var_rm var_logs var_multilogs var_cp \
|
||||
var_run var_secret var_auto var_generate var_insert var_server var_add var_use \
|
||||
var_init var_upgrade; parse 78 "$@"; local prefix=${DOCOPT_PREFIX:-''}
|
||||
unset "${prefix}__help" "${prefix}__stack" "${prefix}__env" \
|
||||
"${prefix}__version" "${prefix}__server" "${prefix}__domain" \
|
||||
"${prefix}__force" "${prefix}__user" "${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}_command_" \
|
||||
"${prefix}app" "${prefix}new" "${prefix}list" "${prefix}ls" "${prefix}deploy" \
|
||||
"${prefix}undeploy" "${prefix}delete" "${prefix}rm" "${prefix}logs" \
|
||||
"${prefix}multilogs" "${prefix}cp" "${prefix}run" "${prefix}secret" \
|
||||
"${prefix}auto" "${prefix}generate" "${prefix}insert" "${prefix}server" \
|
||||
"${prefix}add" "${prefix}use" "${prefix}init" "${prefix}upgrade"
|
||||
eval "${prefix}"'__help=${var___help:-false}'
|
||||
eval "${prefix}"'__stack=${var___stack:-}'
|
||||
eval "${prefix}"'__env=${var___env:-}'
|
||||
var_deploy var_undeploy var_config var_delete var_rm var_logs var_multilogs \
|
||||
var_cp var_run var_secret var_auto var_generate var_insert var_server var_add \
|
||||
var_use var_init var_upgrade; parse 80 "$@"; local prefix=${DOCOPT_PREFIX:-''}
|
||||
unset "${prefix}__env" "${prefix}__version" "${prefix}__stack" \
|
||||
"${prefix}__help" "${prefix}__server" "${prefix}__domain" "${prefix}__force" \
|
||||
"${prefix}__user" "${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}_command_" "${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}run" \
|
||||
"${prefix}secret" "${prefix}auto" "${prefix}generate" "${prefix}insert" \
|
||||
"${prefix}server" "${prefix}add" "${prefix}use" "${prefix}init" \
|
||||
"${prefix}upgrade"; eval "${prefix}"'__env=${var___env:-}'
|
||||
eval "${prefix}"'__version=${var___version:-false}'
|
||||
eval "${prefix}"'__stack=${var___stack:-}'
|
||||
eval "${prefix}"'__help=${var___help:-false}'
|
||||
eval "${prefix}"'__server=${var___server:-}'
|
||||
eval "${prefix}"'__domain=${var___domain:-}'
|
||||
eval "${prefix}"'__force=${var___force:-false}'
|
||||
@ -222,6 +224,7 @@ eval "${prefix}"'app=${var_app:-false}'; eval "${prefix}"'new=${var_new:-false}'
|
||||
eval "${prefix}"'list=${var_list:-false}'; eval "${prefix}"'ls=${var_ls:-false}'
|
||||
eval "${prefix}"'deploy=${var_deploy:-false}'
|
||||
eval "${prefix}"'undeploy=${var_undeploy:-false}'
|
||||
eval "${prefix}"'config=${var_config:-false}'
|
||||
eval "${prefix}"'delete=${var_delete:-false}'
|
||||
eval "${prefix}"'rm=${var_rm:-false}'; eval "${prefix}"'logs=${var_logs:-false}'
|
||||
eval "${prefix}"'multilogs=${var_multilogs:-false}'
|
||||
@ -235,17 +238,18 @@ 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}__help" "${prefix}__stack" "${prefix}__env" \
|
||||
"${prefix}__version" "${prefix}__server" "${prefix}__domain" \
|
||||
"${prefix}__force" "${prefix}__user" "${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}_command_" \
|
||||
"${prefix}app" "${prefix}new" "${prefix}list" "${prefix}ls" "${prefix}deploy" \
|
||||
"${prefix}undeploy" "${prefix}delete" "${prefix}rm" "${prefix}logs" \
|
||||
"${prefix}multilogs" "${prefix}cp" "${prefix}run" "${prefix}secret" \
|
||||
"${prefix}auto" "${prefix}generate" "${prefix}insert" "${prefix}server" \
|
||||
"${prefix}add" "${prefix}use" "${prefix}init" "${prefix}upgrade"; done; }
|
||||
declare -p "${prefix}__env" "${prefix}__version" "${prefix}__stack" \
|
||||
"${prefix}__help" "${prefix}__server" "${prefix}__domain" "${prefix}__force" \
|
||||
"${prefix}__user" "${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}_command_" "${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}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")
|
||||
@ -322,7 +326,7 @@ get_servers() {
|
||||
|
||||
get_app_secrets() {
|
||||
# FIXME 3wc: requires bash 4, use for loop instead
|
||||
mapfile -t SECRETS < <(grep PASSWORD "$ENV_FILE" | cut -d' ' -f2)
|
||||
mapfile -t SECRETS < <(grep "PASSWORD.*VERSION" "$ENV_FILE" | cut -d' ' -f2)
|
||||
}
|
||||
|
||||
load_instance() {
|
||||
@ -454,6 +458,7 @@ sub_app_new (){
|
||||
|
||||
cp "$APP_DIR/.envrc.sample" "$ENV_FILE"
|
||||
sed -i "s/$APP\.example\.com/$DOMAIN/g" "$ENV_FILE"
|
||||
sed -i "s/example\.com/$DOMAIN/g" "$ENV_FILE"
|
||||
|
||||
abra__domain_="$DOMAIN"
|
||||
|
||||
@ -468,9 +473,9 @@ sub_app_new (){
|
||||
|
||||
echo "$(tput setaf 4)Your new '$APP' is ready for action:$(tput sgr0)"
|
||||
echo " $(tput setaf 3)Customise the configuration:"
|
||||
echo " $ENV_FILE$(tput sgr0)"
|
||||
echo " abra app $DOMAIN config$(tput sgr0)"
|
||||
echo " $(tput setaf 2)Deploy it:"
|
||||
echo " abra app deploy $DOMAIN$(tput sgr0)"
|
||||
echo " abra app $DOMAIN deploy$(tput sgr0)"
|
||||
}
|
||||
|
||||
###### .. app <domain> deploy
|
||||
@ -529,6 +534,14 @@ sub_app_undeploy (){
|
||||
docker stack rm "$STACK_NAME"
|
||||
}
|
||||
|
||||
###### .. app <domain> config
|
||||
sub_app_config (){
|
||||
load_instance
|
||||
load_instance_env
|
||||
|
||||
$EDITOR "$ENV_FILE"
|
||||
}
|
||||
|
||||
###### .. app <domain> delete
|
||||
sub_app_rm (){
|
||||
sub_app_delete
|
||||
@ -602,6 +615,7 @@ sub_app_secret_auto(){
|
||||
abra__secret_="${abra__secret_%_VERSION}" # strip VERSION_
|
||||
abra__secret_="${abra__secret_,,}" # lowercase
|
||||
abra__version_="${SECRET#*=}"
|
||||
echo "Generating $abra__secret_"
|
||||
sub_app_secret_generate
|
||||
done
|
||||
}
|
||||
@ -616,7 +630,7 @@ sub_app_run(){
|
||||
fi
|
||||
|
||||
CONTAINER=$(docker container ls --format "table {{.ID}},{{.Names}}" \
|
||||
| grep "${STACK_NAME}_${abra__app_}" | head -n1 | cut -d',' -f1)
|
||||
| grep "${STACK_NAME}_${abra__service_}" | head -n1 | cut -d',' -f1)
|
||||
|
||||
if [ -z "$CONTAINER" ]; then
|
||||
error "Can't find a container for ${STACK_NAME}_${abra__service_}"
|
||||
@ -842,6 +856,7 @@ abra() {
|
||||
# shellcheck disable=SC2086
|
||||
"$CMD" ${abra__args_[*]}
|
||||
else
|
||||
"$CMD not found"
|
||||
docopt_exit
|
||||
fi
|
||||
}
|
||||
|
Reference in New Issue
Block a user