fix: correct entering running containers
This functionality was broken due to a refactor of argument handling in a previous release. In addition to the fix, all the functionality was moved to scheduler-enter, which allows scheduler plugins to implement ways of entering containers in the relevant scheduler. Closes #3972
This commit is contained in:
@@ -1,67 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
cmd-enter-default() {
|
||||
declare desc="enters running app container of specified proc type"
|
||||
declare cmd="enter"
|
||||
[[ "$1" == "$cmd" ]] && shift 1
|
||||
declare APP="$1" CONTAINER_TYPE="$2" CONTAINER_ID="$3"
|
||||
declare APP="$1"
|
||||
|
||||
local IMAGE_TAG=$(get_running_image_tag "$APP")
|
||||
local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
|
||||
verify_app_name "$APP"
|
||||
local AVAILABLE_CONTAINER_TYPES=($(get_app_running_container_types "$APP"))
|
||||
|
||||
if [[ -z "$CONTAINER_TYPE" ]]; then
|
||||
if [[ ${#AVAILABLE_CONTAINER_TYPES[@]} -gt 1 ]]; then
|
||||
dokku_log_warn "No container type specified."
|
||||
dokku_log_fail "Available types for app ($APP): ${AVAILABLE_CONTAINER_TYPES[*]}"
|
||||
else
|
||||
CONTAINER_TYPE="${AVAILABLE_CONTAINER_TYPES[0]}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$CONTAINER_TYPE" == "--container-id" ]]; then
|
||||
local DOKKU_APP_CIDS=($(get_app_container_ids "$APP"))
|
||||
if [[ -z "$CONTAINER_ID" ]]; then
|
||||
dokku_log_warn "No container id specified."
|
||||
dokku_log_fail "Available ids for app ($APP): ${DOKKU_APP_CIDS[*]}"
|
||||
fi
|
||||
if ! (printf -- '%s\n' "${DOKKU_APP_CIDS[@]}" | grep -q -e "^$4"); then
|
||||
dokku_log_warn "Invalid container id for app"
|
||||
dokku_log_fail "Available ids for app ($APP): ${DOKKU_APP_CIDS[*]}"
|
||||
fi
|
||||
local ID=$(printf -- '%s\n' "${DOKKU_APP_CIDS[@]}" | grep -e "^$4")
|
||||
shift 3
|
||||
else
|
||||
local DOKKU_APP_CIDS=($(get_app_container_ids "$APP" "$CONTAINER_TYPE"))
|
||||
local ID=${DOKKU_APP_CIDS[0]}
|
||||
if [[ -z $ID ]]; then
|
||||
dokku_log_warn "No containers found for type '$CONTAINER_TYPE'"
|
||||
dokku_log_fail "Available types for app ($APP): ${AVAILABLE_CONTAINER_TYPES[*]}"
|
||||
fi
|
||||
if [[ "$CONTAINER_TYPE" ]]; then
|
||||
shift 2
|
||||
else
|
||||
shift 1
|
||||
fi
|
||||
fi
|
||||
|
||||
(is_container_status "$ID" "Running") || dokku_log_fail "Container is not running"
|
||||
|
||||
local DOKKU_APP_SHELL="/bin/bash"
|
||||
DOKKU_APP_SHELL="$(config_get --global DOKKU_APP_SHELL || echo "$DOKKU_APP_SHELL")"
|
||||
DOKKU_APP_SHELL="$(config_get "$APP" DOKKU_APP_SHELL || echo "$DOKKU_APP_SHELL")"
|
||||
[[ -z "$DOKKU_APP_SHELL" ]] && DOKKU_APP_SHELL="/bin/bash"
|
||||
|
||||
local EXEC_CMD=""
|
||||
has_tty && local DOKKU_RUN_OPTS+=" -i -t"
|
||||
is_image_herokuish_based "$IMAGE" "$APP" && local EXEC_CMD="/exec"
|
||||
# shellcheck disable=SC2086
|
||||
"$DOCKER_BIN" container exec $DOKKU_RUN_OPTS $ID $EXEC_CMD "${@:-$DOKKU_APP_SHELL}"
|
||||
local DOKKU_SCHEDULER=$(get_app_scheduler "$APP")
|
||||
plugn trigger scheduler-enter "$DOKKU_SCHEDULER" "$@"
|
||||
}
|
||||
|
||||
cmd-enter-default "$@"
|
||||
|
||||
Reference in New Issue
Block a user