Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
use exec.LookPath to find plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
bketelsen authored and rawkode committed Sep 7, 2021
1 parent b57f976 commit 82f1778
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
10 changes: 7 additions & 3 deletions content/postplugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions content/preplugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion dogfood/blox.cue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
static_dir: "static"
prebuild: [ {
name: "images"
executable: "../images_impl"
executable: "images_impl"
}]
}

0 comments on commit 82f1778

Please sign in to comment.