Context set-up, Subsubcommands, COMPOSE->{_FILE}

This commit is contained in:
3wc 2020-09-22 00:08:13 +02:00
parent efd43752d6
commit f4798bf3bd

106
abra
View File

@ -3,8 +3,8 @@
PROGRAM_NAME=$(basename "$0")
ABRA_CONFIG=abra.yml
if [ -z "$COMPOSE" ]; then
COMPOSE="compose.yml"
if [ -z "$COMPOSE_FILE" ]; then
COMPOSE_FILE="compose.yml"
fi
yml_pattern_exists() {
@ -66,7 +66,14 @@ sub_help() {
echo ""
echo "Make sure \$STACK_NAME is set using direnv or -a"
echo ""
echo "Runs compose.yml by default, set e.g. COMPOSE=\"compose.yml compose2.yml\" to override"
echo "Runs compose.yml by default, set e.g. COMPOSE_FILE=\"compose.yml:compose2.yml\" to override"
}
sub_secret_help() {
echo "Usage: $PROGRAM_NAME [-a STACK_NAME] secret <subcommand> [options]"
echo ""
echo "Subcommands:"
echo " generate [PW] generate & store secret"
}
sub_secret_generate(){
@ -84,6 +91,13 @@ sub_secret_generate(){
>(pass insert "hosts/autonomic-swarm/${STACK_NAME}/${SECRET}" -m)
}
sub_secret() {
SUBCOMMAND=$1
shift
# shellcheck disable=SC2068
parse_subcommand "$SUBCOMMAND" "secret" $@
}
sub_run_args(){
SERVICE=$1
DOCKER_ARGS=$2
@ -119,7 +133,7 @@ sub_run(){
sub_deploy (){
echo "About to deploy:"
echo " Compose: $(tput setaf 3)${PWD}/${COMPOSE}$(tput sgr0)"
echo " Compose: $(tput setaf 3)${PWD}/${COMPOSE_FILE}$(tput sgr0)"
if [ -n "$DOMAIN" ]; then
echo " Domain: $(tput setaf 2)${DOMAIN}$(tput sgr0)"
fi
@ -134,7 +148,7 @@ sub_deploy (){
esac
# shellcheck disable=SC2086
if docker stack deploy -c ${COMPOSE/ / -c } "$STACK_NAME"; then
if docker stack deploy -c ${COMPOSE_FILE/:/ -c } "$STACK_NAME"; then
if [ -n "$DOMAIN" ]; then
echo "$(tput setaf 2)Yay! App should be available at https://${DOMAIN}$(tput sgr0)"
else
@ -194,18 +208,70 @@ sub_cp() {
docker cp $CP_ARGS
}
subcommand=$1
case $subcommand in
"" | "-h" | "--help")
sub_help
;;
*)
shift
"sub_${subcommand}" "$@"
if [ $? = 127 ]; then
echo "Error: '$subcommand' is not a known subcommand." >&2
echo " Run '$PROGRAM_NAME --help' for a list of known subcommands." >&2
exit 1
fi
;;
esac
sub_context_help() {
echo "Usage: $PROGRAM_NAME [-a STACK_NAME] context <subcommand> [options]"
echo ""
echo "Subcommands:"
echo " init HOST [USER] [PORT] set up remote Docker context"
echo " use activate remote Docker context"
}
sub_context_init() {
HOST="$1"
USERNAME="$2"
PORT="$3"
if [ -n "$PORT" ]; then
PORT=":$PORT"
fi
if [ -n "$USERNAME" ]; then
USERNAME="$USERNAME@"
fi
docker context create "$HOST" \
--docker "host=ssh://$USERNAME$HOST$PORT"
}
sub_context_use() {
docker context use "$1"
}
sub_context() {
SUBCOMMAND2=$1
shift
# shellcheck disable=SC2068
parse_subcommand "$SUBCOMMAND2" "context" $@
}
parse_subcommand() {
SUBCOMMAND="$1"
PREFIX=$2
if [ -n "$PREFIX" ]; then
PPREFIX="_$2"
SPREFIX="$2 "
SSPREFIX=" $2"
fi
case $SUBCOMMAND in
"" | "-h" | "--help")
"sub${PPREFIX}_help"
;;
*)
shift 2
"sub${PPREFIX}_${SUBCOMMAND}" "$@"
if [ $? = 127 ]; then
echo "Error: '$SPREFIX$SUBCOMMAND' is not a known subcommand." >&2
echo " Run '$PROGRAM_NAME$SSPREFIX --help' for a list of known subcommands." >&2
exit 1
fi
;;
esac
}
SUBCOMMAND=$1
shift
# shellcheck disable=SC2086,SC2068
parse_subcommand $SUBCOMMAND "" $@