Files
dokku/plugins/scheduler-docker-local/scheduler-enter
T
Jose Diaz-Gonzalez 1308e21947 feat: migrate environment variables to plugin properties
Standardize how environment variables are migrated to properties during
install triggers and migrate all remaining DOKKU_* config vars to their
appropriate plugin properties.

Adds a reusable MigrateConfigToProperties() function in the common
package with Transform callback and ListProperty support, plus a
migrate-config-to-property subcommand for the prop binary so shell
plugins can use the same code path.

Migrated variables and their new property owners:
- DOKKU_APP_PROXY_TYPE/DOKKU_PROXY_TYPE → proxy type
- DOKKU_DISABLE_PROXY → proxy disabled
- DOKKU_PROXY_PORT → ports proxy-port
- DOKKU_PROXY_SSL_PORT → ports proxy-ssl-port
- DOKKU_APP_RESTORE → ps restore
- DOKKU_SKIP_DEPLOY → ps skip-deploy
- DOKKU_START_CMD → ps start-cmd
- DOKKU_DOCKERFILE_START_CMD → ps dockerfile-start-cmd
- DOKKU_DISABLE_APP_AUTOCREATION → apps disable-autocreation
- DOKKU_APP_SHELL → scheduler shell
- DOKKU_SKIP_CLEANUP → builder skip-cleanup
- DOKKU_CHECKS_DISABLED → checks disabled
- DOKKU_CHECKS_SKIPPED → checks skipped
- DOKKU_CHECKS_WAIT → checks wait
- DOKKU_CHECKS_TIMEOUT → checks timeout
- DOKKU_CHECKS_ATTEMPTS → checks attempts
- DOKKU_DEFAULT_CHECKS_WAIT → checks default-wait
- DOKKU_SKIP_ALL_CHECKS → checks disabled (legacy)
- DOKKU_SKIP_DEFAULT_CHECKS → checks skipped (legacy)

Also refactors existing bespoke migration loops in scheduler, ports, ps,
builder, and nginx-vhosts plugins to use the standardized utility.

Removes DOKKU_PARALLEL_ARGUMENTS from documentation (unused in core).
Deprecates fn-migrate-config-to-property bash function.

closes #1558
2026-04-25 05:11:07 -04:00

108 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/config/functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
trigger-scheduler-docker-local-scheduler-enter() {
declare desc="enter a running container"
declare trigger="scheduler-enter"
declare DOKKU_SCHEDULER="$1" APP="$2"
shift 2
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
return
fi
local CONTAINER_ID
local CONTAINER_TYPE
while [[ $# -gt 0 ]]; do
case $1 in
--container-id=*)
local arg=$(printf "%s" "$1" | sed -E 's/(^--container-id=)//g')
CONTAINER_ID="$arg"
shift
;;
--container-id)
if [[ ! $2 ]]; then
dokku_log_warn "expected $1 to have an argument"
break
fi
CONTAINER_ID="$2"
shift 2
;;
*)
CONTAINER_TYPE="$1"
shift
break
;;
esac
done
if [[ -z "$CONTAINER_ID" ]] && [[ -z "$CONTAINER_TYPE" || "$CONTAINER_TYPE" == "--" ]]; then
AVAILABLE_CONTAINER_TYPES=($(get_app_running_container_types "$APP"))
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[*]}"
fi
CONTAINER_TYPE="${AVAILABLE_CONTAINER_TYPES[0]}"
fi
if [[ -z "$CONTAINER_ID" ]]; then
if [[ -z "$CONTAINER_TYPE" ]]; then
AVAILABLE_CONTAINER_TYPES=($(get_app_running_container_types "$APP"))
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[*]}"
fi
CONTAINER_TYPE="${AVAILABLE_CONTAINER_TYPES[0]}"
fi
if [[ -z "$CONTAINER_TYPE" ]]; then
dokku_log_fail "No containers found for app"
fi
local DOKKU_APP_CIDS=($(get_app_container_ids "$APP" "$CONTAINER_TYPE"))
local CONTAINER_ID=${DOKKU_APP_CIDS[0]}
if [[ -z "$CONTAINER_ID" ]]; then
if [[ ${#AVAILABLE_CONTAINER_TYPES[@]} -eq 0 ]]; then
AVAILABLE_CONTAINER_TYPES=($(get_app_running_container_types "$APP"))
fi
dokku_log_warn "No containers found for type '$CONTAINER_TYPE'"
dokku_log_fail "Available types for app ($APP): ${AVAILABLE_CONTAINER_TYPES[*]}"
fi
else
local DOKKU_APP_CIDS=($(get_app_container_ids "$APP"))
if ! (printf -- '%s\n' "${DOKKU_APP_CIDS[@]}" | grep -q -e "^$CONTAINER_ID"); then
dokku_log_warn "Invalid container id for app: $CONTAINER_ID"
dokku_log_fail "Available ids for app ($APP): ${DOKKU_APP_CIDS[*]}"
fi
CONTAINER_ID=$(printf -- '%s\n' "${DOKKU_APP_CIDS[@]}" | grep -e "^$CONTAINER_ID")
fi
if ! is_container_status "$CONTAINER_ID" "Running"; then
dokku_log_fail "Container is not running"
fi
if [[ "$1" == "--" ]]; then
shift
fi
local DOKKU_APP_SHELL
DOKKU_APP_SHELL="$(fn-plugin-property-get-default "scheduler" "$APP" "shell" "")"
[[ -z "$DOKKU_APP_SHELL" ]] && DOKKU_APP_SHELL="$(fn-plugin-property-get-default "scheduler" "--global" "shell" "/bin/bash")"
local EXEC_CMD=""
has_tty && local DOKKU_RUN_OPTS+=" -i -t"
local IMAGE="$("$DOCKER_BIN" container inspect --format '{{ .Config.Image }}' "$CONTAINER_ID")"
is_image_herokuish_based "$IMAGE" "$APP" && EXEC_CMD="/exec"
is_image_cnb_based "$IMAGE" && EXEC_CMD="" && DOKKU_RUN_OPTS+=" -w /workspace"
"$DOCKER_BIN" container exec $DOKKU_RUN_OPTS "$CONTAINER_ID" $EXEC_CMD "${@:-$DOKKU_APP_SHELL}"
}
trigger-scheduler-docker-local-scheduler-enter "$@"