feat: add ability to deploy process types in parallel

This commit is contained in:
Jose Diaz-Gonzalez
2021-10-05 01:24:03 -04:00
parent 9e27b07772
commit 76201aed64
5 changed files with 42 additions and 13 deletions

View File

@@ -37,6 +37,29 @@ Once set, you may re-enable it by setting a blank value for `disable-chown`:
dokku scheduler-docker-local:set node-js-app disable-chown
```
### Deploying Process Types in parallel
> New as of 25.5
By default, Dokku deploys an app's processes one-by-one in order, with the `web` process being deployed first. Deployment parallelism may be achieved by setting the `parallel-schedule-count` property, which defaults to `1`. Increasing this number increases the number of process types that may be deployed in parallel (with the web process being the exception).
```shell
# Increase parallelism from 1 process type at a time to 4 process types at a time.
dokku scheduler-docker-local:set node-js-app parallel-schedule-count 4
```
Once set, you may reset it by setting a blank value for `parallel-schedule-count`:
```shell
dokku scheduler-docker-local:set node-js-app parallel-schedule-count
```
If the value of `parallel-schedule-count` is increased and a given process type fails to schedule successfully, then any in-flight process types will continue to be processed, while all process types that have not been scheduled will be skipped before the deployment finally fails.
Container scheduling output is shown in the order it is received, and thus may be out of order in case of output to stderr.
Note that increasing the value of `parallel-schedule-count` may significantly impact CPU utilization on your host as your app containers - and their respective processes - start up. Setting a value higher than the number of available CPUs is discouraged. It is recommended that users carefully set this value so as not to overburden their server.
## Implemented Triggers
This plugin implements various functionality through `plugn` triggers to integrate with Docker for running apps on a single server. The following functionality is supported by the `scheduler-docker-local` plugin.

View File

@@ -8,6 +8,7 @@ main() {
declare APP="$1" IMAGE_SOURCE_TYPE="$2" IMAGE="$3" IMAGE_TAG="$4" PROC_TYPE="$5" PROC_COUNT="$6"
local CONTAINER_INDEX=1
dokku_log_info1 "Deploying $PROC_TYPE (count=$PROC_COUNT)"
DOKKU_CHECKS_DISABLED="$(is_app_proctype_checks_disabled "$APP" "$PROC_TYPE")"
if [[ "$DOKKU_CHECKS_DISABLED" == "true" ]]; then
dokku_log_verbose "Zero downtime is disabled, stopping currently running containers ($PROC_TYPE)"

View File

@@ -38,6 +38,7 @@ cmd-scheduler-docker-local-report-single() {
verify_app_name "$APP"
local flag_map=(
"--scheduler-docker-local-disable-chown: $(fn-plugin-property-get "scheduler-docker-local" "$APP" "disable-chown" "")"
"--scheduler-docker-local-parallel-schedule-count: $(fn-plugin-property-get "scheduler-docker-local" "$APP" "parallel-schedule-count" "")"
)
if [[ -z "$INFO_FLAG" ]]; then

View File

@@ -44,24 +44,28 @@ trigger-scheduler-docker-local-scheduler-deploy() {
local WAIT="${DOKKU_WAIT_TO_RETIRE:-60}"
local TMP_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
trap "rm -rf '$TMP_FILE' >/dev/null" RETURN INT TERM
local line
local PROC_TYPE
local PROC_COUNT
local CONTAINER_INDEX
while read -r line || [[ -n "$line" ]]; do
PROC_TYPE=${line%%=*}
PROC_COUNT=${line#*=}
local PROC_TYPE=${line%%=*}
local PROC_COUNT=${line#*=}
dokku_log_info1 "Deploying $PROC_TYPE (count=$PROC_COUNT)"
export DOKKU_NETWORK_BIND_ALL="$DOKKU_NETWORK_BIND_ALL"
export DOKKU_HEROKUISH="$DOKKU_HEROKUISH"
export DOKKU_CNB="$DOKKU_CNB"
export DOCKER_RUN_LABEL_ARGS="$DOCKER_RUN_LABEL_ARGS"
export DOKKU_START_CMD="$DOKKU_START_CMD"
export DOCKER_STOP_TIME_ARG="$DOCKER_STOP_TIME_ARG"
"$PLUGIN_AVAILABLE_PATH/scheduler-docker-local/bin/scheduler-deploy-process" "$APP" "$IMAGE_SOURCE_TYPE" "$IMAGE" "$IMAGE_TAG" "$PROC_TYPE" "$PROC_COUNT"
if [[ "$PROC_TYPE" != "web" ]]; then
echo "$PLUGIN_AVAILABLE_PATH/scheduler-docker-local/bin/scheduler-deploy-process $APP $IMAGE_SOURCE_TYPE $IMAGE $IMAGE_TAG $PROC_TYPE $PROC_COUNT" >> "$TMP_FILE"
continue
fi
DOKKU_NETWORK_BIND_ALL="$DOKKU_NETWORK_BIND_ALL" DOKKU_HEROKUISH="$DOKKU_HEROKUISH" DOKKU_CNB="$DOKKU_CNB" DOCKER_RUN_LABEL_ARGS="$DOCKER_RUN_LABEL_ARGS" DOKKU_START_CMD="$DOKKU_START_CMD" DOCKER_STOP_TIME_ARG="$DOCKER_STOP_TIME_ARG" "$PLUGIN_AVAILABLE_PATH/scheduler-docker-local/bin/scheduler-deploy-process" "$APP" "$IMAGE_SOURCE_TYPE" "$IMAGE" "$IMAGE_TAG" "$PROC_TYPE" "$PROC_COUNT"
done < <(plugn trigger ps-current-scale "$APP")
PARALLEL_DEPLOY_COUNT="$(fn-plugin-property-get "scheduler-docker-local" "$APP" "parallel-schedule-count" "1")"
DOKKU_NETWORK_BIND_ALL="$DOKKU_NETWORK_BIND_ALL" DOKKU_HEROKUISH="$DOKKU_HEROKUISH" DOKKU_CNB="$DOKKU_CNB" DOCKER_RUN_LABEL_ARGS="$DOCKER_RUN_LABEL_ARGS" DOKKU_START_CMD="$DOKKU_START_CMD" DOCKER_STOP_TIME_ARG="$DOCKER_STOP_TIME_ARG" parallel --halt soon,fail=1 --jobs "$PARALLEL_DEPLOY_COUNT" --ungroup < "$TMP_FILE"
dokku_log_info1 "Running post-deploy"
plugn trigger core-post-deploy "$APP" "$port" "$ipaddr" "$IMAGE_TAG"
plugn trigger post-deploy "$APP" "$port" "$ipaddr" "$IMAGE_TAG"

View File

@@ -9,13 +9,13 @@ cmd-scheduler-docker-local-set() {
declare cmd="scheduler-docker-local:set"
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1" KEY="$2" VALUE="$3"
local VALID_KEYS=("disable-chown")
local VALID_KEYS=("disable-chown" "parallel-schedule-count")
verify_app_name "$APP"
[[ -z "$KEY" ]] && dokku_log_fail "No key specified"
if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then
dokku_log_fail "Invalid key specified, valid keys include: disable-chown"
dokku_log_fail "Invalid key specified, valid keys include: disable-chown, parallel-schedule-count"
fi
if [[ -n "$VALUE" ]]; then