refactor: move run command to it's own plugin
This commit is contained in:
16
plugins/run/commands
Executable file
16
plugins/run/commands
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
[[ " help run:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
|
||||
source "$PLUGIN_AVAILABLE_PATH/run/help-functions"
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
case "$1" in
|
||||
help | run:help)
|
||||
cmd-run-help "$@"
|
||||
;;
|
||||
|
||||
*)
|
||||
exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
|
||||
;;
|
||||
|
||||
esac
|
||||
32
plugins/run/help-functions
Executable file
32
plugins/run/help-functions
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
cmd-run-help() {
|
||||
declare desc="help command"
|
||||
declare CMD="$1"
|
||||
local plugin_name="run"
|
||||
local plugin_description="Run a one-off process inside a container"
|
||||
|
||||
if [[ "$CMD" == "${plugin_name}:help" ]]; then
|
||||
echo -e "Usage: dokku ${plugin_name}[:COMMAND]"
|
||||
echo ''
|
||||
echo "$plugin_description"
|
||||
echo ''
|
||||
echo 'Additional commands:'
|
||||
fn-help-content | sort | column -c2 -t -s,
|
||||
elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then
|
||||
fn-help-content
|
||||
else
|
||||
cat <<help_desc
|
||||
$plugin_name, $plugin_description
|
||||
help_desc
|
||||
fi
|
||||
}
|
||||
|
||||
fn-help-content() {
|
||||
declare desc="return help content"
|
||||
cat <<help_content
|
||||
run [--env KEY=VALUE] <app> <cmd>, Run a command in a new container using the current application image
|
||||
help_content
|
||||
}
|
||||
61
plugins/run/internal-functions
Executable file
61
plugins/run/internal-functions
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
fn-run() {
|
||||
declare desc="runs command in container"
|
||||
|
||||
declare APP=""
|
||||
local SCHEDULER_ID
|
||||
declare -a RUN_ENV
|
||||
RUN_ENV=()
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--cron-id=*)
|
||||
local arg=$(printf "%s" "$1" | sed -E 's/(^--cron-id=)//g')
|
||||
SCHEDULER_ID+=("$arg")
|
||||
shift
|
||||
;;
|
||||
--cron-id)
|
||||
if [[ ! $2 ]]; then
|
||||
dokku_log_warn "expected $1 to have an argument"
|
||||
break
|
||||
fi
|
||||
CRON_ID+=("$2")
|
||||
shift 2
|
||||
;;
|
||||
-e=* | --env=*)
|
||||
local arg=$(printf "%s" "$1" | sed -E 's/(^-e=)|(^--env=)//g')
|
||||
RUN_ENV+=("$arg")
|
||||
shift
|
||||
;;
|
||||
-e | --env)
|
||||
if [[ ! $2 ]]; then
|
||||
dokku_log_warn "expected $1 to have an argument"
|
||||
break
|
||||
fi
|
||||
RUN_ENV+=("$2")
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
APP="$1"
|
||||
shift
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
verify_app_name "$APP"
|
||||
|
||||
local DOKKU_SCHEDULER=$(get_app_scheduler "$APP")
|
||||
DOKKU_CRON_ID="$CRON_ID" plugn trigger scheduler-run "$DOKKU_SCHEDULER" "$APP" "${#RUN_ENV[@]}" "${RUN_ENV[@]}" "$@"
|
||||
}
|
||||
|
||||
cmd-run() {
|
||||
declare desc="runs command in container based on app image"
|
||||
declare cmd="run"
|
||||
[[ "$1" == "$cmd" ]] && shift 1
|
||||
|
||||
fn-run "$@"
|
||||
}
|
||||
4
plugins/run/plugin.toml
Normal file
4
plugins/run/plugin.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[plugin]
|
||||
description = "dokku core run plugin"
|
||||
version = "0.24.10"
|
||||
[plugin.config]
|
||||
6
plugins/run/subcommands/default
Executable file
6
plugins/run/subcommands/default
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
source "$PLUGIN_AVAILABLE_PATH/run/internal-functions"
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
|
||||
cmd-run "$@"
|
||||
Reference in New Issue
Block a user