feat: add --clear and --replace flags to ps:scale

The `ps:scale` command merges the specified process types into the existing formation, so replacing an entire formation from the CLI required reading the current scale, diffing it, and issuing a second call to zero out each unlisted process type. The `--replace` flag treats the specified process types as the whole formation and sets the process count for every unspecified process type to zero, while the `--clear` flag resets the formation to the scale a newly created app has. The two flags cannot be combined, `--replace` requires at least one process type, and `--clear` accepts none. Process types cleared this way are now scaled down as part of the same command rather than being left running with a stale formation.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-09-02 14:55:16 -04:00
1 parent 63351209f8
commit db45f8608b
10 files changed
+391 -21

No files matched your search

+47
View File
@@ -14,11 +14,54 @@ import (
dockeroptions "github.com/dokku/dokku/plugins/docker-options"
)
// appendClearedFormations appends a zero quantity formation for every existing
// process type that was not specified, ensuring cleared process types are both
// persisted and scaled down instead of being silently dropped
func appendClearedFormations(formations FormationSlice, existingFormations FormationSlice) FormationSlice {
specifiedProcessTypes := map[string]bool{}
for _, formation := range formations {
specifiedProcessTypes[formation.ProcessType] = true
}
for _, existingFormation := range existingFormations {
if specifiedProcessTypes[existingFormation.ProcessType] {
continue
}
specifiedProcessTypes[existingFormation.ProcessType] = true
formations = append(formations, &Formation{
ProcessType: existingFormation.ProcessType,
Quantity: 0,
})
}
return formations
}
func canScaleApp(appName string) bool {
canScale := common.PropertyGetDefault("ps", appName, "can-scale", "true")
return common.ToBool(canScale)
}
// defaultProcessTuples returns the process tuples an app is created with, scaling
// the web process to one when it is valid for the app and nothing otherwise
func defaultProcessTuples(appName string) ([]string, error) {
if !hasProcfile(appName) {
return []string{"web=1"}, nil
}
validProcessTypes, err := processesInProcfile(getProcessSpecificProcfilePath(appName))
if err != nil {
return []string{}, err
}
if !validProcessTypes["web"] {
return []string{}, nil
}
return []string{"web=1"}, nil
}
func getProcfileCommand(appName string, procfilePath string, processType string, port int) (string, error) {
if !common.FileExists(procfilePath) {
return "", errors.New("No procfile found")
@@ -308,6 +351,10 @@ func scaleSet(input scaleSetInput) error {
return err
}
if input.clearExisting {
formations = appendClearedFormations(formations, existingFormations)
}
if err := updateScale(input.appName, input.clearExisting, formations); err != nil {
return err
}