mirror of https://github.com/hashicorp/packer
- Internal plugins are compiled into the same packer binary and invoked through the plugin command - Search paths allow disk-based plugins to override and should function as normal - This should allow for a 94% space savings vs statically compiling all the plugins as separate binaries.. approximately 24mb vs 431mbpull/2854/head
parent
f197cf76a7
commit
d09a9ab0c7
@ -0,0 +1,147 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/mitchellh/packer/builder/amazon/chroot"
|
||||
"github.com/mitchellh/packer/builder/amazon/ebs"
|
||||
"github.com/mitchellh/packer/builder/amazon/instance"
|
||||
"github.com/mitchellh/packer/builder/digitalocean"
|
||||
"github.com/mitchellh/packer/builder/docker"
|
||||
filebuilder "github.com/mitchellh/packer/builder/file"
|
||||
"github.com/mitchellh/packer/builder/googlecompute"
|
||||
"github.com/mitchellh/packer/builder/null"
|
||||
"github.com/mitchellh/packer/builder/openstack"
|
||||
parallelsiso "github.com/mitchellh/packer/builder/parallels/iso"
|
||||
parallelspvm "github.com/mitchellh/packer/builder/parallels/pvm"
|
||||
"github.com/mitchellh/packer/builder/qemu"
|
||||
virtualboxiso "github.com/mitchellh/packer/builder/virtualbox/iso"
|
||||
virtualboxovf "github.com/mitchellh/packer/builder/virtualbox/ovf"
|
||||
vmwareiso "github.com/mitchellh/packer/builder/vmware/iso"
|
||||
vmwarevmx "github.com/mitchellh/packer/builder/vmware/vmx"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"github.com/mitchellh/packer/packer/plugin"
|
||||
"github.com/mitchellh/packer/provisioner/ansible-local"
|
||||
"github.com/mitchellh/packer/provisioner/chef-client"
|
||||
"github.com/mitchellh/packer/provisioner/chef-solo"
|
||||
fileprovisioner "github.com/mitchellh/packer/provisioner/file"
|
||||
"github.com/mitchellh/packer/provisioner/powershell"
|
||||
"github.com/mitchellh/packer/provisioner/puppet-masterless"
|
||||
"github.com/mitchellh/packer/provisioner/puppet-server"
|
||||
"github.com/mitchellh/packer/provisioner/salt-masterless"
|
||||
"github.com/mitchellh/packer/provisioner/shell"
|
||||
shelllocal "github.com/mitchellh/packer/provisioner/shell-local"
|
||||
"github.com/mitchellh/packer/provisioner/windows-restart"
|
||||
windowsshell "github.com/mitchellh/packer/provisioner/windows-shell"
|
||||
)
|
||||
|
||||
type PluginCommand struct {
|
||||
Meta
|
||||
}
|
||||
|
||||
var Builders = map[string]packer.Builder{
|
||||
"amazon-chroot": new(chroot.Builder),
|
||||
"amazon-ebs": new(ebs.Builder),
|
||||
"amazon-instance": new(instance.Builder),
|
||||
"digitalocean": new(digitalocean.Builder),
|
||||
"docker": new(docker.Builder),
|
||||
"file": new(filebuilder.Builder),
|
||||
"googlecompute": new(googlecompute.Builder),
|
||||
"null": new(null.Builder),
|
||||
"openstack": new(openstack.Builder),
|
||||
"parallels-iso": new(parallelsiso.Builder),
|
||||
"parallels-pvm": new(parallelspvm.Builder),
|
||||
"qemu": new(qemu.Builder),
|
||||
"virtualbox-iso": new(virtualboxiso.Builder),
|
||||
"virtualbox-ovf": new(virtualboxovf.Builder),
|
||||
"vmware-iso": new(vmwareiso.Builder),
|
||||
"vmware-vmx": new(vmwarevmx.Builder),
|
||||
}
|
||||
|
||||
var Provisioners = map[string]packer.Provisioner{
|
||||
"ansible-local": new(ansiblelocal.Provisioner),
|
||||
"chef-client": new(chefclient.Provisioner),
|
||||
"chef-solo": new(chefsolo.Provisioner),
|
||||
"file": new(fileprovisioner.Provisioner),
|
||||
"powershell": new(powershell.Provisioner),
|
||||
"puppet-masterless": new(puppetmasterless.Provisioner),
|
||||
"puppet-server": new(puppetserver.Provisioner),
|
||||
"salt-masterless": new(saltmasterless.Provisioner),
|
||||
"shell": new(shell.Provisioner),
|
||||
"shell-local": new(shelllocal.Provisioner),
|
||||
"windows-restart": new(restart.Provisioner),
|
||||
"windows-shell": new(windowsshell.Provisioner),
|
||||
}
|
||||
|
||||
var PostProcessors = map[string]packer.PostProcessor{}
|
||||
|
||||
func (c *PluginCommand) Run(args []string) int {
|
||||
// This is an internal call so we're not going to do much error checking.
|
||||
// If there's a problem we'll usually just crash.
|
||||
log.Printf("args: %#v", args)
|
||||
if len(args) != 1 {
|
||||
c.Ui.Error("Wrong number of args")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Plugin should be called like "packer-builder-amazon-ebs" so we'll take it
|
||||
// apart.
|
||||
parts := strings.Split(args[0], "-")
|
||||
pluginType := parts[1]
|
||||
pluginName := ""
|
||||
// Post-processor is split so we'll so some magic here. We could use a
|
||||
// regexp but this is simpler.
|
||||
if pluginType == "post" {
|
||||
pluginType = strings.Join(parts[1:2], "-")
|
||||
pluginName = strings.Join(parts[3:], "-")
|
||||
} else {
|
||||
pluginName = strings.Join(parts[2:], "-")
|
||||
}
|
||||
|
||||
server, err := plugin.Server()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if pluginType == "builder" {
|
||||
builder, found := Builders[pluginName]
|
||||
if !found {
|
||||
c.Ui.Error(fmt.Sprintf("Could not load builder: %s", pluginName))
|
||||
}
|
||||
server.RegisterBuilder(builder)
|
||||
} else if pluginType == "provisioner" {
|
||||
provisioner, found := Provisioners[pluginName]
|
||||
if !found {
|
||||
c.Ui.Error(fmt.Sprintf("Could not load provisioner: %s", pluginName))
|
||||
}
|
||||
server.RegisterProvisioner(provisioner)
|
||||
} else if pluginType == "post-processor" {
|
||||
postProcessor, found := PostProcessors[pluginName]
|
||||
if !found {
|
||||
c.Ui.Error(fmt.Sprintf("Could not load post-processor: %s", pluginName))
|
||||
}
|
||||
server.RegisterPostProcessor(postProcessor)
|
||||
}
|
||||
|
||||
server.Serve()
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func (*PluginCommand) Help() string {
|
||||
helpText := `
|
||||
Usage: packer plugin PLUGIN
|
||||
|
||||
Runs an internally-compiled version of a plugin from the packer binary. Note
|
||||
that this is an internal command and you should not call it yourself.
|
||||
`
|
||||
|
||||
return strings.TrimSpace(helpText)
|
||||
}
|
||||
|
||||
func (c *PluginCommand) Synopsis() string {
|
||||
return "call an internal plugin"
|
||||
}
|
||||
Loading…
Reference in new issue