From 29a22591f9b547e5c0b9b9d2385502178219d425 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 5 Nov 2013 14:30:03 -0800 Subject: [PATCH] post-processor/vagrant: support compression level for DO --- post-processor/vagrant/digitalocean.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/post-processor/vagrant/digitalocean.go b/post-processor/vagrant/digitalocean.go index 5c04b1210..3ff83d04e 100644 --- a/post-processor/vagrant/digitalocean.go +++ b/post-processor/vagrant/digitalocean.go @@ -1,6 +1,7 @@ package vagrant import ( + "compress/flate" "fmt" "github.com/mitchellh/packer/common" "github.com/mitchellh/packer/packer" @@ -8,6 +9,7 @@ import ( "log" "os" "path/filepath" + "strconv" "strings" ) @@ -16,6 +18,7 @@ type DigitalOceanBoxConfig struct { OutputPath string `mapstructure:"output"` VagrantfileTemplate string `mapstructure:"vagrantfile_template"` + CompressionLevel string `mapstructure:"compression_level"` tpl *packer.ConfigTemplate } @@ -47,6 +50,7 @@ func (p *DigitalOceanBoxPostProcessor) Configure(rDigitalOcean ...interface{}) e validates := map[string]*string{ "output": &p.config.OutputPath, "vagrantfile_template": &p.config.VagrantfileTemplate, + "compression_level": &p.config.CompressionLevel, } for n, ptr := range validates { @@ -132,7 +136,15 @@ func (p *DigitalOceanBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer } // Compress the directory to the given output path - if err := DirToBox(outputPath, dir, ui); err != nil { + var level int = flate.DefaultCompression + if p.config.CompressionLevel != "" { + level, err = strconv.Atoi(p.config.CompressionLevel) + if err != nil { + return nil, false, err + } + } + + if err := DirToBox(outputPath, dir, ui, level); err != nil { err = fmt.Errorf("error creating box: %s", err) return nil, false, err }