diff --git a/docs/deployment/builds-management.md b/docs/deployment/builds-management.md new file mode 100644 index 00000000000..cf3e779dd35 --- /dev/null +++ b/docs/deployment/builds-management.md @@ -0,0 +1,30 @@ +# Build Management + +> New as of 0.19.0 + +``` +builds:cancel # Cancel a running build for an app +builds:list # List all running builds +builds:output # Shows build output +builds:report [] [] # Displays a build report for one or more apps +``` + +## Usage + +### Listing running deploys + +### Viewing the status of a deploy + +### Viewing build output for a deploy + +### Canceling a running deploy + +It can be useful to kill a deploy if that deploy does not appear to be progressing, is impacting other apps through system resource utilization, or if a successful deploy will result in app errors. To do so, the `builds:cancel` command can be used: + +```shell +dokku builds:cancel node-js-app +``` + +This command will send a `QUIT` signal to the Process Group ID of the process handling the deploy, and should terminate all processes within that process tree. Finally, it will unlock the deploy so that a new deploy may be immediately invoked. + +> Warning: This may also result in invalid app state depending upon when the app deploy was killed. diff --git a/dokku b/dokku index 88c91825bb9..0a1a0bc15b8 100755 --- a/dokku +++ b/dokku @@ -167,6 +167,11 @@ execute_dokku_cmd() { set -- "$PLUGIN_CMD" "$@" fi + if [[ $PLUGIN_NAME =~ git-* ]] || [[ "$PLUGIN_NAME" == "ps:rebuild" ]] || [[ "$PLUGIN_NAME" == "ps:restart" ]] || [[ "$PLUGIN_NAME" == "deploy" ]]; then + export DOKKU_REDIRECT_OUTPUT=true + exec &> >(tee >(tee | logger -i -t "dokku-${DOKKU_PID}")) + fi + if [[ -x $PLUGIN_ENABLED_PATH/$PLUGIN_NAME/subcommands/default ]]; then "$PLUGIN_ENABLED_PATH/$PLUGIN_NAME/subcommands/default" "$@" implemented=1 diff --git a/plugins/builds/commands b/plugins/builds/commands new file mode 100755 index 00000000000..bbb12122224 --- /dev/null +++ b/plugins/builds/commands @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +[[ " help builds:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT" +source "$PLUGIN_AVAILABLE_PATH/builds/internal-functions" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +case "$1" in + help | builds:help) + cmd-builds-help "$@" + ;; + + *) + exit "$DOKKU_NOT_IMPLEMENTED_EXIT" + ;; + +esac diff --git a/plugins/builds/internal-functions b/plugins/builds/internal-functions new file mode 100755 index 00000000000..1b56fad60ab --- /dev/null +++ b/plugins/builds/internal-functions @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x + +fn-builds-help-content() { + declare desc="return logs plugin help content" + cat <, Cancel a running build for an app + builds:list , List all running builds + builds:output , Shows build output + builds:report [] [], Displays a build report for one or more apps +help_content +} + +cmd-builds-help() { + if [[ $1 == "builds:help" ]]; then + echo -e 'Usage: dokku builds[:COMMAND]' + echo '' + echo 'Manage running builds' + echo '' + echo 'Additional commands:' + fn-builds-help-content | sort | column -c2 -t -s, + elif [[ $(ps -o command= $PPID) == *"--all"* ]]; then + fn-builds-help-content + else + cat < >(tee >(tee | logger -i -t "dokku-${DOKKU_PID}")) + fi + local APP="$1" local IMAGE_TAG="${2:-latest}" local IMAGE=$(get_app_image_name "$APP" "$IMAGE_TAG") diff --git a/plugins/git/internal-functions b/plugins/git/internal-functions index 4f162bc838b..7121d1ab1e0 100755 --- a/plugins/git/internal-functions +++ b/plugins/git/internal-functions @@ -52,6 +52,10 @@ cmd-git-from-archive() { dokku_log_fail "Invalid archive type specified, valid archive types include: tar, tar.gz, zip" fi + if [[ "$DOKKU_REDIRECT_OUTPUT" != "true" ]]; then + export DOKKU_REDIRECT_OUTPUT=true + exec &> >(tee >(tee | logger -i -t "dokku-${DOKKU_PID}")) + fi plugn trigger git-from-archive "$APP" "$ARCHIVE_URL" "$ARCHIVE_TYPE" "$USER_NAME" "$USER_EMAIL" plugn trigger deploy-source-set "$APP" "$ARCHIVE_TYPE" "$ARCHIVE_URL" } @@ -124,6 +128,10 @@ cmd-git-load-image() { [[ -z "$DOCKER_IMAGE" ]] && dokku_log_fail "Please specify a docker image" [[ ! -t 0 ]] || dokku_log_fail "Expecting tar archive containing docker image on STDIN" + if [[ "$DOKKU_REDIRECT_OUTPUT" != "true" ]]; then + export DOKKU_REDIRECT_OUTPUT=true + exec &> >(tee >(tee | logger -i -t "dokku-${DOKKU_PID}")) + fi cat | docker load if ! verify_image "$DOCKER_IMAGE"; then @@ -168,6 +176,11 @@ cmd-git-from-image() { verify_app_name "$APP" [[ -z "$DOCKER_IMAGE" ]] && dokku_log_fail "Please specify a docker image" + if [[ "$DOKKU_REDIRECT_OUTPUT" != "true" ]]; then + export DOKKU_REDIRECT_OUTPUT=true + exec &> >(tee >(tee | logger -i -t "dokku-${DOKKU_PID}")) + fi + if ! plugn trigger git-from-image "$APP" "$DOCKER_IMAGE" "$BUILD_DIR" "$USER_NAME" "$USER_EMAIL"; then return 1 fi @@ -211,6 +224,11 @@ cmd-git-sync() { DOKKU_DEPLOY_BRANCH="$(fn-git-deploy-branch "$APP")" CURRENT_REF="$(fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" 2>/dev/null || true)" + if [[ "$DOKKU_REDIRECT_OUTPUT" != "true" ]]; then + export DOKKU_REDIRECT_OUTPUT=true + exec &> >(tee >(tee | logger -i -t "dokku-${DOKKU_PID}")) + fi + if ! fn-git-cmd "$APP_ROOT" rev-parse "$DOKKU_DEPLOY_BRANCH" >/dev/null 2>&1; then dokku_log_info1_quiet "Cloning $APP from $GIT_REMOTE#$GIT_REF" fn-git-clone "$APP" "$GIT_REMOTE" "$GIT_REF" diff --git a/plugins/git/receive-app b/plugins/git/receive-app index ef7f59af1ac..78821f83558 100755 --- a/plugins/git/receive-app +++ b/plugins/git/receive-app @@ -7,6 +7,11 @@ trigger-git-receive-app() { declare desc="builds the app from the local git repository" declare trigger="receive-app" + if [[ "$DOKKU_REDIRECT_OUTPUT" != "true" ]]; then + export DOKKU_REDIRECT_OUTPUT=true + exec &> >(tee >(tee | logger -i -t "dokku-${DOKKU_PID}")) + fi + git_receive_app "$@" return $? }