Skip to content

Commit

Permalink
Default to PuluginFolders is KnownPluginFolders is unset
Browse files Browse the repository at this point in the history
* PACKER_PLUGIN_PATH takes precedence over all
  • Loading branch information
nywilken committed Jun 22, 2023
1 parent 374729f commit 172fab6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions packer/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package packer
import (
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -81,7 +80,7 @@ func (c *PluginConfig) Discover() error {
}

if len(c.KnownPluginFolders) == 0 {
return errors.New("no known plugin folders defined")
c.KnownPluginFolders = PluginFolders()
}

// TODO after JSON is deprecated remove support for legacy component plugins.
Expand Down
1 change: 0 additions & 1 deletion packer/plugin_discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func newPluginConfig() PluginConfig {
var conf PluginConfig
conf.PluginMinPort = 10000
conf.PluginMaxPort = 25000
conf.KnownPluginFolders = []string{os.TempDir()}
return conf
}

Expand Down
9 changes: 5 additions & 4 deletions packer/plugin_folders.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import (
func PluginFolders(dirs ...string) []string {
res := []string{}

if packerPluginPath := os.Getenv("PACKER_PLUGIN_PATH"); packerPluginPath != "" {
res = append(res, strings.Split(packerPluginPath, string(os.PathListSeparator))...)
return res
}

if path, err := os.Executable(); err != nil {
log.Printf("[ERR] Error finding executable: %v", err)
} else {
Expand All @@ -30,9 +35,5 @@ func PluginFolders(dirs ...string) []string {
res = append(res, filepath.Join(cd, "plugins"))
}

if packerPluginPath := os.Getenv("PACKER_PLUGIN_PATH"); packerPluginPath != "" {
res = append(res, strings.Split(packerPluginPath, string(os.PathListSeparator))...)
}

return res
}

0 comments on commit 172fab6

Please sign in to comment.