From 0fb97a1d55ab42a55ab08c926f64d9f0ad90ceea Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Wed, 16 Mar 2016 16:42:24 -0700 Subject: [PATCH] Add example plugin for third-party plugin use --- plugin/example/main.go | 36 ++++++++++++++++++++++++++++++++++++ plugin/example/main_test.go | 3 +++ 2 files changed, 39 insertions(+) create mode 100644 plugin/example/main.go create mode 100644 plugin/example/main_test.go diff --git a/plugin/example/main.go b/plugin/example/main.go new file mode 100644 index 000000000..3d20ef765 --- /dev/null +++ b/plugin/example/main.go @@ -0,0 +1,36 @@ +// This is an example plugin. In packer 0.9.0 and up, core plugins are compiled +// into the main binary so these files are no longer necessary for the packer +// project. +// +// However, it is still possible to create a third-party plugin for packer that +// is distributed independently from the packer distribution. These continue to +// work in the same way. They will be loaded from the same directory as packer +// by looking for packer-[builder|provisioner|post-processor]-plugin-name. For +// example: +// +// packer-builder-docker +// +// Look at command/plugin.go to see how the core plugins are loaded now, but the +// format below was used for packer <= 0.8.6 and is forward-compatible. +package main + +import ( + "github.com/mitchellh/packer/builder/amazon/chroot" + "github.com/mitchellh/packer/packer/plugin" + "github.com/mitchellh/packer/post-processor/docker-push" + "github.com/mitchellh/packer/provisioner/powershell" +) + +func main() { + server, err := plugin.Server() + if err != nil { + panic(err) + } + // Choose the appropriate type of plugin. You should only use one of these + // at a time, which means you will have a separate plugin for each builder, + // provisioner, or post-processor. + server.RegisterBuilder(new(chroot.Builder)) + server.RegisterPostProcessor(new(dockerpush.PostProcessor)) + server.RegisterProvisioner(new(powershell.Provisioner)) + server.Serve() +} diff --git a/plugin/example/main_test.go b/plugin/example/main_test.go new file mode 100644 index 000000000..34583a2c5 --- /dev/null +++ b/plugin/example/main_test.go @@ -0,0 +1,3 @@ +// Core Packer plugins included a _test.go file to make sure they compiled +// correctly when running packer tests. For custom plugins this file is optional. +package main