From a22391b7ada8dada9027040bd6e864bc176cd01a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 10 Jul 2021 01:32:57 -0400 Subject: [PATCH] fix: copy the specified Procfile into place at the earliest possibility --- plugins/ps/.gitignore | 15 ++++++++------- plugins/ps/Makefile | 2 +- plugins/ps/functions.go | 2 +- plugins/ps/go.mod | 3 ++- plugins/ps/go.sum | 6 ++++++ plugins/ps/src/triggers/triggers.go | 4 ++++ plugins/ps/triggers.go | 27 ++++++++++++++++++++++++++- 7 files changed, 48 insertions(+), 11 deletions(-) diff --git a/plugins/ps/.gitignore b/plugins/ps/.gitignore index 528524b69..413fc555d 100644 --- a/plugins/ps/.gitignore +++ b/plugins/ps/.gitignore @@ -1,12 +1,13 @@ +/app-restart /commands -/subcommands/* -/triggers/* -/triggers -/proxy-* +/core-post-deploy +/core-post-extract /install /post-* -/report /pre-* /procfile-* -/app-restart -/core-post-deploy +/proxy-* +/report +/subcommands/* +/triggers +/triggers/* diff --git a/plugins/ps/Makefile b/plugins/ps/Makefile index b45ea6d12..0761c2505 100644 --- a/plugins/ps/Makefile +++ b/plugins/ps/Makefile @@ -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/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-extract triggers/post-stop triggers/pre-deploy triggers/procfile-extract triggers/procfile-get-command triggers/procfile-remove 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-extract triggers/post-stop triggers/pre-deploy triggers/procfile-extract triggers/procfile-get-command triggers/procfile-remove triggers/report BUILD = commands subcommands triggers PLUGIN_NAME = ps diff --git a/plugins/ps/functions.go b/plugins/ps/functions.go index 713334abc..f6a47bbe8 100644 --- a/plugins/ps/functions.go +++ b/plugins/ps/functions.go @@ -21,7 +21,7 @@ func canScaleApp(appName string) bool { func extractProcfile(appName, image string) error { destination := getProcfilePath(appName) - common.CopyFromImage(appName, image, reportComputedProcfilePath(appName), destination) + common.CopyFromImage(appName, image, "Procfile", destination) if !common.FileExists(destination) { common.LogInfo1Quiet("No Procfile found in app image") return nil diff --git a/plugins/ps/go.mod b/plugins/ps/go.mod index 946afcefc..4655cac06 100644 --- a/plugins/ps/go.mod +++ b/plugins/ps/go.mod @@ -8,8 +8,9 @@ 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.0 + github.com/otiai10/copy v1.6.0 github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 - github.com/spf13/pflag v1.0.5 // indirect + github.com/spf13/pflag v1.0.5 // indirect ) replace github.com/dokku/dokku/plugins/common => ../common diff --git a/plugins/ps/go.sum b/plugins/ps/go.sum index c6f028d99..625b68248 100644 --- a/plugins/ps/go.sum +++ b/plugins/ps/go.sum @@ -8,6 +8,12 @@ github.com/gofrs/flock v0.8.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14j github.com/joho/godotenv v1.2.0 h1:vGTvz69FzUFp+X4/bAkb0j5BoLC+9bpqTWY8mjhA9pc= github.com/joho/godotenv v1.2.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= +github.com/otiai10/copy v1.6.0 h1:IinKAryFFuPONZ7cm6T6E2QX/vcJwSnlaA5lfoaXIiQ= +github.com/otiai10/copy v1.6.0/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E= +github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= +github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs= +github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= +github.com/otiai10/mint v1.3.2/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc= github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3 h1:utdYOikI1XjNtTFGCwSM6OmFJblU4ld4gACoJsbadJg= github.com/ryanuber/columnize v1.1.2-0.20190319233515-9e6335e58db3/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= diff --git a/plugins/ps/src/triggers/triggers.go b/plugins/ps/src/triggers/triggers.go index d60afa0c4..35d3bc675 100644 --- a/plugins/ps/src/triggers/triggers.go +++ b/plugins/ps/src/triggers/triggers.go @@ -24,6 +24,10 @@ func main() { case "core-post-deploy": appName := flag.Arg(0) err = ps.TriggerCorePostDeploy(appName) + case "core-post-extract": + appName := flag.Arg(0) + sourceWorkDir := flag.Arg(1) + err = ps.TriggerCorePostExtract(appName, sourceWorkDir) case "install": err = ps.TriggerInstall() case "post-app-clone": diff --git a/plugins/ps/triggers.go b/plugins/ps/triggers.go index 90e81ac7e..af6fd2cca 100644 --- a/plugins/ps/triggers.go +++ b/plugins/ps/triggers.go @@ -3,6 +3,7 @@ package ps import ( "fmt" "os" + "path" "path/filepath" "strings" @@ -10,6 +11,7 @@ import ( "github.com/dokku/dokku/plugins/common" "github.com/dokku/dokku/plugins/config" dockeroptions "github.com/dokku/dokku/plugins/docker-options" + "github.com/otiai10/copy" ) // TriggerAppRestart restarts an app @@ -29,6 +31,29 @@ 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 { + procfilePath := strings.Trim(reportComputedProcfilePath(appName), "/") + if procfilePath == "" || procfilePath == "Procfile" { + return nil + } + + if err := os.Remove(path.Join(sourceWorkDir, "Procfile")); err != nil { + return fmt.Errorf("Unable to remove existing Procfile: %v", err.Error()) + } + + fullProcfilePath := path.Join(sourceWorkDir, procfilePath) + if !common.FileExists(fullProcfilePath) { + return nil + } + + if err := copy.Copy(fullProcfilePath, path.Join(sourceWorkDir, "Procfile")); err != nil { + return fmt.Errorf("Unable to move specified Procfile into place: %v", err.Error()) + } + + return nil +} + // TriggerInstall initializes app restart policies func TriggerInstall() error { if err := common.PropertySetup("ps"); err != nil { @@ -142,7 +167,7 @@ func TriggerPostDelete(appName string) error { // TriggerPostExtract validates a procfile func TriggerPostExtract(appName string, tempWorkDir string) error { - procfile := filepath.Join(tempWorkDir, reportComputedProcfilePath(appName)) + procfile := filepath.Join(tempWorkDir, "Procfile") if !common.FileExists(procfile) { return nil }