plugins: add a release only flag to Discover

Since we now support loading pre-releases, we also want Packer to be
able to ignore them by user demand, so we put in place the
infrastructure to modulate this.
pull/12863/head
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent e099c5c661
commit 9f7e6ca52b

@ -76,6 +76,7 @@ func (cfg *PackerConfig) DetectPluginBinaries() hcl.Diagnostics {
Checksummers: []plugingetter.Checksummer{
{Type: "sha256", Hash: sha256.New()},
},
ReleasesOnly: cfg.parser.PluginConfig.ReleasesOnly,
},
}

@ -60,6 +60,10 @@ type BinaryInstallationOptions struct {
Ext string
Checksummers []Checksummer
// ReleasesOnly may be set by commands like validate or build, and
// forces Packer to not consider plugin pre-releases.
ReleasesOnly bool
}
type ListInstallationsOptions struct {
@ -154,13 +158,18 @@ func (pr Requirement) ListInstallations(opts ListInstallationsOptions) (InstallL
// versionsStr now looks like v1.2.3_x5.1 or amazon_v1.2.3_x5.1
parts := strings.SplitN(versionsStr, "_", 2)
pluginVersionStr, protocolVerionStr := parts[0], parts[1]
_, err = version.NewVersion(pluginVersionStr)
ver, err := version.NewVersion(pluginVersionStr)
if err != nil {
// could not be parsed, ignoring the file
log.Printf("found %q with an incorrect %q version, ignoring it. %v", path, pluginVersionStr, err)
continue
}
if ver.Prerelease() != "" && opts.ReleasesOnly {
log.Printf("ignoring pre-release plugin %q", path)
continue
}
matches := pluginVersionRegex.FindStringSubmatch(pluginVersionStr)
if matches == nil {
log.Printf("invalid version found: %q, ignoring", pluginVersionStr)

@ -34,6 +34,7 @@ type PluginConfig struct {
Provisioners ProvisionerSet
PostProcessors PostProcessorSet
DataSources DatasourceSet
ReleasesOnly bool
}
// PACKERSPACE is used to represent the spaces that separate args for a command
@ -81,6 +82,7 @@ func (c *PluginConfig) Discover() error {
Checksummers: []plugingetter.Checksummer{
{Type: "sha256", Hash: sha256.New()},
},
ReleasesOnly: c.ReleasesOnly,
},
})
if err != nil {

Loading…
Cancel
Save