Only load apps once, exciting 2× speed increase

This commit is contained in:
3wc 2021-03-13 20:15:54 +02:00
parent af52ba1fec
commit e8651976ca

56
abra
View File

@ -430,6 +430,7 @@ require_app_latest() {
debug "Using $APP_DIR" debug "Using $APP_DIR"
if [ "$abra___skip_update" = "false" ]; then if [ "$abra___skip_update" = "false" ]; then
debug "Pulling latest '$APP' definition via git"
(cd "$APP_DIR" && git pull > /dev/null 2>&1) (cd "$APP_DIR" && git pull > /dev/null 2>&1)
fi fi
} }
@ -467,8 +468,6 @@ load_abra_sh() {
fi fi
if [ -n "$abra__app_" ]; then if [ -n "$abra__app_" ]; then
load_instance
load_instance_env
require_app_latest "$TYPE" require_app_latest "$TYPE"
fi fi
@ -809,9 +808,6 @@ sub_app_new (){
###### .. app backup ###### .. app backup
sub_app_backup (){ sub_app_backup (){
load_instance
load_instance_env
require_app_latest "$TYPE" require_app_latest "$TYPE"
# Add _<service> if it's defined # Add _<service> if it's defined
@ -829,9 +825,6 @@ sub_app_backup (){
###### .. app restore ###### .. app restore
sub_app_restore (){ sub_app_restore (){
load_instance
load_instance_env
require_app_latest "$TYPE" require_app_latest "$TYPE"
FUNCTION="abra_restore_$abra__service_" FUNCTION="abra_restore_$abra__service_"
@ -925,9 +918,6 @@ POWERED BY
} }
sub_app_deploy (){ sub_app_deploy (){
load_instance
load_instance_env
require_app_latest "$TYPE" require_app_latest "$TYPE"
CONSENT_TO_UPDATE=$abra___update CONSENT_TO_UPDATE=$abra___update
@ -1014,9 +1004,6 @@ POWERED BY
} }
sub_app_undeploy (){ sub_app_undeploy (){
load_instance
load_instance_env
warning "About to un-deploy $STACK_NAME from $SERVER" warning "About to un-deploy $STACK_NAME from $SERVER"
prompt_confirm prompt_confirm
@ -1031,8 +1018,6 @@ Open the app configuration in \$EDITOR."
} }
sub_app_config (){ sub_app_config (){
load_instance
if [ -z "$EDITOR" ]; then if [ -z "$EDITOR" ]; then
warning "\$EDITOR not set; which text editor would you like to use?" warning "\$EDITOR not set; which text editor would you like to use?"
@ -1073,9 +1058,6 @@ sub_app_check (){
return 0 return 0
fi fi
load_instance
load_instance_env
APP_ENV=$(grep -v '^#' "$ENV_FILE" | cut -d' ' -f2 | cut -d'=' -f1 | sort -u) APP_ENV=$(grep -v '^#' "$ENV_FILE" | cut -d' ' -f2 | cut -d'=' -f1 | sort -u)
STACK_ENV=$(grep -v '^#' "$APP_DIR/.env.sample" | cut -d' ' -f2 | cut -d'=' -f1 | sort -u) STACK_ENV=$(grep -v '^#' "$APP_DIR/.env.sample" | cut -d' ' -f2 | cut -d'=' -f1 | sort -u)
@ -1105,9 +1087,6 @@ POWERED BY
} }
sub_app_ps (){ sub_app_ps (){
load_instance
load_instance_env
docker stack ps "$STACK_NAME" docker stack ps "$STACK_NAME"
} }
@ -1133,9 +1112,6 @@ OPTIONS
} }
sub_app_delete (){ sub_app_delete (){
load_instance
load_instance_env
if [ "$abra___force" != "true" ]; then if [ "$abra___force" != "true" ]; then
warning "About to delete $ENV_FILE" warning "About to delete $ENV_FILE"
prompt_confirm prompt_confirm
@ -1181,9 +1157,6 @@ OPTIONS
--pass Save the secret in \`pass\` as well" --pass Save the secret in \`pass\` as well"
} }
sub_app_secret_insert() { sub_app_secret_insert() {
load_instance
load_instance_env
SECRET="$abra__secret_" SECRET="$abra__secret_"
VERSION="$abra__version_" VERSION="$abra__version_"
PW="$abra__data_" PW="$abra__data_"
@ -1223,9 +1196,6 @@ OPTIONS
} }
sub_app_secret_delete(){ sub_app_secret_delete(){
load_instance
load_instance_env
# if --all is provided then $abra__secret_ will be blank and this will work # if --all is provided then $abra__secret_ will be blank and this will work
# auto-magically # auto-magically
NAMES=$(docker secret ls --filter "name=${STACK_NAME}_${abra__secret_}" --format "{{.Name}}") NAMES=$(docker secret ls --filter "name=${STACK_NAME}_${abra__secret_}" --format "{{.Name}}")
@ -1266,9 +1236,6 @@ OPTIONS
} }
sub_app_secret_generate(){ sub_app_secret_generate(){
load_instance
load_instance_env
SECRET="$abra__secret_" SECRET="$abra__secret_"
VERSION="$abra__version_" VERSION="$abra__version_"
LENGTH="$abra__length_" LENGTH="$abra__length_"
@ -1333,9 +1300,6 @@ POWERED BY
} }
sub_app_run(){ sub_app_run(){
load_instance
load_instance_env
if [ -n "$abra___user" ]; then if [ -n "$abra___user" ]; then
RUN_USER="-u $abra___user" RUN_USER="-u $abra___user"
fi fi
@ -1354,7 +1318,7 @@ sub_app_run(){
exit exit
fi fi
debug "Using Container ID ${CONTAINER}" debug "Using container ID ${CONTAINER}"
# 3wc: we want the "splitting" that shellcheck warns us about, so that -u and # 3wc: we want the "splitting" that shellcheck warns us about, so that -u and
# $RUN_USER aren't treated as a single argument: # $RUN_USER aren't treated as a single argument:
@ -1378,9 +1342,6 @@ POWERED BY
} }
sub_app_rollback(){ sub_app_rollback(){
load_instance
load_instance_env
SERVICE="${abra__service_}" SERVICE="${abra__service_}"
docker service rollback "${STACK_NAME}_${SERVICE}" docker service rollback "${STACK_NAME}_${SERVICE}"
@ -1404,9 +1365,6 @@ POWERED BY
} }
sub_app_logs (){ sub_app_logs (){
load_instance
load_instance_env
SERVICE="${abra__service_}" SERVICE="${abra__service_}"
if [ -z "$SERVICE" ]; then if [ -z "$SERVICE" ]; then
@ -1456,9 +1414,6 @@ POWERED BY
} }
sub_app_cp() { sub_app_cp() {
load_instance
load_instance_env
SOURCE="${abra__src_}" SOURCE="${abra__src_}"
DEST="${abra__dst_}" DEST="${abra__dst_}"
@ -1481,7 +1436,7 @@ sub_app_cp() {
exit exit
fi fi
debug "Using Container ID ${CONTAINER}" debug "Using container ID ${CONTAINER}"
# Replace $SERVICE with $CONTAINER in the original args # Replace $SERVICE with $CONTAINER in the original args
CP_ARGS=$(echo "$SOURCE $DEST" | sed "s/$SERVICE:/$CONTAINER:/") CP_ARGS=$(echo "$SOURCE $DEST" | sed "s/$SERVICE:/$CONTAINER:/")
@ -1762,6 +1717,11 @@ abra() {
set +a set +a
fi fi
if [ -n "$abra__app_" ]; then
load_instance
load_instance_env
fi
load_abra_sh load_abra_sh
# Search for sub_* functions, and check if any of them matches enabled # Search for sub_* functions, and check if any of them matches enabled