Files
dokku/plugins/run/internal-functions
T

144 lines
3.1 KiB
Bash
Executable File

#!/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 CRON_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')
CRON_ID="$arg"
shift
;;
--no-tty)
export DOKKU_DISABLE_TTY=true
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
export DOKKU_RM_CONTAINER=1
fn-run "$@"
}
cmd-run-detached() {
declare desc="run a detached container"
declare cmd="run:detached"
[[ "$1" == "$cmd" ]] && shift 1
export DOKKU_DETACH_CONTAINER=1
export DOKKU_DISABLE_TTY=true
export DOKKU_RM_CONTAINER=1
fn-run "$@"
}
cmd-run-list() {
declare desc="list all run containers for an app"
declare cmd="run:list"
[[ "$1" == "$cmd" ]] && shift 1
declare APP=""
local FORMAT="stdout"
while [[ $# -gt 0 ]]; do
case $1 in
--format=*)
local arg=$(printf "%s" "$1" | sed -E 's/(^--format=)//g')
FORMAT="$arg"
shift
;;
--format)
if [[ ! $2 ]]; then
dokku_log_warn "expected $1 to have an argument"
break
fi
FORMAT="$2"
shift 2
;;
*)
APP="$1"
shift
;;
esac
done
verify_app_name "$APP"
local DOKKU_SCHEDULER=$(get_app_scheduler "$APP")
plugn trigger scheduler-run-list "$DOKKU_SCHEDULER" "$APP" "$FORMAT"
}
cmd-run-stop() {
declare desc="Stops all run containers for an app or a specified run container"
declare cmd="run:stop"
[[ "$1" == "$cmd" ]] && shift 1
declare APP CONTAINER_NAME
while [[ $# -gt 0 ]]; do
case $1 in
--container=*)
local arg=$(printf "%s" "$1" | sed -E 's/(^--container=)//g')
CONTAINER_NAME="$arg"
shift
;;
--container)
if [[ ! $2 ]]; then
dokku_log_warn "expected $1 to have an argument"
break
fi
CONTAINER_NAME="$2"
shift 2
;;
*)
APP="$1"
shift
;;
esac
done
local DOKKU_SCHEDULER=$(get_app_scheduler "$APP")
plugn trigger scheduler-run-stop "$DOKKU_SCHEDULER" "$APP" "$CONTAINER_NAME"
}