mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-20 15:01:40 -04:00
As maintainers of Packer and plugins, we ask our users to provide us with the versions of Packer and the plugins they use when they open an issue for us to review. This is often misunderstood, and may be hidden in the logs, making it harder for all of us to understand where to look. This commit adds a log statement that reports the list of plugins used, their version, and the path they've been loaded from.
41 lines
891 B
Go
41 lines
891 B
Go
package main
|
|
|
|
import (
|
|
_ "embed"
|
|
"fmt"
|
|
"os"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
"golang.org/x/mod/modfile"
|
|
)
|
|
|
|
//go:embed go.mod
|
|
var mod string
|
|
|
|
var pluginRegex = regexp.MustCompile("packer-plugin-.*$")
|
|
|
|
func GetBundledPluginVersions() map[string]packer.PluginSpec {
|
|
pluginSpecs := map[string]packer.PluginSpec{}
|
|
|
|
mods, err := modfile.Parse("", []byte(mod), nil)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("failed to parse embedded modfile: %s", err))
|
|
}
|
|
|
|
for _, req := range mods.Require {
|
|
if pluginRegex.MatchString(req.Mod.Path) {
|
|
pluginName := pluginRegex.FindString(req.Mod.Path)
|
|
pluginShortName := strings.Replace(pluginName, "packer-plugin-", "", 1)
|
|
pluginSpecs[pluginShortName] = packer.PluginSpec{
|
|
Name: pluginShortName,
|
|
Version: fmt.Sprintf("bundled (%s)", req.Mod.Version),
|
|
Path: os.Args[0],
|
|
}
|
|
}
|
|
}
|
|
|
|
return pluginSpecs
|
|
}
|