This reduces duplication and allows users to rely on global arguments to generate most labels needed. The 'commit' command cannot have global arguments because the whitespace within the label change breaks string-based interpolation, and shell arrays cannot be exported.
74 lines
2.5 KiB
Bash
Executable File
74 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
|
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
|
|
|
|
scheduler-docker-local-scheduler-run() {
|
|
declare desc="runs command in container based on app image"
|
|
declare trigger="scheduler-docker-local scheduler-run"
|
|
declare DOKKU_SCHEDULER="$1" APP="$2" ENV_COUNT="$3"
|
|
shift 3
|
|
|
|
declare RUN_ENV=("${@:1:ENV_COUNT}")
|
|
shift "$ENV_COUNT"
|
|
|
|
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
|
return
|
|
fi
|
|
|
|
local DOCKER_RUN_LABEL_ARGS="--label=com.dokku.app-name=$APP"
|
|
local IMAGE_TAG=$(get_running_image_tag "$APP")
|
|
local IMAGE=$(get_deploying_app_image_name "$APP" "$IMAGE_TAG")
|
|
|
|
if [[ -z "$DOKKU_RM_CONTAINER" ]]; then
|
|
local DOKKU_APP_RM_CONTAINER=$(config_get "$APP" DOKKU_RM_CONTAINER || true)
|
|
local DOKKU_GLOBAL_RM_CONTAINER=$(config_get --global DOKKU_RM_CONTAINER || true)
|
|
local DOKKU_RM_CONTAINER=${DOKKU_APP_RM_CONTAINER:="$DOKKU_GLOBAL_RM_CONTAINER"}
|
|
fi
|
|
|
|
local DOCKER_ARGS=$(: | plugn trigger docker-args-run "$APP" "$IMAGE_TAG")
|
|
[[ "$DOKKU_TRACE" ]] && DOCKER_ARGS+=" -e TRACE=true "
|
|
|
|
local IMAGE_SOURCE_TYPE="dockerfile"
|
|
is_image_herokuish_based "$IMAGE" && IMAGE_SOURCE_TYPE="herokuish"
|
|
DOCKER_ARGS+=$(: | plugn trigger docker-args-process-run "$APP" "$IMAGE_TAG" "$IMAGE_SOURCE_TYPE")
|
|
DOCKER_ARGS+=" -e DYNO=run.$RANDOM"
|
|
|
|
declare -a ARG_ARRAY
|
|
eval "ARG_ARRAY=($DOCKER_ARGS)"
|
|
|
|
local DOKKU_RUN_OPTS=" -e DYNO=run.$RANDOM"
|
|
if [[ "$DOKKU_RM_CONTAINER" ]]; then
|
|
DOCKER_ARGS+=" --rm"
|
|
elif [[ "$DOKKU_DETACH_CONTAINER" ]]; then
|
|
DOCKER_ARGS+=" --detach"
|
|
fi
|
|
has_tty && DOCKER_ARGS+=" -i -t"
|
|
# the output of docker-args-run is possibly quoted/escaped so eval to normalize
|
|
declare -a DOCKER_ARGS_ARRAY
|
|
eval "DOCKER_ARGS_ARRAY=($DOCKER_ARGS)"
|
|
for env_pair in "${RUN_ENV[@]}"; do
|
|
DOCKER_ARGS_ARRAY+=("--env=$env_pair")
|
|
done
|
|
|
|
[[ "$IMAGE_SOURCE_TYPE" == "herokuish" ]] && local EXEC_CMD="/exec"
|
|
|
|
DOKKU_QUIET_OUTPUT=1 extract_procfile "$APP"
|
|
|
|
POTENTIAL_PROCFILE_KEY="$1"
|
|
PROC_CMD=$(get_cmd_from_procfile "$APP" "$POTENTIAL_PROCFILE_KEY" 2>/dev/null || echo '')
|
|
remove_procfile "$APP"
|
|
|
|
if [[ -n "$PROC_CMD" ]]; then
|
|
dokku_log_info1_quiet "Found '$POTENTIAL_PROCFILE_KEY' in Procfile, running that command"
|
|
set -- "$PROC_CMD" "${@:2}"
|
|
fi
|
|
|
|
# shellcheck disable=SC2086
|
|
"$DOCKER_BIN" run "${DOCKER_RUN_LABEL_ARGS[@]}" $DOKKU_GLOBAL_RUN_ARGS "${DOCKER_ARGS_ARRAY[@]}" $IMAGE $EXEC_CMD "$@"
|
|
}
|
|
|
|
scheduler-docker-local-scheduler-run "$@"
|