From d9af6516bbf5eeac5e07d00725b62f1f312fb5fd Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 28 Dec 2022 11:29:26 -0500 Subject: [PATCH 1/6] tests: validate that procfile-path is respected Refs #5550 --- tests/apps/python/second.Procfile | 2 +- tests/apps/python/web.py | 3 +++ tests/unit/ps-general-2.bats | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/apps/python/second.Procfile b/tests/apps/python/second.Procfile index b03a168c7..66d57acc6 100644 --- a/tests/apps/python/second.Procfile +++ b/tests/apps/python/second.Procfile @@ -1 +1 @@ -web: python3 web.py +web: python3 web.py second.Procfile diff --git a/tests/apps/python/web.py b/tests/apps/python/web.py index e14bb903c..5d7a77953 100644 --- a/tests/apps/python/web.py +++ b/tests/apps/python/web.py @@ -22,6 +22,9 @@ if __name__ == "__main__": print("Failing on startup due to FAIL_ON_STARTUP=true") sys.exit(1) + for arg in sys.argv: + print(f"Arg: {arg}") + port = int(os.getenv("PORT", 5000)) server = http.server.HTTPServer(("0.0.0.0", port), GetHandler) print("Listening on port {0}".format(port)) diff --git a/tests/unit/ps-general-2.bats b/tests/unit/ps-general-2.bats index 0fc167f5b..55dc60e8c 100644 --- a/tests/unit/ps-general-2.bats +++ b/tests/unit/ps-general-2.bats @@ -95,6 +95,13 @@ teardown() { echo "status: $status" assert_success + run /bin/bash -c "dokku logs $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_output_contains "Arg: web.py" + assert_output_contains "Arg: second.Procfile" 0 + assert_success + run /bin/bash -c "dokku ps:set $TEST_APP procfile-path nonexistent-procfile" echo "output: $output" echo "status: $status" @@ -117,6 +124,13 @@ teardown() { assert_success assert_output_contains 'SECRET_KEY:' 0 + run /bin/bash -c "dokku logs $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_output_contains "Arg: web.py" + assert_output_contains "Arg: second.Procfile" + assert_success + run /bin/bash -c "dokku ps:set $TEST_APP procfile-path" echo "output: $output" echo "status: $status" @@ -127,6 +141,13 @@ teardown() { echo "status: $status" assert_success assert_output_contains 'SECRET_KEY:' + + run /bin/bash -c "dokku logs $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_output_contains "Arg: web.py" + assert_output_contains "Arg: second.Procfile" 0 + assert_success } @test "(ps:scale) remove zerod processes" { From 21bb5ea2ed53a8e54aff1eda1248b3fc63beb65e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 28 Dec 2022 15:34:53 -0500 Subject: [PATCH 2/6] fix: delete existing Procfile if the user tried to overwrite it with a non-existing one This behavior follows what is described in the documentation. --- plugins/ps/triggers.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/ps/triggers.go b/plugins/ps/triggers.go index ee3f133c8..a5c7f317e 100644 --- a/plugins/ps/triggers.go +++ b/plugins/ps/triggers.go @@ -80,6 +80,11 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error { 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)) } From 476a4efa46b9aefbfabd8f9919edf31800f5495b Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 28 Dec 2022 15:35:26 -0500 Subject: [PATCH 3/6] fix: use -u in Procfile to unbuffer python output Without this, logs don't get written out immediately, causing tests to fail. --- tests/apps/python/Procfile | 8 ++++---- tests/apps/python/second.Procfile | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/apps/python/Procfile b/tests/apps/python/Procfile index 88d4d849f..77b9a38ff 100644 --- a/tests/apps/python/Procfile +++ b/tests/apps/python/Procfile @@ -3,11 +3,11 @@ ############################### # Procfile for development using the new threaded worker (scheduler, twitter stream and delayed job) -cron: python3 worker.py -web: python3 web.py # testing inline comment -worker: python3 worker.py +cron: python3 -u worker.py +web: python3 -u web.py first.Procfile # testing inline comment +worker: python3 -u worker.py custom: echo -n -release: python3 release.py +release: python3 -u release.py # Old version with separate processes (use this if you have issues with the threaded version) diff --git a/tests/apps/python/second.Procfile b/tests/apps/python/second.Procfile index 66d57acc6..9c0e25d2e 100644 --- a/tests/apps/python/second.Procfile +++ b/tests/apps/python/second.Procfile @@ -1 +1 @@ -web: python3 web.py second.Procfile +web: python3 -u web.py second.Procfile From 514a3efa5c96fd65dcbdb2dc3fd4425a9853aa0c Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 28 Dec 2022 15:35:56 -0500 Subject: [PATCH 4/6] fix: use the correct test app for ps-general-2 Otherwise we aren't testing the desired Procfile behavior. --- tests/unit/ps-general-2.bats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/ps-general-2.bats b/tests/unit/ps-general-2.bats index 55dc60e8c..70a869e43 100644 --- a/tests/unit/ps-general-2.bats +++ b/tests/unit/ps-general-2.bats @@ -90,7 +90,7 @@ teardown() { } @test "(ps:set) procfile-path" { - run deploy_app dockerfile-procfile + run deploy_app python echo "output: $output" echo "status: $status" assert_success @@ -99,7 +99,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_output_contains "Arg: web.py" - assert_output_contains "Arg: second.Procfile" 0 + assert_output_contains "Arg: first.Procfile" assert_success run /bin/bash -c "dokku ps:set $TEST_APP procfile-path nonexistent-procfile" @@ -146,7 +146,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_output_contains "Arg: web.py" - assert_output_contains "Arg: second.Procfile" 0 + assert_output_contains "Arg: first.Procfile" assert_success } From e01730857c0250357376ad98d015d5dfd788d69c Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 28 Dec 2022 15:36:34 -0500 Subject: [PATCH 5/6] fix: overwrite the in-repo Procfile with the desired Procfile Without this change, herokuish and pack builds would not run the correct command as the Procfile could still be the old Procfile. --- plugins/ps/triggers.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/ps/triggers.go b/plugins/ps/triggers.go index a5c7f317e..c6ef96a8e 100644 --- a/plugins/ps/triggers.go +++ b/plugins/ps/triggers.go @@ -77,6 +77,7 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error { b, _ := common.PlugnTriggerOutput("git-get-property", []string{appName, "source-image"}...) appSourceImage := strings.TrimSpace(string(b[:])) + repoDefaultProcfilePath := path.Join(sourceWorkDir, "Procfile") if appSourceImage == "" { repoProcfilePath := path.Join(sourceWorkDir, procfilePath) if !common.FileExists(repoProcfilePath) { @@ -91,6 +92,12 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error { if err := copy.Copy(repoProcfilePath, processSpecificProcfile); err != nil { return fmt.Errorf("Unable to extract Procfile: %v", err.Error()) } + + if procfilePath != "Procfile" { + if err := copy.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)) From 9f6aade092daf087f4e350a22319ee28de1e62f8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Wed, 28 Dec 2022 16:42:36 -0500 Subject: [PATCH 6/6] fix: run unbuffered --- tests/apps/python/sub-app/Procfile | 2 +- tests/unit/app-json.bats | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/apps/python/sub-app/Procfile b/tests/apps/python/sub-app/Procfile index bb1e3346a..9512e68d7 100644 --- a/tests/apps/python/sub-app/Procfile +++ b/tests/apps/python/sub-app/Procfile @@ -1,2 +1,2 @@ web: python3 web.py -release: python3 release.py +release: python3 -u release.py diff --git a/tests/unit/app-json.bats b/tests/unit/app-json.bats index 7155f59e9..3ea5fb674 100644 --- a/tests/unit/app-json.bats +++ b/tests/unit/app-json.bats @@ -52,7 +52,7 @@ teardown() { echo "status: $status" assert_success assert_output_contains "touch /app/heroku-postdeploy.test" - assert_output_contains "python3 release.py" + assert_output_contains "python3 -u release.py" } @test "(app-json) app.json scripts missing" {