From 82f1778fcf4c79caa3a46a652d92da7fc8a918a0 Mon Sep 17 00:00:00 2001 From: Brian Ketelsen Date: Sat, 28 Aug 2021 07:49:30 -0400 Subject: [PATCH] use exec.LookPath to find plugins --- content/postplugins.go | 10 +++++++--- content/preplugins.go | 10 ++++++++-- dogfood/blox.cue | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/content/postplugins.go b/content/postplugins.go index 616ef6a..4b51054 100644 --- a/content/postplugins.go +++ b/content/postplugins.go @@ -64,12 +64,16 @@ func (s *Service) callPostPlugin(name, executable string) error { Output: os.Stdout, Level: hclog.Info, }) - + executablePath, err := exec.LookPath(executable) + if err != nil { + pterm.Error.Println("plugin not found in path", executable) + log.Fatal(err) + } // We're a host! Start by launching the plugin process. client := plugin.NewClient(&plugin.ClientConfig{ HandshakeConfig: shared.PostbuildHandshakeConfig, Plugins: prePluginMap, - Cmd: exec.Command(executable), + Cmd: exec.Command(executablePath), Logger: logger, }) defer client.Kill() @@ -86,7 +90,7 @@ func (s *Service) callPostPlugin(name, executable string) error { log.Fatal(err) } - // We should have a Greeter now! This feels like a normal interface + // We should have a Postbuild plugin now! This feels like a normal interface // implementation but is in fact over an RPC connection. postplug := raw.(plugins.Postbuild) return postplug.Process(s.rawConfig) diff --git a/content/preplugins.go b/content/preplugins.go index 5b9d85a..ea93ca4 100644 --- a/content/preplugins.go +++ b/content/preplugins.go @@ -63,11 +63,17 @@ func (s *Service) callPrePlugin(name, executable string) error { Level: hclog.Info, }) + executablePath, err := exec.LookPath(executable) + if err != nil { + pterm.Error.Println("plugin not found in path", executable) + log.Fatal(err) + } + pterm.Info.Println("found plugin at path", executable, executablePath) // We're a host! Start by launching the plugin process. client := plugin.NewClient(&plugin.ClientConfig{ HandshakeConfig: shared.PrebuildHandshakeConfig, Plugins: prePluginMap, - Cmd: exec.Command(executable), + Cmd: exec.Command(executablePath), Logger: logger, }) defer client.Kill() @@ -84,7 +90,7 @@ func (s *Service) callPrePlugin(name, executable string) error { log.Fatal(err) } - // We should have a Greeter now! This feels like a normal interface + // We should have a Prebuild plugin now! This feels like a normal interface // implementation but is in fact over an RPC connection. preplug := raw.(plugins.Prebuild) return preplug.Process(s.rawConfig) diff --git a/dogfood/blox.cue b/dogfood/blox.cue index 6350e2a..d0a6400 100644 --- a/dogfood/blox.cue +++ b/dogfood/blox.cue @@ -5,6 +5,6 @@ static_dir: "static" prebuild: [ { name: "images" - executable: "../images_impl" + executable: "images_impl" }] }