fix: treat empty ps restart-policy as an unset
`dokku ps:set <app> restart-policy` with no value erroneously returned `Invalid restart-policy specified` instead of unsetting the property like every other ps property. The restart policy is now managed as a normal app and global property surfaced through the `--ps-restart-policy`, `--ps-global-restart-policy`, and `--ps-computed-restart-policy` report flags, with the effective value applied at deploy time and existing values migrated on install. Because it is no longer stored as a Docker option it no longer appears in `docker-options:report`, and `--ps-restart-policy` now reports the raw value with the `on-failure:10` default available via `--ps-computed-restart-policy`.
This commit is contained in:
@@ -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-release-builder triggers/post-stop triggers/procfile-get-command triggers/procfile-exists triggers/ps-can-scale triggers/ps-current-scale triggers/ps-get-property triggers/ps-set-scale triggers/report
|
||||
TRIGGERS = triggers/app-restart triggers/core-post-deploy triggers/core-post-extract triggers/docker-args-process-deploy 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-release-builder triggers/post-stop triggers/procfile-get-command triggers/procfile-exists triggers/ps-can-scale triggers/ps-current-scale triggers/ps-get-property triggers/ps-set-scale triggers/report
|
||||
BUILD = commands subcommands triggers
|
||||
PLUGIN_NAME = ps
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ var (
|
||||
// GlobalProperties is a map of all valid global ps properties
|
||||
GlobalProperties = map[string]bool{
|
||||
"procfile-path": true,
|
||||
"restart-policy": true,
|
||||
"skip-deploy": true,
|
||||
"stop-timeout-seconds": true,
|
||||
}
|
||||
|
||||
@@ -20,9 +20,11 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
|
||||
if appName == "--global" {
|
||||
flags = map[string]common.ReportFunc{
|
||||
"--ps-computed-procfile-path": reportComputedProcfilePath,
|
||||
"--ps-computed-restart-policy": reportComputedRestartPolicy,
|
||||
"--ps-computed-skip-deploy": reportComputedSkipDeploy,
|
||||
"--ps-computed-stop-timeout-seconds": reportComputedStopTimeoutSeconds,
|
||||
"--ps-global-procfile-path": reportGlobalProcfilePath,
|
||||
"--ps-global-restart-policy": reportGlobalRestartPolicy,
|
||||
"--ps-global-skip-deploy": reportGlobalSkipDeploy,
|
||||
"--ps-global-stop-timeout-seconds": reportGlobalStopTimeoutSeconds,
|
||||
}
|
||||
@@ -33,11 +35,13 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
|
||||
"--ps-can-scale": reportCanScale,
|
||||
"--ps-computed-dockerfile-start-cmd": reportComputedDockerfileStartCmd,
|
||||
"--ps-computed-procfile-path": reportComputedProcfilePath,
|
||||
"--ps-computed-restart-policy": reportComputedRestartPolicy,
|
||||
"--ps-computed-skip-deploy": reportComputedSkipDeploy,
|
||||
"--ps-computed-start-cmd": reportComputedStartCmd,
|
||||
"--ps-computed-stop-timeout-seconds": reportComputedStopTimeoutSeconds,
|
||||
"--ps-dockerfile-start-cmd": reportDockerfileStartCmd,
|
||||
"--ps-global-procfile-path": reportGlobalProcfilePath,
|
||||
"--ps-global-restart-policy": reportGlobalRestartPolicy,
|
||||
"--ps-global-skip-deploy": reportGlobalSkipDeploy,
|
||||
"--ps-global-stop-timeout-seconds": reportGlobalStopTimeoutSeconds,
|
||||
"--ps-procfile-path": reportProcfilePath,
|
||||
@@ -162,13 +166,24 @@ func reportProcesses(appName string) string {
|
||||
return strconv.Itoa(count)
|
||||
}
|
||||
|
||||
func reportRestartPolicy(appName string) string {
|
||||
policy, _ := getRestartPolicy(appName)
|
||||
if policy == "" {
|
||||
policy = DefaultProperties["restart-policy"]
|
||||
func reportComputedRestartPolicy(appName string) string {
|
||||
value := reportRestartPolicy(appName)
|
||||
if value == "" {
|
||||
value = reportGlobalRestartPolicy(appName)
|
||||
}
|
||||
if value == "" {
|
||||
value = DefaultProperties["restart-policy"]
|
||||
}
|
||||
|
||||
return policy
|
||||
return value
|
||||
}
|
||||
|
||||
func reportGlobalRestartPolicy(appName string) string {
|
||||
return common.PropertyGet("ps", "--global", "restart-policy")
|
||||
}
|
||||
|
||||
func reportRestartPolicy(appName string) string {
|
||||
return common.PropertyGet("ps", appName, "restart-policy")
|
||||
}
|
||||
|
||||
func reportRestore(appName string) string {
|
||||
|
||||
@@ -28,6 +28,9 @@ func main() {
|
||||
appName := flag.Arg(0)
|
||||
sourceWorkDir := flag.Arg(1)
|
||||
err = ps.TriggerCorePostExtract(appName, sourceWorkDir)
|
||||
case "docker-args-process-deploy":
|
||||
appName := flag.Arg(0)
|
||||
err = ps.TriggerDockerArgsProcessDeploy(appName)
|
||||
case "install":
|
||||
err = ps.TriggerInstall()
|
||||
case "post-app-clone":
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
dockeroptions "github.com/dokku/dokku/plugins/docker-options"
|
||||
"github.com/gofrs/flock"
|
||||
)
|
||||
|
||||
@@ -184,13 +183,8 @@ func CommandScale(appName string, skipDeploy bool, processTuples []string) error
|
||||
|
||||
// CommandSet sets or clears a ps property for an app
|
||||
func CommandSet(appName string, property string, value string) error {
|
||||
if property == "restart-policy" {
|
||||
if !isValidRestartPolicy(value) {
|
||||
return errors.New("Invalid restart-policy specified")
|
||||
}
|
||||
|
||||
common.LogInfo2Quiet(fmt.Sprintf("Setting %s to %s", property, value))
|
||||
return dockeroptions.SetDockerOptionForPhases(appName, []string{"deploy"}, "restart", value)
|
||||
if property == "restart-policy" && value != "" && !isValidRestartPolicy(value) {
|
||||
return errors.New("Invalid restart-policy specified")
|
||||
}
|
||||
|
||||
common.CommandPropertySet("ps", appName, property, value, DefaultProperties, GlobalProperties)
|
||||
|
||||
@@ -3,6 +3,7 @@ package ps
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -39,6 +40,24 @@ func TriggerCorePostDeploy(appName string) error {
|
||||
return common.PropertyWrite("ps", appName, "restore", "true")
|
||||
}
|
||||
|
||||
// TriggerDockerArgsProcessDeploy injects the computed restart policy as a
|
||||
// `--restart=` docker option at deploy time. The value is no longer persisted
|
||||
// in the docker-options store; it is derived from the app/global restart-policy
|
||||
// property on every deploy.
|
||||
func TriggerDockerArgsProcessDeploy(appName string) error {
|
||||
stdin, err := io.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := os.Stdout.Write(stdin); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf(" --restart=%s", reportComputedRestartPolicy(appName))
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerCorePostExtract ensures that the main Procfile is the one specified by procfile-path
|
||||
func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
|
||||
destination := common.GetAppDataDirectory("ps", appName)
|
||||
@@ -104,16 +123,22 @@ func TriggerInstall() error {
|
||||
}
|
||||
|
||||
for _, appName := range apps {
|
||||
policies, err := getRestartPolicy(appName)
|
||||
policy, err := getRestartPolicy(appName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(policies) != 0 {
|
||||
if policy == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := dockeroptions.AddDockerOptionToPhases(appName, []string{"deploy"}, "--restart=on-failure:10"); err != nil {
|
||||
if policy != DefaultProperties["restart-policy"] {
|
||||
if err := common.PropertyWrite("ps", appName, "restart-policy", policy); err != nil {
|
||||
common.LogWarn(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if err := dockeroptions.RemoveDockerOptionFromPhases(appName, []string{"deploy"}, fmt.Sprintf("--restart=%s", policy)); err != nil {
|
||||
common.LogWarn(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -210,13 +235,8 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
|
||||
return common.CloneAppData("ps", oldAppName, newAppName)
|
||||
}
|
||||
|
||||
// TriggerPostCreate ensures apps have a default restart policy
|
||||
// and scale value for web
|
||||
// TriggerPostCreate ensures apps have a default scale value for web
|
||||
func TriggerPostCreate(appName string) error {
|
||||
if err := dockeroptions.AddDockerOptionToPhases(appName, []string{"deploy"}, "--restart=on-failure:10"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := common.CreateAppDataDirectory("ps", appName); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -319,6 +339,7 @@ func TriggerPsSetScale(appName string, skipDeploy bool, clearExisting bool, proc
|
||||
|
||||
func TriggerPsGetProperty(appName string, property string) error {
|
||||
computedValueMap := map[string]common.ReportFunc{
|
||||
"restart-policy": reportComputedRestartPolicy,
|
||||
"restore": reportRestore,
|
||||
"skip-deploy": reportComputedSkipDeploy,
|
||||
"stop-timeout-seconds": reportComputedStopTimeoutSeconds,
|
||||
|
||||
Reference in New Issue
Block a user