这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/deployment/builds-management.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Build Management

> New as of 0.19.0

```
builds:cancel <app> # Cancel a running build for an app
builds:list <app> # List all running builds
builds:output <app> # Shows build output
builds:report [<app>] [<flag>] # 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.
5 changes: 5 additions & 0 deletions dokku
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions plugins/builds/commands
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions plugins/builds/internal-functions
Original file line number Diff line number Diff line change
@@ -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 <<help_content
builds, Manage running builds
builds:cancel <app>, Cancel a running build for an app
builds:list <app>, List all running builds
builds:output <app>, Shows build output
builds:report [<app>] [<flag>], 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 <<help_desc
builds, Manage running builds
help_desc
fi
}
4 changes: 4 additions & 0 deletions plugins/builds/plugin.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[plugin]
description = "dokku core builds plugin"
version = "0.33.9"
[plugin.config]
37 changes: 37 additions & 0 deletions plugins/builds/subcommands/cancel
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"

cmd-builds-cancel() {
declare desc="cancel a running build for an app"
declare cmd="builds:cancel"
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1"
local APP_DEPLOY_LOCK_FILE PROCESS_ID PROCESS_GROUP_ID
verify_app_name "$APP"

local APP_DEPLOY_LOCK_FILE PROCESS_ID PROCESS_GROUP_ID
APP_DEPLOY_LOCK_FILE="$DOKKU_LIB_ROOT/data/apps/$APP/.deploy.lock"
if [[ ! -f "$APP_DEPLOY_LOCK_FILE" ]]; then
dokku_log_info1 "App not currently deploying"
return
fi

PROCESS_ID="$(cat "$APP_DEPLOY_LOCK_FILE")"
if [[ -z "$PROCESS_ID" ]]; then
dokku_log_info1 "No matching app deploy found"
return
fi

PROCESS_GROUP_ID="$(ps -o pgid= "$PROCESS_ID" || true)"
if [[ -z "$PROCESS_ID" ]]; then
dokku_log_info1 "Unable to find process group id for app deploy"
return
fi

dokku_log_info1 "Killing app deploy"
kill -quit -- "-${PROCESS_GROUP_ID}" && rm -f "$APP_DEPLOY_LOCK_FILE"
}

cmd-builds-cancel "$@"
6 changes: 6 additions & 0 deletions plugins/builds/subcommands/default
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_AVAILABLE_PATH/builds/internal-functions"

cmd-builds-help "builds:help"
13 changes: 13 additions & 0 deletions plugins/builds/subcommands/list
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"

cmd-builds-list() {
declare desc="list all running builds"
declare cmd="builds:list"
[[ "$1" == "$cmd" ]] && shift 1

}

cmd-builds-list "$@"
40 changes: 40 additions & 0 deletions plugins/builds/subcommands/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"

cmd-builds-output() {
declare desc="shows build output"
declare cmd="builds:output"
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1" DEPLOY_ID="$2"
verify_app_name "$APP"

if [[ -z "$DEPLOY_ID" ]] || [[ "$DEPLOY_ID" == "current" ]]; then
local APP_DEPLOY_LOCK_FILE PROCESS_ID
APP_DEPLOY_LOCK_FILE="$DOKKU_ROOT/$APP/.deploy.lock"
if [[ ! -f "$APP_DEPLOY_LOCK_FILE" ]]; then
dokku_log_info1 "App not currently deploying"
return
fi

DEPLOY_ID="$(cat "$APP_DEPLOY_LOCK_FILE")"
if [[ -z "$DEPLOY_ID" ]]; then
dokku_log_info1 "No matching app deploy found"
return
fi
fi

if [[ -z "$DEPLOY_ID" ]]; then
dokku_log_fail "No deploy id specified"
return 1
fi

if [[ -x /usr/bin/systemctl ]] || [[ -x /usr/local/bin/systemctl ]]; then
journalctl -n1000 -f -b -a -o cat "SYSLOG_IDENTIFIER=dokku-${DEPLOY_ID}"
else
grep "dokku-${DEPLOY_ID}" /var/log/syslog
fi
}

cmd-builds-output "$@"
15 changes: 15 additions & 0 deletions plugins/builds/subcommands/report
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"

cmd-builds-report() {
declare desc="displays a build report for one or more apps"
declare cmd="builds:report"
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1"
verify_app_name "$APP"

}

cmd-builds-report "$@"
5 changes: 5 additions & 0 deletions plugins/common/functions
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,11 @@ release_and_deploy() {
declare desc="main function for releasing and deploying an app"
source "$PLUGIN_AVAILABLE_PATH/config/functions"

if [[ "$DOKKU_REDIRECT_OUTPUT" != "true" ]]; then
export DOKKU_REDIRECT_OUTPUT=true
exec &> >(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")
Expand Down
18 changes: 18 additions & 0 deletions plugins/git/internal-functions
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions plugins/git/receive-app
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?
}
Expand Down