Commit 29a22591 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

post-processor/vagrant: support compression level for DO

parent c6392481
package vagrant package vagrant
import ( import (
"compress/flate"
"fmt" "fmt"
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
...@@ -8,6 +9,7 @@ import ( ...@@ -8,6 +9,7 @@ import (
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
) )
...@@ -16,6 +18,7 @@ type DigitalOceanBoxConfig struct { ...@@ -16,6 +18,7 @@ type DigitalOceanBoxConfig struct {
OutputPath string `mapstructure:"output"` OutputPath string `mapstructure:"output"`
VagrantfileTemplate string `mapstructure:"vagrantfile_template"` VagrantfileTemplate string `mapstructure:"vagrantfile_template"`
CompressionLevel string `mapstructure:"compression_level"`
tpl *packer.ConfigTemplate tpl *packer.ConfigTemplate
} }
...@@ -47,6 +50,7 @@ func (p *DigitalOceanBoxPostProcessor) Configure(rDigitalOcean ...interface{}) e ...@@ -47,6 +50,7 @@ func (p *DigitalOceanBoxPostProcessor) Configure(rDigitalOcean ...interface{}) e
validates := map[string]*string{ validates := map[string]*string{
"output": &p.config.OutputPath, "output": &p.config.OutputPath,
"vagrantfile_template": &p.config.VagrantfileTemplate, "vagrantfile_template": &p.config.VagrantfileTemplate,
"compression_level": &p.config.CompressionLevel,
} }
for n, ptr := range validates { for n, ptr := range validates {
...@@ -132,7 +136,15 @@ func (p *DigitalOceanBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer ...@@ -132,7 +136,15 @@ func (p *DigitalOceanBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer
} }
// Compress the directory to the given output path // 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) err = fmt.Errorf("error creating box: %s", err)
return nil, false, err return nil, false, err
} }
......
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