From ab1f8bfd30d04166aafd7fc245829c6a95d07016 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 11 Feb 2024 21:03:50 -0500 Subject: [PATCH 1/8] chore: remove unused code in ps plugin --- plugins/ps/functions.go | 24 ------------------------ plugins/ps/go.mod | 2 +- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/plugins/ps/functions.go b/plugins/ps/functions.go index c13005cf1..d042e511c 100644 --- a/plugins/ps/functions.go +++ b/plugins/ps/functions.go @@ -12,7 +12,6 @@ import ( "github.com/dokku/dokku/plugins/common" dockeroptions "github.com/dokku/dokku/plugins/docker-options" - "github.com/ryanuber/columnize" ) func canScaleApp(appName string) bool { @@ -20,24 +19,6 @@ func canScaleApp(appName string) bool { 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) { if !common.FileExists(procfilePath) { return "", errors.New("No procfile found") @@ -229,11 +210,6 @@ func scaleReport(appName string) error { } common.LogInfo1Quiet(fmt.Sprintf("Scaling for %s", appName)) - config := columnize.DefaultConfig() - config.Delim = "=" - config.Glue = ": " - config.Prefix = " " - config.Empty = "" content := []string{} if os.Getenv("DOKKU_QUIET_OUTPUT") == "" { diff --git a/plugins/ps/go.mod b/plugins/ps/go.mod index a088fa6e5..c3a0d29df 100644 --- a/plugins/ps/go.mod +++ b/plugins/ps/go.mod @@ -8,7 +8,6 @@ require ( 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/gofrs/flock v0.8.1 - github.com/ryanuber/columnize v2.1.2+incompatible github.com/spf13/pflag v1.0.5 ) @@ -26,6 +25,7 @@ require ( github.com/otiai10/copy v1.14.0 // indirect github.com/pkg/errors v0.9.1 // 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/sync v0.6.0 // indirect golang.org/x/sys v0.17.0 // indirect From 66f46de2fd986442f3e293c4eb42856cc6b94269 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 11 Feb 2024 21:06:28 -0500 Subject: [PATCH 2/8] fix: ensure each entry in a process type has whitespace removed --- plugins/ps/functions.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/ps/functions.go b/plugins/ps/functions.go index d042e511c..03d947fd7 100644 --- a/plugins/ps/functions.go +++ b/plugins/ps/functions.go @@ -130,8 +130,8 @@ func parseProcessTuples(processTuples []string) (FormationSlice, error) { return formations, fmt.Errorf("Missing count for process type %s", processTuple) } - processType := s[0] - quantity, err := strconv.Atoi(s[1]) + processType := strings.TrimSpace(s[0]) + quantity, err := strconv.Atoi(strings.TrimSpace(s[1])) if err != nil { return formations, fmt.Errorf("Invalid count for process type %s", s[0]) } From 701f18a69c4de78f9508958c9a2a4aa97b996eec Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 11 Feb 2024 21:11:40 -0500 Subject: [PATCH 3/8] fix: ensure splitting only ever returns at most two parts --- plugins/ps/functions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ps/functions.go b/plugins/ps/functions.go index 03d947fd7..4db5ec3c9 100644 --- a/plugins/ps/functions.go +++ b/plugins/ps/functions.go @@ -125,7 +125,7 @@ func parseProcessTuples(processTuples []string) (FormationSlice, error) { formations := FormationSlice{} for _, processTuple := range processTuples { - s := strings.Split(processTuple, "=") + s := strings.SplitN(processTuple, "=", 2) if len(s) == 1 { return formations, fmt.Errorf("Missing count for process type %s", processTuple) } From 0102d219f3e41ed81c55bbf4db0ac676c367056d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 11 Feb 2024 21:12:15 -0500 Subject: [PATCH 4/8] refactor: do not ever return duplicate entries when getting formations --- plugins/ps/functions.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/plugins/ps/functions.go b/plugins/ps/functions.go index 4db5ec3c9..f12ab5e36 100644 --- a/plugins/ps/functions.go +++ b/plugins/ps/functions.go @@ -124,6 +124,7 @@ func isValidRestartPolicy(policy string) bool { func parseProcessTuples(processTuples []string) (FormationSlice, error) { formations := FormationSlice{} + foundFormations := map[string]bool{} for _, processTuple := range processTuples { s := strings.SplitN(processTuple, "=", 2) if len(s) == 1 { @@ -136,6 +137,11 @@ func parseProcessTuples(processTuples []string) (FormationSlice, error) { return formations, fmt.Errorf("Invalid count for process type %s", s[0]) } + if foundFormations[processType] { + continue + } + + foundFormations[processType] = true formations = append(formations, &Formation{ ProcessType: processType, Quantity: quantity, @@ -192,7 +198,21 @@ func getFormations(appName string) (FormationSlice, error) { 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) + } + + return formations, nil } func restorePrep() error { From 31abd7e31e5b9da02960323c6dfa93efea496671 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 11 Feb 2024 21:12:25 -0500 Subject: [PATCH 5/8] chore: always sort returned formations --- plugins/ps/functions.go | 2 +- plugins/ps/triggers.go | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/ps/functions.go b/plugins/ps/functions.go index f12ab5e36..ca7b52e49 100644 --- a/plugins/ps/functions.go +++ b/plugins/ps/functions.go @@ -212,6 +212,7 @@ func getFormations(appName string) (FormationSlice, error) { formations = append(formations, formation) } + sort.Sort(formations) return formations, nil } @@ -236,7 +237,6 @@ func scaleReport(appName string) error { content = append(content, "proctype=qty", "--------=---") } - sort.Sort(formations) for _, formation := range formations { content = append(content, fmt.Sprintf("%s=%d", formation.ProcessType, formation.Quantity)) } diff --git a/plugins/ps/triggers.go b/plugins/ps/triggers.go index 38d91ec1a..f7aaab99f 100644 --- a/plugins/ps/triggers.go +++ b/plugins/ps/triggers.go @@ -6,7 +6,6 @@ import ( "os" "path" "path/filepath" - "sort" "strconv" "strings" @@ -298,7 +297,6 @@ func TriggerPsCurrentScale(appName string) error { return err } - sort.Sort(formations) lines := []string{} for _, formation := range formations { lines = append(lines, fmt.Sprintf("%s=%d", formation.ProcessType, formation.Quantity)) From 3adb7b615afbd35506bd6ca53adc1e32f5f5bf5c Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 11 Feb 2024 21:56:18 -0500 Subject: [PATCH 6/8] feat: add test for scale formatting issues --- tests/unit/ps-general-1.bats | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/unit/ps-general-1.bats b/tests/unit/ps-general-1.bats index 2f568ab7f..3e34703b0 100644 --- a/tests/unit/ps-general-1.bats +++ b/tests/unit/ps-general-1.bats @@ -71,6 +71,7 @@ EOF run /bin/bash -c "dokku --quiet ps:scale $TEST_APP" output=$(echo "$output" | tr -s " ") echo "output: ($output)" + echo "status: $status" assert_output $'cron: 0\ncustom: 0\nrelease: 0\nweb: 1\nworker: 0' pushd $TMP @@ -81,12 +82,25 @@ EOF run /bin/bash -c "dokku --quiet ps:scale $TEST_APP" output=$(echo "$output" | tr -s " ") echo "output: ($output)" + echo "status: $status" assert_output $'cron: 0\ncustom: 0\nrelease: 0\nscaletest: 0\nweb: 1\nworker: 0' popd 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" { run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP procfile_line_endings_to_windows echo "output: $output" From a5a05c2c443d54985842bdb6ffc0a5e140920a04 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 11 Feb 2024 22:01:20 -0500 Subject: [PATCH 7/8] chore: update procfile-util dependency Also run formatting against the file. --- contrib/dependencies.json | 210 +++++++++++++++++++------------------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/contrib/dependencies.json b/contrib/dependencies.json index 6559cf687..797ae125a 100644 --- a/contrib/dependencies.json +++ b/contrib/dependencies.json @@ -1,107 +1,107 @@ { - "dependencies": [ - { - "name": "docker-image-labeler", - "version": "0.6.1", - "urls": { - "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", - "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", - "version": "0.7.2", - "urls": { - "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", - "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", - "version": "0.5.0", - "urls": { - "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", - "arm": "https://github.com/dokku/lambda-builder/releases/download/v0.5.0/lambda-builder_0.5.0_linux_armhf.tgz" - } - }, - { - "name": "netrc", - "version": "0.7.1", - "urls": { - "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", - "arm": "https://github.com/dokku/netrc/releases/download/v0.7.1/netrc_0.7.1_linux_armhf.tgz" - } - }, - { - "name": "procfile-util", - "version": "0.16.0", - "urls": { - "amd64": "https://github.com/dokku/procfile-util/releases/download/v0.16.0/procfile-util_0.16.0_linux_amd64.tgz", - "arm64": "https://github.com/dokku/procfile-util/releases/download/v0.16.0/procfile-util_0.16.0_linux_arm64.tgz", - "arm": "https://github.com/dokku/procfile-util/releases/download/v0.16.0/procfile-util_0.16.0_linux_armhf.tgz" - } - }, - { - "name": "sshcommand", - "version": "0.17.1", - "urls": { - "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", - "arm": "https://github.com/dokku/sshcommand/releases/download/v0.17.1/sshcommand_0.17.1_linux_x86_64.tgz" - } - } - ], - "predependencies": [ - { - "name": "gliderlabs-sigil", - "version": "0.10.1", - "urls": { - "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", - "arm": "https://github.com/gliderlabs/sigil/releases/download/v0.10.1/gliderlabs-sigil_0.10.1_linux_armhf.tgz" - } - }, - { - "name": "plugn", - "version": "0.12.0", - "urls": { - "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", - "arm": "https://github.com/dokku/plugn/releases/download/v0.12.0/plugn_0.12.0_linux_armhf.tgz" - } - } - ], - "recommendations": [ - { - "name": "dokku-event-listener", - "version": "0.15.0", - "urls": { - "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", - "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", - "version": "0.7.2", - "urls": { - "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", - "arm": "https://github.com/dokku/dokku-update/releases/download/v0.7.2/dokku-update_0.7.2_linux_x86_64.tgz" - } - }, - { - "name": "herokuish", - "version": "0.7.1", - "urls": { - "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", - "arm": "https://github.com/gliderlabs/herokuish/releases/download/v0.7.1/herokuish_0.7.1_linux_x86_64.tgz" - } - } - ] + "dependencies": [ + { + "name": "docker-image-labeler", + "version": "0.6.1", + "urls": { + "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", + "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", + "version": "0.7.2", + "urls": { + "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", + "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", + "version": "0.5.0", + "urls": { + "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", + "arm": "https://github.com/dokku/lambda-builder/releases/download/v0.5.0/lambda-builder_0.5.0_linux_armhf.tgz" + } + }, + { + "name": "netrc", + "version": "0.7.1", + "urls": { + "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", + "arm": "https://github.com/dokku/netrc/releases/download/v0.7.1/netrc_0.7.1_linux_armhf.tgz" + } + }, + { + "name": "procfile-util", + "version": "0.17.1", + "urls": { + "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.17.1/procfile-util_0.17.1_linux_arm64.tgz", + "arm": "https://github.com/dokku/procfile-util/releases/download/v0.17.1/procfile-util_0.17.1_linux_armhf.tgz" + } + }, + { + "name": "sshcommand", + "version": "0.17.1", + "urls": { + "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", + "arm": "https://github.com/dokku/sshcommand/releases/download/v0.17.1/sshcommand_0.17.1_linux_x86_64.tgz" + } + } + ], + "predependencies": [ + { + "name": "gliderlabs-sigil", + "version": "0.10.1", + "urls": { + "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", + "arm": "https://github.com/gliderlabs/sigil/releases/download/v0.10.1/gliderlabs-sigil_0.10.1_linux_armhf.tgz" + } + }, + { + "name": "plugn", + "version": "0.12.0", + "urls": { + "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", + "arm": "https://github.com/dokku/plugn/releases/download/v0.12.0/plugn_0.12.0_linux_armhf.tgz" + } + } + ], + "recommendations": [ + { + "name": "dokku-event-listener", + "version": "0.15.0", + "urls": { + "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", + "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", + "version": "0.7.2", + "urls": { + "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", + "arm": "https://github.com/dokku/dokku-update/releases/download/v0.7.2/dokku-update_0.7.2_linux_x86_64.tgz" + } + }, + { + "name": "herokuish", + "version": "0.7.1", + "urls": { + "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", + "arm": "https://github.com/gliderlabs/herokuish/releases/download/v0.7.1/herokuish_0.7.1_linux_x86_64.tgz" + } + } + ] } From f5018ce70fe8b8e3cab960e821b218d071f19f90 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 11 Feb 2024 22:02:36 -0500 Subject: [PATCH 8/8] chore: fix shfmt issue --- tests/unit/ps-general-1.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ps-general-1.bats b/tests/unit/ps-general-1.bats index 3e34703b0..13f4d6a7a 100644 --- a/tests/unit/ps-general-1.bats +++ b/tests/unit/ps-general-1.bats @@ -93,7 +93,7 @@ EOF echo "web=4 worker=1 beat =0 -web =0" > /var/lib/dokku/config/ps/$TEST_APP/scale +web =0" >/var/lib/dokku/config/ps/$TEST_APP/scale run /bin/bash -c "dokku --quiet ps:scale $TEST_APP" echo "output: $output"