feat: add ability to increase the max parallelism when deploying a given process type
This commit is contained in:
1
plugins/20_events/app-json-process-deploy-parallelism
Symbolic link
1
plugins/20_events/app-json-process-deploy-parallelism
Symbolic link
@@ -0,0 +1 @@
|
||||
hook
|
||||
1
plugins/app-json/.gitignore
vendored
1
plugins/app-json/.gitignore
vendored
@@ -6,3 +6,4 @@
|
||||
/subcommands/*
|
||||
/triggers
|
||||
/triggers/*
|
||||
/app-json-process-deploy-parallelism
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
SUBCOMMANDS = subcommands/report subcommands/set
|
||||
TRIGGERS = triggers/install triggers/post-delete triggers/post-deploy triggers/pre-deploy triggers/report
|
||||
TRIGGERS = triggers/app-json-process-deploy-parallelism triggers/install triggers/post-delete triggers/post-deploy triggers/pre-deploy triggers/report
|
||||
BUILD = commands subcommands triggers
|
||||
PLUGIN_NAME = app-json
|
||||
|
||||
|
||||
@@ -39,7 +39,8 @@ type CronCommand struct {
|
||||
|
||||
// Formation is a struct that represents the scale for a process from an app.json file
|
||||
type Formation struct {
|
||||
Quantity int `json:"quantity"`
|
||||
Quantity *int `json:"quantity"`
|
||||
MaxParallel *int `json:"max_parallel"`
|
||||
}
|
||||
|
||||
// GetAppjsonDirectory returns the directory containing a given app's extracted app.json file
|
||||
|
||||
@@ -500,7 +500,9 @@ func setScale(appName string, image string) error {
|
||||
clearExisting := false
|
||||
args := []string{appName, strconv.FormatBool(skipDeploy), strconv.FormatBool(clearExisting)}
|
||||
for processType, formation := range appJSON.Formation {
|
||||
args = append(args, fmt.Sprintf("%s=%d", processType, formation.Quantity))
|
||||
if formation.Quantity != nil {
|
||||
args = append(args, fmt.Sprintf("%s=%d", processType, *formation.Quantity))
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 3 {
|
||||
@@ -567,7 +569,7 @@ func injectDokkuScale(appName string, image string) error {
|
||||
}
|
||||
|
||||
appJSON.Formation[processType] = Formation{
|
||||
Quantity: quantity,
|
||||
Quantity: &quantity,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@ func main() {
|
||||
|
||||
var err error
|
||||
switch trigger {
|
||||
case "app-json-process-deploy-parallelism":
|
||||
appName := flag.Arg(0)
|
||||
processType := flag.Arg(1)
|
||||
err = appjson.TriggerAppJSONProcessDeployParallelism(appName, processType)
|
||||
case "install":
|
||||
err = appjson.TriggerInstall()
|
||||
case "post-delete":
|
||||
|
||||
@@ -8,6 +8,32 @@ import (
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// TriggerAppJSONProcessDeployParallelism returns the max number of processes to deploy in parallel
|
||||
func TriggerAppJSONProcessDeployParallelism(appName string, processType string) error {
|
||||
appJSON, err := getAppJSON(appName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
parallelism := 1
|
||||
for procType, formation := range appJSON.Formation {
|
||||
if procType != processType {
|
||||
continue
|
||||
}
|
||||
|
||||
if formation.MaxParallel == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if *formation.MaxParallel > 0 {
|
||||
parallelism = *formation.MaxParallel
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(parallelism)
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerInstall initializes app restart policies
|
||||
func TriggerInstall() error {
|
||||
if err := common.PropertySetup("app-json"); err != nil {
|
||||
|
||||
@@ -27,11 +27,17 @@ main() {
|
||||
done
|
||||
fi
|
||||
|
||||
local PROCESS_TMP_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
|
||||
trap "rm -rf '$PROCESS_TMP_FILE' >/dev/null" RETURN INT TERM
|
||||
|
||||
while [[ $CONTAINER_INDEX -le $PROC_COUNT ]]; do
|
||||
export DOKKU_CHECKS_DISABLED="$DOKKU_CHECKS_DISABLED"
|
||||
"$PLUGIN_AVAILABLE_PATH/scheduler-docker-local/bin/scheduler-deploy-process-container" "$APP" "$IMAGE_SOURCE_TYPE" "$IMAGE" "$IMAGE_TAG" "$PROC_TYPE" "$PROC_COUNT" "$CONTAINER_INDEX"
|
||||
echo "$PLUGIN_AVAILABLE_PATH/scheduler-docker-local/bin/scheduler-deploy-process-container $APP $IMAGE_SOURCE_TYPE $IMAGE $IMAGE_TAG $PROC_TYPE $PROC_COUNT $CONTAINER_INDEX" >>"$PROCESS_TMP_FILE"
|
||||
CONTAINER_INDEX=$((CONTAINER_INDEX + 1))
|
||||
done
|
||||
|
||||
PARALLEL_DEPLOY_COUNT="$(plugn trigger "app-json-process-deploy-parallelism" "$APP" "$PROC_TYPE")"
|
||||
DOKKU_CHECKS_DISABLED="$DOKKU_CHECKS_DISABLED" parallel --will-cite --halt soon,fail=1 --jobs "$PARALLEL_DEPLOY_COUNT" --ungroup <"$PROCESS_TMP_FILE"
|
||||
|
||||
# cleanup when we scale down
|
||||
if [[ "$PROC_COUNT" == 0 ]]; then
|
||||
local CONTAINER_IDX_OFFSET=0
|
||||
|
||||
Reference in New Issue
Block a user