Files
dokku/plugins/enter/commands
Jose Diaz-Gonzalez 70511c340d Check if command is implemented in a plugin before executing plugin code
Because of how plugin commands are implemented, their output can be incredibly verbose. Rather than executing even the `set -eo pipefail` parts of a plugin, we immediately check if the command is implemented by a plugin. If it is not, then we continue on as normal.

One side-effect of this change is that plugin commands need to be duplicated again:

- once in the command array
- once for the actual body of the command
- once in the help output

This is also quite hackish, and probably not the best way to decrease trace output. Note that we drop approximately 2k lines worth of logs with this change.
2015-09-18 16:09:59 -04:00

46 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
[[ " enter help enter:help " == *" $1 "* ]] || exit $DOKKU_NOT_IMPLEMENTED_EXIT
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
case "$1" in
enter)
APP="$2"; CONTAINER_TYPE="$3"; IMAGE_TAG=$(get_running_image_tag $APP); IMAGE=$(get_app_image_name $APP $IMAGE_TAG)
verify_app_name "$APP"
[[ ! -n "$3" ]] && dokku_log_fail "No container id specified"
if [[ "$3" == "--container-id" ]]; then
[[ ! -n "$4" ]] && dokku_log_fail "No container id specified"
DOKKU_APP_CIDS=( $(get_app_container_ids "$APP") )
printf -- '%s\n' "${DOKKU_APP_CIDS[@]}" | grep -q -e "^$4" || dokku_log_fail "Invalid container id for app"
ID=$(printf -- '%s\n' "${DOKKU_APP_CIDS[@]}" | grep -e "^$4")
shift 4
else
DOKKU_APP_CIDS=( $(get_app_container_ids "$APP" "$CONTAINER_TYPE") )
ID=${DOKKU_APP_CIDS[0]}
[[ ! -n $ID ]] && dokku_log_fail "No containers found for type '$CONTAINER_TYPE'"
shift 3
fi
docker ps -aq --no-trunc | grep -e "^$ID" > /dev/null || dokku_log_fail "Container does not exist"
docker ps -q --no-trunc | grep -e "^$ID" > /dev/null || dokku_log_fail "Container is not running"
EXEC_CMD=""
is_image_herokuish_based "$IMAGE" && EXEC_CMD="/exec"
docker exec -it $ID $EXEC_CMD "${@:-/bin/bash}"
;;
help | enter:help)
cat && cat<<EOF
enter <app> [<container-type> || --container-id <container-id>], Connect to a specific app container
EOF
;;
*)
exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
;;
esac