mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-20 06:51:39 -04:00
Listing installed plugins is a sequential operation that iterates on each potential plugin binary under PACKER_PLUGIN_PATH. Each potential candidate may be executed in order to get its description, and to match that what is reported by the plugin binary matches what is effectively installed on the filesystem. This operation may be causing lots of I/O syncs, and if done sequentially on a rather large number of installed plugins will take time. In order to make this faster, we paralellise listing installations, so we run those commands in parallel in order to minimise idle waiting time on the main process.
80 lines
1.7 KiB
Go
80 lines
1.7 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package command
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"runtime"
|
|
"strings"
|
|
|
|
plugingetter "github.com/hashicorp/packer/packer/plugin-getter"
|
|
)
|
|
|
|
type PluginsInstalledCommand struct {
|
|
Meta
|
|
}
|
|
|
|
func (c *PluginsInstalledCommand) Synopsis() string {
|
|
return "List all installed Packer plugin binaries"
|
|
}
|
|
|
|
func (c *PluginsInstalledCommand) Help() string {
|
|
helpText := `
|
|
Usage: packer plugins installed
|
|
|
|
This command lists all installed plugin binaries that match with the current
|
|
OS and architecture. Packer's API version will be ignored.
|
|
|
|
`
|
|
|
|
return strings.TrimSpace(helpText)
|
|
}
|
|
|
|
func (c *PluginsInstalledCommand) Run(args []string) int {
|
|
ctx, cleanup := handleTermInterrupt(c.Ui)
|
|
defer cleanup()
|
|
|
|
return c.RunContext(ctx)
|
|
}
|
|
|
|
func (c *PluginsInstalledCommand) RunContext(buildCtx context.Context) int {
|
|
|
|
opts := plugingetter.ListInstallationsOptions{
|
|
PluginDirectory: c.Meta.CoreConfig.Components.PluginConfig.PluginDirectory,
|
|
BinaryInstallationOptions: plugingetter.BinaryInstallationOptions{
|
|
OS: runtime.GOOS,
|
|
ARCH: runtime.GOARCH,
|
|
Checksummers: []plugingetter.Checksummer{
|
|
{Type: "sha256"},
|
|
},
|
|
},
|
|
}
|
|
|
|
if runtime.GOOS == "windows" && opts.Ext == "" {
|
|
opts.BinaryInstallationOptions.Ext = ".exe"
|
|
}
|
|
|
|
log.Printf("[TRACE] init: %#v", opts)
|
|
|
|
// a plugin requirement that matches them all
|
|
allPlugins := plugingetter.Requirement{
|
|
Accessor: "",
|
|
VersionConstraints: nil,
|
|
Identifier: nil,
|
|
}
|
|
|
|
installations, err := allPlugins.ListInstallations(opts)
|
|
if err != nil {
|
|
c.Ui.Error(err.Error())
|
|
return 1
|
|
}
|
|
|
|
for _, installation := range installations {
|
|
c.Ui.Message(installation.BinaryPath)
|
|
}
|
|
|
|
return 0
|
|
}
|