Commit eaf76618 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

post-processor/vagrant: compression_level is an int

parent ac36b33f
...@@ -13,7 +13,6 @@ import ( ...@@ -13,7 +13,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strconv"
) )
type VBoxBoxConfig struct { type VBoxBoxConfig struct {
...@@ -21,7 +20,7 @@ type VBoxBoxConfig struct { ...@@ -21,7 +20,7 @@ type VBoxBoxConfig struct {
OutputPath string `mapstructure:"output"` OutputPath string `mapstructure:"output"`
VagrantfileTemplate string `mapstructure:"vagrantfile_template"` VagrantfileTemplate string `mapstructure:"vagrantfile_template"`
CompressionLevel string `mapstructure:"compression_level"` CompressionLevel int `mapstructure:"compression_level"`
tpl *packer.ConfigTemplate tpl *packer.ConfigTemplate
} }
...@@ -46,13 +45,26 @@ func (p *VBoxBoxPostProcessor) Configure(raws ...interface{}) error { ...@@ -46,13 +45,26 @@ func (p *VBoxBoxPostProcessor) Configure(raws ...interface{}) error {
} }
p.config.tpl.UserVars = p.config.PackerUserVars p.config.tpl.UserVars = p.config.PackerUserVars
// Defaults
found := false
for _, k := range md.Keys {
println(k)
if k == "compression_level" {
found = true
break
}
}
if !found {
p.config.CompressionLevel = flate.DefaultCompression
}
// Accumulate any errors // Accumulate any errors
errs := common.CheckUnusedConfig(md) errs := common.CheckUnusedConfig(md)
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 {
...@@ -145,14 +157,6 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac ...@@ -145,14 +157,6 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
vf.Write([]byte(vagrantfileContents)) vf.Write([]byte(vagrantfileContents))
vf.Close() vf.Close()
var level int = flate.DefaultCompression
if p.config.CompressionLevel != "" {
level, err = strconv.Atoi(p.config.CompressionLevel)
if err != nil {
return nil, false, err
}
}
// Create the metadata // Create the metadata
metadata := map[string]string{"provider": "virtualbox"} metadata := map[string]string{"provider": "virtualbox"}
if err := WriteMetadata(dir, metadata); err != nil { if err := WriteMetadata(dir, metadata); err != nil {
...@@ -167,7 +171,7 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac ...@@ -167,7 +171,7 @@ func (p *VBoxBoxPostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifac
// Compress the directory to the given output path // Compress the directory to the given output path
ui.Message(fmt.Sprintf("Compressing box...")) ui.Message(fmt.Sprintf("Compressing box..."))
if err := DirToBox(outputPath, dir, ui, level); err != nil { if err := DirToBox(outputPath, dir, ui, p.config.CompressionLevel); err != nil {
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