-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
packer: log plugins used and their version/path
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.
- Loading branch information
1 parent
f961715
commit 8232633
Showing
6 changed files
with
231 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters