Merge pull request #6582 from dokku/ps-cleanup

Correctly handle extra whitespace in scale file contents
This commit is contained in:
Jose Diaz-Gonzalez authored and GitHub committed 2024-02-11 22:48:15 -05:00
commit 03df28af87
5 files changed
+145 -137

No files matched your search

+105 -105
View File
@@ -1,107 +1,107 @@
{ {
"dependencies": [ "dependencies": [
{ {
"name": "docker-image-labeler", "name": "docker-image-labeler",
"version": "0.6.1", "version": "0.6.1",
"urls": { "urls": {
"amd64": "https://github.com/dokku/docker-image-labeler/releases/download/v0.6.1/docker-image-labeler_0.6.1_linux_amd64.tgz", "amd64": "https://github.com/dokku/docker-image-labeler/releases/download/v0.6.1/docker-image-labeler_0.6.1_linux_amd64.tgz",
"arm64": "https://github.com/dokku/docker-image-labeler/releases/download/v0.6.1/docker-image-labeler_0.6.1_linux_arm64.tgz", "arm64": "https://github.com/dokku/docker-image-labeler/releases/download/v0.6.1/docker-image-labeler_0.6.1_linux_arm64.tgz",
"arm": "https://github.com/dokku/docker-image-labeler/releases/download/v0.6.1/docker-image-labeler_0.6.1_linux_armhf.tgz" "arm": "https://github.com/dokku/docker-image-labeler/releases/download/v0.6.1/docker-image-labeler_0.6.1_linux_armhf.tgz"
} }
}, },
{ {
"name": "docker-container-healthchecker", "name": "docker-container-healthchecker",
"version": "0.7.2", "version": "0.7.2",
"urls": { "urls": {
"amd64": "https://github.com/dokku/docker-container-healthchecker/releases/download/v0.7.2/docker-container-healthchecker_0.7.2_linux_amd64.tgz", "amd64": "https://github.com/dokku/docker-container-healthchecker/releases/download/v0.7.2/docker-container-healthchecker_0.7.2_linux_amd64.tgz",
"arm64": "https://github.com/dokku/docker-container-healthchecker/releases/download/v0.7.2/docker-container-healthchecker_0.7.2_linux_arm64.tgz", "arm64": "https://github.com/dokku/docker-container-healthchecker/releases/download/v0.7.2/docker-container-healthchecker_0.7.2_linux_arm64.tgz",
"arm": "https://github.com/dokku/docker-container-healthchecker/releases/download/v0.7.2/docker-container-healthchecker_0.7.2_linux_armhf.tgz" "arm": "https://github.com/dokku/docker-container-healthchecker/releases/download/v0.7.2/docker-container-healthchecker_0.7.2_linux_armhf.tgz"
} }
}, },
{ {
"name": "lambda-builder", "name": "lambda-builder",
"version": "0.5.0", "version": "0.5.0",
"urls": { "urls": {
"amd64": "https://github.com/dokku/lambda-builder/releases/download/v0.5.0/lambda-builder_0.5.0_linux_amd64.tgz", "amd64": "https://github.com/dokku/lambda-builder/releases/download/v0.5.0/lambda-builder_0.5.0_linux_amd64.tgz",
"arm64": "https://github.com/dokku/lambda-builder/releases/download/v0.5.0/lambda-builder_0.5.0_linux_arm64.tgz", "arm64": "https://github.com/dokku/lambda-builder/releases/download/v0.5.0/lambda-builder_0.5.0_linux_arm64.tgz",
"arm": "https://github.com/dokku/lambda-builder/releases/download/v0.5.0/lambda-builder_0.5.0_linux_armhf.tgz" "arm": "https://github.com/dokku/lambda-builder/releases/download/v0.5.0/lambda-builder_0.5.0_linux_armhf.tgz"
} }
}, },
{ {
"name": "netrc", "name": "netrc",
"version": "0.7.1", "version": "0.7.1",
"urls": { "urls": {
"amd64": "https://github.com/dokku/netrc/releases/download/v0.7.1/netrc_0.7.1_linux_amd64.tgz", "amd64": "https://github.com/dokku/netrc/releases/download/v0.7.1/netrc_0.7.1_linux_amd64.tgz",
"arm64": "https://github.com/dokku/netrc/releases/download/v0.7.1/netrc_0.7.1_linux_arm64.tgz", "arm64": "https://github.com/dokku/netrc/releases/download/v0.7.1/netrc_0.7.1_linux_arm64.tgz",
"arm": "https://github.com/dokku/netrc/releases/download/v0.7.1/netrc_0.7.1_linux_armhf.tgz" "arm": "https://github.com/dokku/netrc/releases/download/v0.7.1/netrc_0.7.1_linux_armhf.tgz"
} }
}, },
{ {
"name": "procfile-util", "name": "procfile-util",
"version": "0.16.0", "version": "0.17.1",
"urls": { "urls": {
"amd64": "https://github.com/dokku/procfile-util/releases/download/v0.16.0/procfile-util_0.16.0_linux_amd64.tgz", "amd64": "https://github.com/dokku/procfile-util/releases/download/v0.17.1/procfile-util_0.17.1_linux_amd64.tgz",
"arm64": "https://github.com/dokku/procfile-util/releases/download/v0.16.0/procfile-util_0.16.0_linux_arm64.tgz", "arm64": "https://github.com/dokku/procfile-util/releases/download/v0.17.1/procfile-util_0.17.1_linux_arm64.tgz",
"arm": "https://github.com/dokku/procfile-util/releases/download/v0.16.0/procfile-util_0.16.0_linux_armhf.tgz" "arm": "https://github.com/dokku/procfile-util/releases/download/v0.17.1/procfile-util_0.17.1_linux_armhf.tgz"
} }
}, },
{ {
"name": "sshcommand", "name": "sshcommand",
"version": "0.17.1", "version": "0.17.1",
"urls": { "urls": {
"amd64": "https://github.com/dokku/sshcommand/releases/download/v0.17.1/sshcommand_0.17.1_linux_x86_64.tgz", "amd64": "https://github.com/dokku/sshcommand/releases/download/v0.17.1/sshcommand_0.17.1_linux_x86_64.tgz",
"arm64": "https://github.com/dokku/sshcommand/releases/download/v0.17.1/sshcommand_0.17.1_linux_x86_64.tgz", "arm64": "https://github.com/dokku/sshcommand/releases/download/v0.17.1/sshcommand_0.17.1_linux_x86_64.tgz",
"arm": "https://github.com/dokku/sshcommand/releases/download/v0.17.1/sshcommand_0.17.1_linux_x86_64.tgz" "arm": "https://github.com/dokku/sshcommand/releases/download/v0.17.1/sshcommand_0.17.1_linux_x86_64.tgz"
} }
} }
], ],
"predependencies": [ "predependencies": [
{ {
"name": "gliderlabs-sigil", "name": "gliderlabs-sigil",
"version": "0.10.1", "version": "0.10.1",
"urls": { "urls": {
"amd64": "https://github.com/gliderlabs/sigil/releases/download/v0.10.1/gliderlabs-sigil_0.10.1_linux_amd64.tgz", "amd64": "https://github.com/gliderlabs/sigil/releases/download/v0.10.1/gliderlabs-sigil_0.10.1_linux_amd64.tgz",
"arm64": "https://github.com/gliderlabs/sigil/releases/download/v0.10.1/gliderlabs-sigil_0.10.1_linux_arm64.tgz", "arm64": "https://github.com/gliderlabs/sigil/releases/download/v0.10.1/gliderlabs-sigil_0.10.1_linux_arm64.tgz",
"arm": "https://github.com/gliderlabs/sigil/releases/download/v0.10.1/gliderlabs-sigil_0.10.1_linux_armhf.tgz" "arm": "https://github.com/gliderlabs/sigil/releases/download/v0.10.1/gliderlabs-sigil_0.10.1_linux_armhf.tgz"
} }
}, },
{ {
"name": "plugn", "name": "plugn",
"version": "0.12.0", "version": "0.12.0",
"urls": { "urls": {
"amd64": "https://github.com/dokku/plugn/releases/download/v0.12.0/plugn_0.12.0_linux_amd64.tgz", "amd64": "https://github.com/dokku/plugn/releases/download/v0.12.0/plugn_0.12.0_linux_amd64.tgz",
"arm64": "https://github.com/dokku/plugn/releases/download/v0.12.0/plugn_0.12.0_linux_arm64.tgz", "arm64": "https://github.com/dokku/plugn/releases/download/v0.12.0/plugn_0.12.0_linux_arm64.tgz",
"arm": "https://github.com/dokku/plugn/releases/download/v0.12.0/plugn_0.12.0_linux_armhf.tgz" "arm": "https://github.com/dokku/plugn/releases/download/v0.12.0/plugn_0.12.0_linux_armhf.tgz"
} }
} }
], ],
"recommendations": [ "recommendations": [
{ {
"name": "dokku-event-listener", "name": "dokku-event-listener",
"version": "0.15.0", "version": "0.15.0",
"urls": { "urls": {
"amd64": "https://github.com/dokku/dokku-event-listener/releases/download/v0.15.0/dokku-event-listener_0.15.0_linux_amd64.tgz", "amd64": "https://github.com/dokku/dokku-event-listener/releases/download/v0.15.0/dokku-event-listener_0.15.0_linux_amd64.tgz",
"arm64": "https://github.com/dokku/dokku-event-listener/releases/download/v0.15.0/dokku-event-listener_0.15.0_linux_arm64.tgz", "arm64": "https://github.com/dokku/dokku-event-listener/releases/download/v0.15.0/dokku-event-listener_0.15.0_linux_arm64.tgz",
"arm": "https://github.com/dokku/dokku-event-listener/releases/download/v0.15.0/dokku-event-listener_0.15.0_linux_armhf.tgz" "arm": "https://github.com/dokku/dokku-event-listener/releases/download/v0.15.0/dokku-event-listener_0.15.0_linux_armhf.tgz"
} }
}, },
{ {
"name": "dokku-update", "name": "dokku-update",
"version": "0.7.2", "version": "0.7.2",
"urls": { "urls": {
"amd64": "https://github.com/dokku/dokku-update/releases/download/v0.7.2/dokku-update_0.7.2_linux_x86_64.tgz", "amd64": "https://github.com/dokku/dokku-update/releases/download/v0.7.2/dokku-update_0.7.2_linux_x86_64.tgz",
"arm64": "https://github.com/dokku/dokku-update/releases/download/v0.7.2/dokku-update_0.7.2_linux_x86_64.tgz", "arm64": "https://github.com/dokku/dokku-update/releases/download/v0.7.2/dokku-update_0.7.2_linux_x86_64.tgz",
"arm": "https://github.com/dokku/dokku-update/releases/download/v0.7.2/dokku-update_0.7.2_linux_x86_64.tgz" "arm": "https://github.com/dokku/dokku-update/releases/download/v0.7.2/dokku-update_0.7.2_linux_x86_64.tgz"
} }
}, },
{ {
"name": "herokuish", "name": "herokuish",
"version": "0.7.1", "version": "0.7.1",
"urls": { "urls": {
"amd64": "https://github.com/gliderlabs/herokuish/releases/download/v0.7.1/herokuish_0.7.1_linux_x86_64.tgz", "amd64": "https://github.com/gliderlabs/herokuish/releases/download/v0.7.1/herokuish_0.7.1_linux_x86_64.tgz",
"arm64": "https://github.com/gliderlabs/herokuish/releases/download/v0.7.1/herokuish_0.7.1_linux_x86_64.tgz", "arm64": "https://github.com/gliderlabs/herokuish/releases/download/v0.7.1/herokuish_0.7.1_linux_x86_64.tgz",
"arm": "https://github.com/gliderlabs/herokuish/releases/download/v0.7.1/herokuish_0.7.1_linux_x86_64.tgz" "arm": "https://github.com/gliderlabs/herokuish/releases/download/v0.7.1/herokuish_0.7.1_linux_x86_64.tgz"
} }
} }
] ]
} }
+25 -29
View File
@@ -12,7 +12,6 @@ import (
"github.com/dokku/dokku/plugins/common" "github.com/dokku/dokku/plugins/common"
dockeroptions "github.com/dokku/dokku/plugins/docker-options" dockeroptions "github.com/dokku/dokku/plugins/docker-options"
"github.com/ryanuber/columnize"
) )
func canScaleApp(appName string) bool { func canScaleApp(appName string) bool {
@@ -20,24 +19,6 @@ func canScaleApp(appName string) bool {
return common.ToBool(canScale) return common.ToBool(canScale)
} }
func getProcessStatus(appName string) map[string]string {
statuses := make(map[string]string)
containerFiles := common.ListFilesWithPrefix(common.AppRoot(appName), "CONTAINER.")
for _, filename := range containerFiles {
containerID := common.ReadFirstLine(filename)
containerStatus, _ := common.DockerInspect(containerID, "{{ .State.Status }}")
process := strings.TrimPrefix(filename, fmt.Sprintf("%s/CONTAINER.", common.AppRoot(appName)))
if containerStatus == "" {
containerStatus = "missing"
}
statuses[process] = fmt.Sprintf("%s (CID: %s)", containerStatus, containerID[0:11])
}
return statuses
}
func getProcfileCommand(procfilePath string, processType string, port int) (string, error) { func getProcfileCommand(procfilePath string, processType string, port int) (string, error) {
if !common.FileExists(procfilePath) { if !common.FileExists(procfilePath) {
return "", errors.New("No procfile found") return "", errors.New("No procfile found")
@@ -143,18 +124,24 @@ func isValidRestartPolicy(policy string) bool {
func parseProcessTuples(processTuples []string) (FormationSlice, error) { func parseProcessTuples(processTuples []string) (FormationSlice, error) {
formations := FormationSlice{} formations := FormationSlice{}
foundFormations := map[string]bool{}
for _, processTuple := range processTuples { for _, processTuple := range processTuples {
s := strings.Split(processTuple, "=") s := strings.SplitN(processTuple, "=", 2)
if len(s) == 1 { if len(s) == 1 {
return formations, fmt.Errorf("Missing count for process type %s", processTuple) return formations, fmt.Errorf("Missing count for process type %s", processTuple)
} }
processType := s[0] processType := strings.TrimSpace(s[0])
quantity, err := strconv.Atoi(s[1]) quantity, err := strconv.Atoi(strings.TrimSpace(s[1]))
if err != nil { if err != nil {
return formations, fmt.Errorf("Invalid count for process type %s", s[0]) return formations, fmt.Errorf("Invalid count for process type %s", s[0])
} }
if foundFormations[processType] {
continue
}
foundFormations[processType] = true
formations = append(formations, &Formation{ formations = append(formations, &Formation{
ProcessType: processType, ProcessType: processType,
Quantity: quantity, Quantity: quantity,
@@ -211,7 +198,22 @@ func getFormations(appName string) (FormationSlice, error) {
return formations, err return formations, err
} }
return append(formations, oldFormations...), nil foundProcessTypes := map[string]bool{}
for _, formation := range formations {
foundProcessTypes[formation.ProcessType] = true
}
for _, formation := range oldFormations {
if foundProcessTypes[formation.ProcessType] {
continue
}
foundProcessTypes[formation.ProcessType] = true
formations = append(formations, formation)
}
sort.Sort(formations)
return formations, nil
} }
func restorePrep() error { func restorePrep() error {
@@ -229,18 +231,12 @@ func scaleReport(appName string) error {
} }
common.LogInfo1Quiet(fmt.Sprintf("Scaling for %s", appName)) common.LogInfo1Quiet(fmt.Sprintf("Scaling for %s", appName))
config := columnize.DefaultConfig()
config.Delim = "="
config.Glue = ": "
config.Prefix = " "
config.Empty = ""
content := []string{} content := []string{}
if os.Getenv("DOKKU_QUIET_OUTPUT") == "" { if os.Getenv("DOKKU_QUIET_OUTPUT") == "" {
content = append(content, "proctype=qty", "--------=---") content = append(content, "proctype=qty", "--------=---")
} }
sort.Sort(formations)
for _, formation := range formations { for _, formation := range formations {
content = append(content, fmt.Sprintf("%s=%d", formation.ProcessType, formation.Quantity)) content = append(content, fmt.Sprintf("%s=%d", formation.ProcessType, formation.Quantity))
} }
+1 -1
View File
@@ -8,7 +8,6 @@ require (
github.com/dokku/dokku/plugins/config v0.0.0-00010101000000-000000000000 github.com/dokku/dokku/plugins/config v0.0.0-00010101000000-000000000000
github.com/dokku/dokku/plugins/docker-options v0.0.0-00010101000000-000000000000 github.com/dokku/dokku/plugins/docker-options v0.0.0-00010101000000-000000000000
github.com/gofrs/flock v0.8.1 github.com/gofrs/flock v0.8.1
github.com/ryanuber/columnize v2.1.2+incompatible
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
) )
@@ -26,6 +25,7 @@ require (
github.com/otiai10/copy v1.14.0 // indirect github.com/otiai10/copy v1.14.0 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/sftp v1.13.5 // indirect github.com/pkg/sftp v1.13.5 // indirect
github.com/ryanuber/columnize v2.1.2+incompatible // indirect
golang.org/x/crypto v0.19.0 // indirect golang.org/x/crypto v0.19.0 // indirect
golang.org/x/sync v0.6.0 // indirect golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect golang.org/x/sys v0.17.0 // indirect
-2
View File
@@ -6,7 +6,6 @@ import (
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"sort"
"strconv" "strconv"
"strings" "strings"
@@ -298,7 +297,6 @@ func TriggerPsCurrentScale(appName string) error {
return err return err
} }
sort.Sort(formations)
lines := []string{} lines := []string{}
for _, formation := range formations { for _, formation := range formations {
lines = append(lines, fmt.Sprintf("%s=%d", formation.ProcessType, formation.Quantity)) lines = append(lines, fmt.Sprintf("%s=%d", formation.ProcessType, formation.Quantity))
+14
View File
@@ -71,6 +71,7 @@ EOF
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP" run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
output=$(echo "$output" | tr -s " ") output=$(echo "$output" | tr -s " ")
echo "output: ($output)" echo "output: ($output)"
echo "status: $status"
assert_output $'cron: 0\ncustom: 0\nrelease: 0\nweb: 1\nworker: 0' assert_output $'cron: 0\ncustom: 0\nrelease: 0\nweb: 1\nworker: 0'
pushd $TMP pushd $TMP
@@ -81,12 +82,25 @@ EOF
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP" run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
output=$(echo "$output" | tr -s " ") output=$(echo "$output" | tr -s " ")
echo "output: ($output)" echo "output: ($output)"
echo "status: $status"
assert_output $'cron: 0\ncustom: 0\nrelease: 0\nscaletest: 0\nweb: 1\nworker: 0' assert_output $'cron: 0\ncustom: 0\nrelease: 0\nscaletest: 0\nweb: 1\nworker: 0'
popd popd
rm -rf "$TMP" rm -rf "$TMP"
} }
@test "(ps:scale) ps:scale formatting" {
echo "web=4
worker=1
beat =0
web =0" >/var/lib/dokku/config/ps/$TEST_APP/scale
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_output $'beat: 0\nweb: 4\nworker: 1'
}
@test "(ps) handle windows newlines in procfile" { @test "(ps) handle windows newlines in procfile" {
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP procfile_line_endings_to_windows run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP procfile_line_endings_to_windows
echo "output: $output" echo "output: $output"