@@ -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-set-scale 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-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
|
||||
|
||||
|
||||
@@ -247,33 +247,77 @@ func scaleReport(appName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func scaleSet(appName string, skipDeploy bool, clearExisting bool, processTuples []string) error {
|
||||
formations, err := parseProcessTuples(processTuples)
|
||||
// scaleSetInput is the input for the scaleSet function
|
||||
type scaleSetInput struct {
|
||||
// appName is the name of the app to scale
|
||||
appName string
|
||||
|
||||
// skipDeploy is a flag to skip the deploy phase
|
||||
skipDeploy bool
|
||||
|
||||
// clearExisting is a flag to clear the existing scale
|
||||
clearExisting bool
|
||||
|
||||
// processTuples is a list of process tuples to scale
|
||||
processTuples []string
|
||||
|
||||
// deployOnlyChanged is a flag to deploy only the changed formations
|
||||
deployOnlyChanged bool
|
||||
}
|
||||
|
||||
func scaleSet(input scaleSetInput) error {
|
||||
existingFormations, err := getFormations(input.appName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := updateScale(appName, clearExisting, formations); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if skipDeploy {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !common.IsDeployed(appName) {
|
||||
return nil
|
||||
}
|
||||
|
||||
imageTag, err := common.GetRunningImageTag(appName, "")
|
||||
formations, err := parseProcessTuples(input.processTuples)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, formation := range formations {
|
||||
if err := updateScale(input.appName, input.clearExisting, formations); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if input.skipDeploy {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !common.IsDeployed(input.appName) {
|
||||
return nil
|
||||
}
|
||||
|
||||
imageTag, err := common.GetRunningImageTag(input.appName, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
changedFormations := FormationSlice{}
|
||||
if input.deployOnlyChanged {
|
||||
for _, formation := range formations {
|
||||
isChanged := true
|
||||
for _, existingFormation := range existingFormations {
|
||||
if existingFormation.ProcessType == formation.ProcessType {
|
||||
if existingFormation.Quantity == formation.Quantity {
|
||||
isChanged = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if isChanged {
|
||||
changedFormations = append(changedFormations, formation)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
changedFormations = formations
|
||||
}
|
||||
|
||||
for _, formation := range changedFormations {
|
||||
_, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "deploy",
|
||||
Args: []string{appName, imageTag, formation.ProcessType},
|
||||
Args: []string{input.appName, imageTag, formation.ProcessType},
|
||||
StreamStdio: true,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module github.com/dokku/dokku/plugins/ps
|
||||
|
||||
go 1.23.0
|
||||
go 1.24.0
|
||||
|
||||
require (
|
||||
github.com/dokku/dokku/plugins/common v0.0.0-00010101000000-000000000000
|
||||
|
||||
@@ -13,13 +13,15 @@ const RunInSerial = 0
|
||||
var (
|
||||
// DefaultProperties is a map of all valid ps properties with corresponding default property values
|
||||
DefaultProperties = map[string]string{
|
||||
"restart-policy": "on-failure:10",
|
||||
"procfile-path": "",
|
||||
"restart-policy": "on-failure:10",
|
||||
"procfile-path": "",
|
||||
"stop-timeout-seconds": "30",
|
||||
}
|
||||
|
||||
// GlobalProperties is a map of all valid global ps properties
|
||||
GlobalProperties = map[string]bool{
|
||||
"procfile-path": true,
|
||||
"procfile-path": true,
|
||||
"stop-timeout-seconds": true,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -15,15 +15,18 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
|
||||
}
|
||||
|
||||
flags := map[string]common.ReportFunc{
|
||||
"--deployed": reportDeployed,
|
||||
"--processes": reportProcesses,
|
||||
"--ps-can-scale": reportCanScale,
|
||||
"--ps-restart-policy": reportRestartPolicy,
|
||||
"--ps-computed-procfile-path": reportComputedProcfilePath,
|
||||
"--ps-global-procfile-path": reportGlobalProcfilePath,
|
||||
"--ps-procfile-path": reportProcfilePath,
|
||||
"--restore": reportRestore,
|
||||
"--running": reportRunningState,
|
||||
"--deployed": reportDeployed,
|
||||
"--processes": reportProcesses,
|
||||
"--ps-can-scale": reportCanScale,
|
||||
"--ps-restart-policy": reportRestartPolicy,
|
||||
"--ps-computed-procfile-path": reportComputedProcfilePath,
|
||||
"--ps-global-procfile-path": reportGlobalProcfilePath,
|
||||
"--ps-procfile-path": reportProcfilePath,
|
||||
"--restore": reportRestore,
|
||||
"--running": reportRunningState,
|
||||
"--global-stop-timeout-seconds": reportGlobalStopTimeoutSeconds,
|
||||
"--computed-stop-timeout-seconds": reportComputedStopTimeoutSeconds,
|
||||
"--stop-timeout-seconds": reportStopTimeoutSeconds,
|
||||
}
|
||||
|
||||
extraFlags := addStatusFlags(appName, infoFlag)
|
||||
@@ -146,3 +149,20 @@ func reportRestore(appName string) string {
|
||||
func reportRunningState(appName string) string {
|
||||
return getRunningState(appName)
|
||||
}
|
||||
|
||||
func reportComputedStopTimeoutSeconds(appName string) string {
|
||||
value := reportStopTimeoutSeconds(appName)
|
||||
if value == "" {
|
||||
value = reportGlobalStopTimeoutSeconds(appName)
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
func reportGlobalStopTimeoutSeconds(appName string) string {
|
||||
return common.PropertyGetDefault("ps", "--global", "stop-timeout-seconds", "30")
|
||||
}
|
||||
|
||||
func reportStopTimeoutSeconds(appName string) string {
|
||||
return common.PropertyGetDefault("ps", appName, "stop-timeout-seconds", "30")
|
||||
}
|
||||
|
||||
@@ -75,8 +75,11 @@ func main() {
|
||||
case "ps-current-scale":
|
||||
appName := flag.Arg(0)
|
||||
err = ps.TriggerPsCurrentScale(appName)
|
||||
case "ps-set-scale":
|
||||
case "ps-get-property":
|
||||
appName := flag.Arg(0)
|
||||
property := flag.Arg(1)
|
||||
err = ps.TriggerPsGetProperty(appName, property)
|
||||
case "ps-set-scale":
|
||||
appName, args := common.ShiftString(flag.Args())
|
||||
skipDeploy, args := common.ShiftString(args)
|
||||
clearExisting, processTuples := common.ShiftString(args)
|
||||
|
||||
@@ -160,7 +160,13 @@ func CommandScale(appName string, skipDeploy bool, processTuples []string) error
|
||||
}
|
||||
|
||||
common.LogInfo1(fmt.Sprintf("Scaling %s processes: %s", appName, strings.Join(processTuples, " ")))
|
||||
return scaleSet(appName, skipDeploy, false, processTuples)
|
||||
return scaleSet(scaleSetInput{
|
||||
appName: appName,
|
||||
skipDeploy: skipDeploy,
|
||||
clearExisting: false,
|
||||
processTuples: processTuples,
|
||||
deployOnlyChanged: true,
|
||||
})
|
||||
}
|
||||
|
||||
// CommandSet sets or clears a ps property for an app
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -22,22 +21,16 @@ func TriggerAppRestart(appName string) error {
|
||||
// TriggerCorePostDeploy sets a property to
|
||||
// allow the app to be restored on boot
|
||||
func TriggerCorePostDeploy(appName string) error {
|
||||
existingProcfile := getProcfilePath(appName)
|
||||
processSpecificProcfile := fmt.Sprintf("%s.%s", existingProcfile, os.Getenv("DOKKU_PID"))
|
||||
if common.FileExists(processSpecificProcfile) {
|
||||
if err := os.Rename(processSpecificProcfile, existingProcfile); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if common.FileExists(fmt.Sprintf("%s.missing", processSpecificProcfile)) {
|
||||
if err := os.Remove(fmt.Sprintf("%s.missing", processSpecificProcfile)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if common.FileExists(existingProcfile) {
|
||||
if err := os.Remove(existingProcfile); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err := common.CorePostDeploy(common.CorePostDeployInput{
|
||||
AppName: appName,
|
||||
Destination: common.GetAppDataDirectory("ps", appName),
|
||||
PluginName: "ps",
|
||||
ExtractedPaths: []common.CorePostDeployPath{
|
||||
{Path: "Procfile", IsDirectory: false},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := common.PropertyDelete("ps", appName, "scale.old"); err != nil {
|
||||
@@ -55,67 +48,45 @@ func TriggerCorePostDeploy(appName string) error {
|
||||
|
||||
// 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)
|
||||
procfilePath := strings.Trim(reportComputedProcfilePath(appName), "/")
|
||||
if procfilePath == "" {
|
||||
procfilePath = "Procfile"
|
||||
}
|
||||
|
||||
existingProcfile := getProcfilePath(appName)
|
||||
files, err := filepath.Glob(fmt.Sprintf("%s.*", existingProcfile))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, f := range files {
|
||||
if err := os.Remove(f); err != nil {
|
||||
validator := func(appName string, path string) error {
|
||||
if !common.FileExists(path) {
|
||||
return nil
|
||||
}
|
||||
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "procfile-util",
|
||||
Args: []string{"check", "-P", path},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if result.ExitCode != 0 {
|
||||
return fmt.Errorf("Invalid Procfile: %s", result.StderrContents())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
processSpecificProcfile := fmt.Sprintf("%s.%s", existingProcfile, os.Getenv("DOKKU_PID"))
|
||||
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "git-get-property",
|
||||
Args: []string{appName, "source-image"},
|
||||
return common.CorePostExtract(common.CorePostExtractInput{
|
||||
AppName: appName,
|
||||
Destination: destination,
|
||||
PluginName: "ps",
|
||||
SourceWorkDir: sourceWorkDir,
|
||||
ToExtract: []common.CorePostExtractToExtract{
|
||||
{
|
||||
Path: procfilePath,
|
||||
IsDirectory: false,
|
||||
Name: "Procfile",
|
||||
Destination: "Procfile",
|
||||
Validator: validator,
|
||||
},
|
||||
},
|
||||
})
|
||||
appSourceImage := results.StdoutContents()
|
||||
|
||||
repoDefaultProcfilePath := path.Join(sourceWorkDir, "Procfile")
|
||||
if appSourceImage == "" {
|
||||
repoProcfilePath := path.Join(sourceWorkDir, procfilePath)
|
||||
if !common.FileExists(repoProcfilePath) {
|
||||
if procfilePath != "Procfile" && common.FileExists(repoDefaultProcfilePath) {
|
||||
if err := os.Remove(repoDefaultProcfilePath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return common.TouchFile(fmt.Sprintf("%s.missing", processSpecificProcfile))
|
||||
}
|
||||
|
||||
if err := common.Copy(repoProcfilePath, processSpecificProcfile); err != nil {
|
||||
return fmt.Errorf("Unable to extract Procfile: %v", err.Error())
|
||||
}
|
||||
|
||||
if procfilePath != "Procfile" {
|
||||
if err := common.Copy(repoProcfilePath, repoDefaultProcfilePath); err != nil {
|
||||
return fmt.Errorf("Unable to move Procfile into place: %v", err.Error())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if err := common.CopyFromImage(appName, appSourceImage, procfilePath, processSpecificProcfile); err != nil {
|
||||
return common.TouchFile(fmt.Sprintf("%s.missing", processSpecificProcfile))
|
||||
}
|
||||
}
|
||||
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "procfile-util",
|
||||
Args: []string{"check", "-P", processSpecificProcfile},
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf(result.StderrContents())
|
||||
}
|
||||
if result.ExitCode != 0 {
|
||||
return fmt.Errorf("Invalid Procfile: %s", result.StderrContents())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerInstall initializes app restart policies
|
||||
@@ -164,8 +135,29 @@ func TriggerInstall() error {
|
||||
if common.FileExists(dokkuScaleExtracted) {
|
||||
os.Remove(dokkuScaleExtracted)
|
||||
}
|
||||
}
|
||||
|
||||
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "config-get",
|
||||
Args: []string{appName, "DOKKU_DOCKER_STOP_TIMEOUT"},
|
||||
})
|
||||
stopTimeout := results.StdoutContents()
|
||||
if stopTimeout == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
common.LogVerboseQuiet(fmt.Sprintf("Setting %s ps property 'stop-timeout-seconds' to %v", appName, stopTimeout))
|
||||
if err := common.PropertyWrite("ps", appName, "stop-timeout-seconds", stopTimeout); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "config-unset",
|
||||
Args: []string{appName, "DOKKU_DOCKER_STOP_TIMEOUT"},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -318,5 +310,25 @@ func TriggerPsCurrentScale(appName string) error {
|
||||
|
||||
// TriggerPsSetScale configures the scale parameters for a given app
|
||||
func TriggerPsSetScale(appName string, skipDeploy bool, clearExisting bool, processTuples []string) error {
|
||||
return scaleSet(appName, skipDeploy, clearExisting, processTuples)
|
||||
return scaleSet(scaleSetInput{
|
||||
appName: appName,
|
||||
skipDeploy: skipDeploy,
|
||||
clearExisting: clearExisting,
|
||||
processTuples: processTuples,
|
||||
deployOnlyChanged: false,
|
||||
})
|
||||
}
|
||||
|
||||
func TriggerPsGetProperty(appName string, property string) error {
|
||||
computedValueMap := map[string]common.ReportFunc{
|
||||
"stop-timeout-seconds": reportComputedStopTimeoutSeconds,
|
||||
}
|
||||
|
||||
fn, ok := computedValueMap[property]
|
||||
if !ok {
|
||||
return fmt.Errorf("Invalid network property specified: %v", property)
|
||||
}
|
||||
|
||||
fmt.Println(fn(appName))
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user