mirror of
https://github.com/hashicorp/packer.git
synced 2026-05-28 04:35:38 -04:00
packer: only support one directory for plugins
Since we're removing the alternative plugin installation directories in favour of only supporting installing them in the PACKER_PLUGIN_PATH directory, we only return one directory when getting the known plugin directories.
This commit is contained in:
parent
32f89015fe
commit
94aaff44a1
12 changed files with 32 additions and 47 deletions
|
|
@ -76,7 +76,7 @@ for more info.`)
|
|||
}
|
||||
|
||||
opts := plugingetter.ListInstallationsOptions{
|
||||
FromFolders: c.Meta.CoreConfig.Components.PluginConfig.KnownPluginFolders,
|
||||
FromFolders: []string{c.Meta.CoreConfig.Components.PluginConfig.PluginDirectory},
|
||||
BinaryInstallationOptions: plugingetter.BinaryInstallationOptions{
|
||||
OS: runtime.GOOS,
|
||||
ARCH: runtime.GOARCH,
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ func TestInitCommand_Run(t *testing.T) {
|
|||
t.Fatalf("Failed to discover plugins: %s", err)
|
||||
}
|
||||
|
||||
c.CoreConfig.Components.PluginConfig.KnownPluginFolders = []string{tt.packerConfigDir}
|
||||
c.CoreConfig.Components.PluginConfig.PluginDirectory = tt.packerConfigDir
|
||||
if got := c.Run(args); got != tt.want {
|
||||
t.Errorf("InitCommand.Run() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ func (c *PluginsInstallCommand) ParseArgs(args []string) (*PluginsInstallArgs, i
|
|||
|
||||
func (c *PluginsInstallCommand) RunContext(buildCtx context.Context, args *PluginsInstallArgs) int {
|
||||
opts := plugingetter.ListInstallationsOptions{
|
||||
FromFolders: c.Meta.CoreConfig.Components.PluginConfig.KnownPluginFolders,
|
||||
FromFolders: []string{c.Meta.CoreConfig.Components.PluginConfig.PluginDirectory},
|
||||
BinaryInstallationOptions: plugingetter.BinaryInstallationOptions{
|
||||
OS: runtime.GOOS,
|
||||
ARCH: runtime.GOARCH,
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ func TestPluginsInstallCommand_Run(t *testing.T) {
|
|||
t.Fatalf("Failed to discover plugins: %s", err)
|
||||
}
|
||||
|
||||
c.CoreConfig.Components.PluginConfig.KnownPluginFolders = []string{tt.packerConfigDir}
|
||||
c.CoreConfig.Components.PluginConfig.PluginDirectory = tt.packerConfigDir
|
||||
if got := c.Run(tt.pluginSourceArgs); got != tt.want {
|
||||
t.Errorf("PluginsInstallCommand.Run() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ func (c *PluginsInstalledCommand) Run(args []string) int {
|
|||
func (c *PluginsInstalledCommand) RunContext(buildCtx context.Context) int {
|
||||
|
||||
opts := plugingetter.ListInstallationsOptions{
|
||||
FromFolders: c.Meta.CoreConfig.Components.PluginConfig.KnownPluginFolders,
|
||||
FromFolders: []string{c.Meta.CoreConfig.Components.PluginConfig.PluginDirectory},
|
||||
BinaryInstallationOptions: plugingetter.BinaryInstallationOptions{
|
||||
OS: runtime.GOOS,
|
||||
ARCH: runtime.GOARCH,
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ func (c *PluginsRemoveCommand) RunContext(buildCtx context.Context, args []strin
|
|||
}
|
||||
|
||||
opts := plugingetter.ListInstallationsOptions{
|
||||
FromFolders: c.Meta.CoreConfig.Components.PluginConfig.KnownPluginFolders,
|
||||
FromFolders: []string{c.Meta.CoreConfig.Components.PluginConfig.PluginDirectory},
|
||||
BinaryInstallationOptions: plugingetter.BinaryInstallationOptions{
|
||||
OS: runtime.GOOS,
|
||||
ARCH: runtime.GOARCH,
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ func TestPluginsRemoveCommand_Run(t *testing.T) {
|
|||
Meta: tt.Meta,
|
||||
}
|
||||
|
||||
c.CoreConfig.Components.PluginConfig.KnownPluginFolders = []string{tt.packerConfigDir}
|
||||
c.CoreConfig.Components.PluginConfig.PluginDirectory = tt.packerConfigDir
|
||||
if got := c.Run(tt.pluginSourceArgs); got != tt.want {
|
||||
t.Errorf("PluginsRemoveCommand.Run() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ func (c *PluginsRequiredCommand) RunContext(buildCtx context.Context, cla *Plugi
|
|||
}
|
||||
|
||||
opts := plugingetter.ListInstallationsOptions{
|
||||
FromFolders: c.Meta.CoreConfig.Components.PluginConfig.KnownPluginFolders,
|
||||
FromFolders: []string{c.Meta.CoreConfig.Components.PluginConfig.PluginDirectory},
|
||||
BinaryInstallationOptions: plugingetter.BinaryInstallationOptions{
|
||||
OS: runtime.GOOS,
|
||||
ARCH: runtime.GOARCH,
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func (cfg *PackerConfig) PluginRequirements() (plugingetter.Requirements, hcl.Di
|
|||
|
||||
func (cfg *PackerConfig) DetectPluginBinaries() hcl.Diagnostics {
|
||||
opts := plugingetter.ListInstallationsOptions{
|
||||
FromFolders: cfg.parser.PluginConfig.KnownPluginFolders,
|
||||
FromFolders: []string{cfg.parser.PluginConfig.PluginDirectory},
|
||||
BinaryInstallationOptions: plugingetter.BinaryInstallationOptions{
|
||||
OS: runtime.GOOS,
|
||||
ARCH: runtime.GOARCH,
|
||||
|
|
|
|||
11
main.go
11
main.go
|
|
@ -329,11 +329,16 @@ func extractMachineReadable(args []string) ([]string, bool) {
|
|||
}
|
||||
|
||||
func loadConfig() (*config, error) {
|
||||
pluginDir, err := packer.PluginFolder()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var config config
|
||||
config.Plugins = &packer.PluginConfig{
|
||||
PluginMinPort: 10000,
|
||||
PluginMaxPort: 25000,
|
||||
KnownPluginFolders: packer.PluginFolders("."),
|
||||
PluginMinPort: 10000,
|
||||
PluginMaxPort: 25000,
|
||||
PluginDirectory: pluginDir,
|
||||
}
|
||||
if err := config.Plugins.Discover(); err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -27,13 +27,13 @@ var defaultChecksummer = plugingetter.Checksummer{
|
|||
|
||||
// PluginConfig helps load and use packer plugins
|
||||
type PluginConfig struct {
|
||||
KnownPluginFolders []string
|
||||
PluginMinPort int
|
||||
PluginMaxPort int
|
||||
Builders BuilderSet
|
||||
Provisioners ProvisionerSet
|
||||
PostProcessors PostProcessorSet
|
||||
DataSources DatasourceSet
|
||||
PluginDirectory string
|
||||
PluginMinPort int
|
||||
PluginMaxPort int
|
||||
Builders BuilderSet
|
||||
Provisioners ProvisionerSet
|
||||
PostProcessors PostProcessorSet
|
||||
DataSources DatasourceSet
|
||||
}
|
||||
|
||||
// PACKERSPACE is used to represent the spaces that separate args for a command
|
||||
|
|
@ -67,15 +67,7 @@ func (c *PluginConfig) Discover() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if len(c.KnownPluginFolders) == 0 {
|
||||
//PluginFolders should match the call in github.com/hahicorp/packer/main.go#loadConfig
|
||||
c.KnownPluginFolders = PluginFolders(".")
|
||||
}
|
||||
|
||||
// Pick last folder as it's the one with the highest priority
|
||||
// This is the same logic used when installing plugins via Packer's plugin installation commands.
|
||||
pluginInstallationPath := c.KnownPluginFolders[len(c.KnownPluginFolders)-1]
|
||||
if err := c.discoverInstalledComponents(pluginInstallationPath); err != nil {
|
||||
if err := c.discoverInstalledComponents(c.PluginDirectory); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,33 +7,21 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/packer-plugin-sdk/pathing"
|
||||
)
|
||||
|
||||
// PluginFolders returns the list of known plugin folders based on system.
|
||||
func PluginFolders(dirs ...string) []string {
|
||||
res := []string{}
|
||||
|
||||
// PluginFolder returns the known plugin folder based on system.
|
||||
func PluginFolder() (string, error) {
|
||||
if packerPluginPath := os.Getenv("PACKER_PLUGIN_PATH"); packerPluginPath != "" {
|
||||
res = append(res, strings.Split(packerPluginPath, string(os.PathListSeparator))...)
|
||||
return res
|
||||
return packerPluginPath, nil
|
||||
}
|
||||
|
||||
if path, err := os.Executable(); err != nil {
|
||||
log.Printf("[ERR] Error finding executable: %v", err)
|
||||
} else {
|
||||
res = append(res, filepath.Dir(path))
|
||||
}
|
||||
|
||||
res = append(res, dirs...)
|
||||
|
||||
if cd, err := pathing.ConfigDir(); err != nil {
|
||||
cd, err := pathing.ConfigDir()
|
||||
if err != nil {
|
||||
log.Printf("[ERR] Error loading config directory: %v", err)
|
||||
} else {
|
||||
res = append(res, filepath.Join(cd, "plugins"))
|
||||
return "", err
|
||||
}
|
||||
|
||||
return res
|
||||
return filepath.Join(cd, "plugins"), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue