post-processor/vagrant: support compression level for DO
This commit is contained in:
parent
c6392481f9
commit
29a22591f9
|
@ -1,6 +1,7 @@
|
||||||
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 (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue