From 3177a5413c8a6057c06c6d91564c12f9e636c7dc Mon Sep 17 00:00:00 2001 From: Tommy McNeely Date: Fri, 27 Dec 2019 16:09:53 -0700 Subject: [PATCH 1/3] Fix external plugins path was blank --- config.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/config.go b/config.go index f99761979..145a2fca5 100644 --- a/config.go +++ b/config.go @@ -131,10 +131,11 @@ func (c *config) discoverExternalComponents(path string) error { if err != nil { return err } - for plugin := range pluginPaths { + for plugin, path := range pluginPaths { plugin := plugin + path := path c.Builders[plugin] = func() (packer.Builder, error) { - return c.pluginClient(pluginPaths[plugin]).Builder() + return c.pluginClient(path).Builder() } externallyUsed = append(externallyUsed, plugin) } @@ -148,10 +149,11 @@ func (c *config) discoverExternalComponents(path string) error { if err != nil { return err } - for plugin := range pluginPaths { + for plugin, path := range pluginPaths { plugin := plugin + path := path c.PostProcessors[plugin] = func() (packer.PostProcessor, error) { - return c.pluginClient(pluginPaths[plugin]).PostProcessor() + return c.pluginClient(path).PostProcessor() } externallyUsed = append(externallyUsed, plugin) } @@ -165,10 +167,11 @@ func (c *config) discoverExternalComponents(path string) error { if err != nil { return err } - for plugin := range pluginPaths { + for plugin, path := range pluginPaths { plugin := plugin + path := path c.Provisioners[plugin] = func() (packer.Provisioner, error) { - return c.pluginClient(pluginPaths[plugin]).Provisioner() + return c.pluginClient(path).Provisioner() } externallyUsed = append(externallyUsed, plugin) } From 72112ccae23591c86f6965ca22b260b947373ffe Mon Sep 17 00:00:00 2001 From: Tommy McNeely Date: Mon, 6 Jan 2020 12:50:12 -0700 Subject: [PATCH 2/3] Make the path assignment less confusing --- config.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/config.go b/config.go index 145a2fca5..c226b49ec 100644 --- a/config.go +++ b/config.go @@ -132,10 +132,9 @@ func (c *config) discoverExternalComponents(path string) error { return err } for plugin, path := range pluginPaths { - plugin := plugin - path := path + newPath := path // this needs to be stored in a new variable for the func below c.Builders[plugin] = func() (packer.Builder, error) { - return c.pluginClient(path).Builder() + return c.pluginClient(newPath).Builder() } externallyUsed = append(externallyUsed, plugin) } @@ -150,10 +149,9 @@ func (c *config) discoverExternalComponents(path string) error { return err } for plugin, path := range pluginPaths { - plugin := plugin - path := path + newPath := path // this needs to be stored in a new variable for the func below c.PostProcessors[plugin] = func() (packer.PostProcessor, error) { - return c.pluginClient(path).PostProcessor() + return c.pluginClient(newPath).PostProcessor() } externallyUsed = append(externallyUsed, plugin) } @@ -168,10 +166,9 @@ func (c *config) discoverExternalComponents(path string) error { return err } for plugin, path := range pluginPaths { - plugin := plugin - path := path + newPath := path // this needs to be stored in a new variable for the func below c.Provisioners[plugin] = func() (packer.Provisioner, error) { - return c.pluginClient(path).Provisioner() + return c.pluginClient(newPath).Provisioner() } externallyUsed = append(externallyUsed, plugin) } From 469a4d2a11ebac1916e7c364efdf9aadf4eaf21c Mon Sep 17 00:00:00 2001 From: Tommy McNeely Date: Mon, 6 Jan 2020 13:12:23 -0700 Subject: [PATCH 3/3] Fix names of range variables to reduce confusion and remove overriden plugin name --- config.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/config.go b/config.go index c226b49ec..db2d73a95 100644 --- a/config.go +++ b/config.go @@ -131,12 +131,12 @@ func (c *config) discoverExternalComponents(path string) error { if err != nil { return err } - for plugin, path := range pluginPaths { - newPath := path // this needs to be stored in a new variable for the func below - c.Builders[plugin] = func() (packer.Builder, error) { + for pluginName, pluginPath := range pluginPaths { + newPath := pluginPath // this needs to be stored in a new variable for the func below + c.Builders[pluginName] = func() (packer.Builder, error) { return c.pluginClient(newPath).Builder() } - externallyUsed = append(externallyUsed, plugin) + externallyUsed = append(externallyUsed, pluginName) } if len(externallyUsed) > 0 { sort.Strings(externallyUsed) @@ -148,12 +148,12 @@ func (c *config) discoverExternalComponents(path string) error { if err != nil { return err } - for plugin, path := range pluginPaths { - newPath := path // this needs to be stored in a new variable for the func below - c.PostProcessors[plugin] = func() (packer.PostProcessor, error) { + for pluginName, pluginPath := range pluginPaths { + newPath := pluginPath // this needs to be stored in a new variable for the func below + c.PostProcessors[pluginName] = func() (packer.PostProcessor, error) { return c.pluginClient(newPath).PostProcessor() } - externallyUsed = append(externallyUsed, plugin) + externallyUsed = append(externallyUsed, pluginName) } if len(externallyUsed) > 0 { sort.Strings(externallyUsed) @@ -165,12 +165,12 @@ func (c *config) discoverExternalComponents(path string) error { if err != nil { return err } - for plugin, path := range pluginPaths { - newPath := path // this needs to be stored in a new variable for the func below - c.Provisioners[plugin] = func() (packer.Provisioner, error) { + for pluginName, pluginPath := range pluginPaths { + newPath := pluginPath // this needs to be stored in a new variable for the func below + c.Provisioners[pluginName] = func() (packer.Provisioner, error) { return c.pluginClient(newPath).Provisioner() } - externallyUsed = append(externallyUsed, plugin) + externallyUsed = append(externallyUsed, pluginName) } if len(externallyUsed) > 0 { sort.Strings(externallyUsed) @@ -209,9 +209,9 @@ func (c *config) discoverSingle(glob string) (map[string]string, error) { } // Look for foo-bar-baz. The plugin name is "baz" - plugin := file[len(prefix):] - log.Printf("[DEBUG] Discovered plugin: %s = %s", plugin, match) - res[plugin] = match + pluginName := file[len(prefix):] + log.Printf("[DEBUG] Discovered plugin: %s = %s", pluginName, match) + res[pluginName] = match } return res, nil