From 0a90d3e7917de7eb8cc33257f2a19bd9d04853ec Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 18 Jun 2013 21:18:41 -0700 Subject: [PATCH] post-processor/compress: Boilerplate for the compress PP --- config.go | 4 +++ plugin/post-processor-compress/main.go | 10 ++++++ post-processor/compress/post-processor.go | 38 +++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 plugin/post-processor-compress/main.go create mode 100644 post-processor/compress/post-processor.go diff --git a/config.go b/config.go index c14da113e..3e3278371 100644 --- a/config.go +++ b/config.go @@ -30,6 +30,10 @@ const defaultConfig = ` "validate": "packer-command-validate" }, + "post-processors": { + "compress": "packer-post-processor-compress" + }, + "provisioners": { "shell": "packer-provisioner-shell" } diff --git a/plugin/post-processor-compress/main.go b/plugin/post-processor-compress/main.go new file mode 100644 index 000000000..6f6f3e600 --- /dev/null +++ b/plugin/post-processor-compress/main.go @@ -0,0 +1,10 @@ +package main + +import ( + "github.com/mitchellh/packer/post-processor/compress" + "github.com/mitchellh/packer/packer/plugin" +) + +func main() { + plugin.ServePostProcessor(new(compress.PostProcessor)) +} diff --git a/post-processor/compress/post-processor.go b/post-processor/compress/post-processor.go new file mode 100644 index 000000000..24b5ef5e9 --- /dev/null +++ b/post-processor/compress/post-processor.go @@ -0,0 +1,38 @@ +// compress implements the packer.PostProcessor interface and adds a +// post-processor for compressing output. +package compress + +import ( + "errors" + "github.com/mitchellh/packer/packer" + "github.com/mitchellh/mapstructure" +) + +type Config struct { + Format string +} + +type PostProcessor struct { + config Config +} + +func (p *PostProcessor) Configure(raw interface{}) error { + if err := mapstructure.Decode(raw, &p.config); err != nil { + return err + } + + if p.config.Format == "" { + p.config.Format = "tar.gz" + } + + if p.config.Format != "tar.gz" { + return errors.New("only 'tar.gz' is a supported format right now") + } + + return nil +} + +func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (packer.Artifact, error) { + ui.Say("We made it to here.") + return nil, nil +}