diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index a9d211c34..1f2c8c6a5 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -1800,6 +1800,21 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # TODO ``` +### `ps-current-scale` + +- Description: Prints out the current scale contents (process-type=quantity) delimited by newlines. +- Invoked by: +- Arguments: `$APP` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + ### `receive-app` - Description: Allows you to customize what occurs when an app is received. Normally just triggers an app build. diff --git a/plugins/checks/subcommands/run b/plugins/checks/subcommands/run index 3c5b747a1..b774c7977 100755 --- a/plugins/checks/subcommands/run +++ b/plugins/checks/subcommands/run @@ -7,7 +7,6 @@ source "$PLUGIN_AVAILABLE_PATH/checks/functions" check_all_processes() { local APP="$1" CHECK_PROC_TYPE="$2" - local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" local VALID_CHECK_PROC_TYPE=false local line @@ -30,7 +29,7 @@ check_all_processes() { fi check_process_type "$APP" "$PROC_TYPE" "$PROC_COUNT" - done <"$DOKKU_SCALE_FILE" + done <"$(plugn trigger ps-current-scale "$APP")" if [[ "$VALID_CHECK_PROC_TYPE" == "false" ]]; then dokku_log_fail "Invalid process type specified ($APP.$CHECK_PROC_TYPE)" diff --git a/plugins/network/network.go b/plugins/network/network.go index b7d77e8fd..39d14efb1 100644 --- a/plugins/network/network.go +++ b/plugins/network/network.go @@ -34,6 +34,22 @@ var ( } ) +func parseScaleOutput(b []byte) (map[string]int, error) { + scale := make(map[string]int) + + for _, line := range strings.Split(string(b), "\n") { + s := strings.Split(line, "=") + processType := s[0] + count, err := strconv.Atoi(s[1]) + if err != nil { + return scale, err + } + scale[processType] = count + } + + return scale, nil +} + // BuildConfig builds network config files func BuildConfig(appName string) error { if !common.IsDeployed(appName) { @@ -41,34 +57,25 @@ func BuildConfig(appName string) error { } appRoot := common.AppRoot(appName) - scaleFile := strings.Join([]string{appRoot, "DOKKU_SCALE"}, "/") - if !common.FileExists(scaleFile) { + s, err := common.PlugnTriggerOutput("ps-current-scale", []string{appName}...) + if err != nil { + return err + } + + scale, err := parseScaleOutput(s) + if err != nil { + return err + } + + if len(scale) == 0 { return nil } image := common.GetAppImageName(appName, "", "") isHerokuishContainer := common.IsImageHerokuishBased(image, appName) common.LogInfo1(fmt.Sprintf("Ensuring network configuration is in sync for %s", appName)) - lines, err := common.FileToSlice(scaleFile) - if err != nil { - return err - } - - for _, line := range lines { - if line == "" || strings.HasPrefix(line, "#") { - continue - } - - procParts := strings.SplitN(line, "=", 2) - if len(procParts) != 2 { - continue - } - processType := procParts[0] - procCount, err := strconv.Atoi(procParts[1]) - if err != nil { - continue - } + for processType, procCount := range scale { containerIndex := 0 for containerIndex < procCount { containerIndex++ diff --git a/plugins/nginx-vhosts/functions b/plugins/nginx-vhosts/functions index d5092d1c9..d1f776eda 100755 --- a/plugins/nginx-vhosts/functions +++ b/plugins/nginx-vhosts/functions @@ -510,7 +510,6 @@ nginx_build_config() { PROXY_X_FORWARDED_PROTO="$PROXY_X_FORWARDED_PROTO" PROXY_X_FORWARDED_SSL="$PROXY_X_FORWARDED_SSL") - local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" while read -r line || [[ -n "$line" ]]; do [[ "$line" =~ ^#.* ]] && continue line="$(strip_inline_comments "$line")" @@ -519,7 +518,7 @@ nginx_build_config() { UPP_PROC_TYPE="${PROC_TYPE^^}" UPP_PROC_TYPE="${UPP_PROC_TYPE//-/_}" SIGIL_PARAMS+=("DOKKU_APP_${UPP_PROC_TYPE}_LISTENERS=$LISTENERS") - done <"$DOKKU_SCALE_FILE" + done <"$(plugn trigger ps-current-scale "$APP")" if grep DOKKU_APP_LISTENERS "$NGINX_TEMPLATE"; then dokku_log_warn "Deprecated: Usage of DOKKU_APP_LISTENERS within nginx.conf.sigil templates is deprecated in favor of DOKKU_APP_WEB_LISTENERS" diff --git a/plugins/ps/Makefile b/plugins/ps/Makefile index 0761c2505..e2a68b39a 100644 --- a/plugins/ps/Makefile +++ b/plugins/ps/Makefile @@ -1,5 +1,5 @@ SUBCOMMANDS = subcommands/inspect subcommands/rebuild subcommands/report subcommands/restart subcommands/restore subcommands/retire subcommands/scale subcommands/set subcommands/start subcommands/stop -TRIGGERS = triggers/app-restart triggers/core-post-deploy triggers/core-post-extract triggers/install triggers/post-app-clone triggers/post-app-clone-setup triggers/post-app-rename triggers/post-app-rename-setup triggers/post-create triggers/post-delete triggers/post-extract triggers/post-stop triggers/pre-deploy triggers/procfile-extract triggers/procfile-get-command triggers/procfile-remove triggers/report +TRIGGERS = triggers/app-restart triggers/core-post-deploy triggers/core-post-extract triggers/install triggers/post-app-clone triggers/post-app-clone-setup triggers/post-app-rename triggers/post-app-rename-setup triggers/post-create triggers/post-delete triggers/post-extract triggers/post-stop triggers/pre-deploy triggers/procfile-extract triggers/procfile-get-command triggers/procfile-remove triggers/ps-current-scale triggers/report BUILD = commands subcommands triggers PLUGIN_NAME = ps diff --git a/plugins/ps/src/triggers/triggers.go b/plugins/ps/src/triggers/triggers.go index 35d3bc675..161521ea9 100644 --- a/plugins/ps/src/triggers/triggers.go +++ b/plugins/ps/src/triggers/triggers.go @@ -75,6 +75,9 @@ func main() { case "procfile-remove": appName := flag.Arg(0) err = ps.TriggerProcfileRemove(appName) + case "ps-current-scale": + appName := flag.Arg(0) + err = ps.TriggerPsCurrentScale(appName) case "report": appName := flag.Arg(0) err = ps.ReportSingleApp(appName, "", "") diff --git a/plugins/ps/triggers.go b/plugins/ps/triggers.go index af6fd2cca..b5044659d 100644 --- a/plugins/ps/triggers.go +++ b/plugins/ps/triggers.go @@ -5,6 +5,7 @@ import ( "os" "path" "path/filepath" + "sort" "strings" sh "github.com/codeskyblue/go-sh" @@ -263,3 +264,18 @@ func TriggerProcfileGetCommand(appName string, processType string, port int) err func TriggerProcfileRemove(appName string) error { return removeProcfile(appName) } + +// TriggerPsCurrentScale prints out the current scale contents (process-type=quantity) delimited by newlines +func TriggerPsCurrentScale(appName string) error { + formations, err := getFormations(appName) + if err != nil { + return err + } + + sort.Sort(formations) + for _, formation := range formations { + fmt.Printf("%s=%d\n", formation.ProcessType, formation.Quantity) + } + + return nil +} diff --git a/plugins/scheduler-docker-local/core-post-deploy b/plugins/scheduler-docker-local/core-post-deploy index 4edb1f656..d29f72b02 100755 --- a/plugins/scheduler-docker-local/core-post-deploy +++ b/plugins/scheduler-docker-local/core-post-deploy @@ -16,7 +16,7 @@ trigger-scheduler-docker-local-core-post-deploy() { fi dokku_log_info1 "Renaming containers" - local PROCTYPES="$(grep -v -E "^#" "$DOKKU_ROOT/$APP/DOKKU_SCALE" | awk -F '=' '{ print $1 }' | xargs)" + local PROCTYPES="$(plugn trigger ps-current-scale "$APP" | awk -F '=' '{ print $1 }' | xargs)" local CONTAINER_FILES="$(find "$DOKKU_ROOT/$APP" -maxdepth 1 -name "CONTAINER.*" -printf "%f\n" 2>/dev/null | sort -t . -k 3 -n | xargs)" local CONTAINER_FILE diff --git a/plugins/scheduler-docker-local/scheduler-deploy b/plugins/scheduler-docker-local/scheduler-deploy index fb6e4dafe..13d17345a 100755 --- a/plugins/scheduler-docker-local/scheduler-deploy +++ b/plugins/scheduler-docker-local/scheduler-deploy @@ -29,7 +29,6 @@ trigger-scheduler-docker-local-scheduler-deploy() { local IMAGE_SOURCE_TYPE="dockerfile" [[ "$DOKKU_HEROKUISH" == "true" ]] && IMAGE_SOURCE_TYPE="herokuish" [[ "$DOKKU_CNB" == "true" ]] && IMAGE_SOURCE_TYPE="pack" - local DOKKU_SCALE_FILE="$DOKKU_ROOT/$APP/DOKKU_SCALE" local oldids=$(get_app_container_ids "$APP") DOKKU_NETWORK_BIND_ALL="$(plugn trigger network-get-property "$APP" bind-all-interfaces)" @@ -178,7 +177,7 @@ trigger-scheduler-docker-local-scheduler-deploy() { cd "$DOKKU_ROOT/$APP" find . -maxdepth 1 -name "$container_state_filetype.$PROC_TYPE.*" -printf "%f\n" | sort -t . -k 3 -n | tail -n +$CONTAINER_IDX_OFFSET | xargs rm -f done - done <"$DOKKU_SCALE_FILE" + done <"$(plugn trigger ps-current-scale "$APP")" dokku_log_info1 "Running post-deploy" plugn trigger core-post-deploy "$APP" "$port" "$ipaddr" "$IMAGE_TAG"