Commit e904705a authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer uses the new plugin client API

parent 88d50889
...@@ -66,38 +66,45 @@ func (c *config) LoadBuilder(name string) (packer.Builder, error) { ...@@ -66,38 +66,45 @@ func (c *config) LoadBuilder(name string) (packer.Builder, error) {
return nil, nil return nil, nil
} }
return plugin.Builder(exec.Command(bin)) return c.pluginClient(bin).Builder()
} }
// This is a proper packer.CommandFunc that can be used to load packer.Command // This is a proper packer.CommandFunc that can be used to load packer.Command
// implementations from the defined plugins. // implementations from the defined plugins.
func (c *config) LoadCommand(name string) (packer.Command, error) { func (c *config) LoadCommand(name string) (packer.Command, error) {
log.Printf("Loading command: %s\n", name) log.Printf("Loading command: %s\n", name)
commandBin, ok := c.Commands[name] bin, ok := c.Commands[name]
if !ok { if !ok {
log.Printf("Command not found: %s\n", name) log.Printf("Command not found: %s\n", name)
return nil, nil return nil, nil
} }
return plugin.Command(exec.Command(commandBin)) return c.pluginClient(bin).Command()
} }
// This is a proper implementation of packer.HookFunc that can be used // This is a proper implementation of packer.HookFunc that can be used
// to load packer.Hook implementations from the defined plugins. // to load packer.Hook implementations from the defined plugins.
func (c *config) LoadHook(name string) (packer.Hook, error) { func (c *config) LoadHook(name string) (packer.Hook, error) {
log.Printf("Loading hook: %s\n", name) log.Printf("Loading hook: %s\n", name)
return plugin.Hook(exec.Command(name)) return c.pluginClient(name).Hook()
} }
// This is a proper packer.ProvisionerFunc that can be used to load // This is a proper packer.ProvisionerFunc that can be used to load
// packer.Provisioner implementations from defined plugins. // packer.Provisioner implementations from defined plugins.
func (c *config) LoadProvisioner(name string) (packer.Provisioner, error) { func (c *config) LoadProvisioner(name string) (packer.Provisioner, error) {
log.Printf("Loading provisioner: %s\n", name) log.Printf("Loading provisioner: %s\n", name)
provBin, ok := c.Provisioners[name] bin, ok := c.Provisioners[name]
if !ok { if !ok {
log.Printf("Provisioner not found: %s\n", name) log.Printf("Provisioner not found: %s\n", name)
return nil, nil return nil, nil
} }
return plugin.Provisioner(exec.Command(provBin)) return c.pluginClient(bin).Provisioner()
}
func (c *config) pluginClient(path string) *plugin.Client {
var config plugin.ClientConfig
config.Cmd = exec.Command(path)
config.Managed = true
return plugin.NewClient(&config)
} }
...@@ -42,7 +42,7 @@ type ClientConfig struct { ...@@ -42,7 +42,7 @@ type ClientConfig struct {
// plugin package or not. If true, then by calling CleanupClients, // plugin package or not. If true, then by calling CleanupClients,
// it will automatically be cleaned up. Otherwise, the client // it will automatically be cleaned up. Otherwise, the client
// user is fully responsible for making sure to Kill all plugin // user is fully responsible for making sure to Kill all plugin
// clients. // clients. By default the client is _not_ managed.
Managed bool Managed bool
// The minimum and maximum port to use for communicating with // The minimum and maximum port to use for communicating with
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment