Commit c4fc365c authored by Chris Bednarski's avatar Chris Bednarski

Updated to reflect changes to template code

parent 52269b66
...@@ -10,6 +10,6 @@ func main() { ...@@ -10,6 +10,6 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
server.RegisterPostProcessor(new(compress.PostProcessor)) server.RegisterPostProcessor(new(compress.CompressPostProcessor))
server.Serve() server.Serve()
} }
...@@ -16,7 +16,9 @@ import ( ...@@ -16,7 +16,9 @@ import (
bgzf "github.com/biogo/hts/bgzf" bgzf "github.com/biogo/hts/bgzf"
pgzip "github.com/klauspost/pgzip" pgzip "github.com/klauspost/pgzip"
"github.com/mitchellh/packer/common" "github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
lz4 "github.com/pierrec/lz4" lz4 "github.com/pierrec/lz4"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
...@@ -40,7 +42,7 @@ type Config struct { ...@@ -40,7 +42,7 @@ type Config struct {
NumCPU int `mapstructure:"numcpu"` NumCPU int `mapstructure:"numcpu"`
Format string `mapstructure:"format"` Format string `mapstructure:"format"`
KeepInputArtifact bool `mapstructure:"keep_input_artifact"` KeepInputArtifact bool `mapstructure:"keep_input_artifact"`
tpl *packer.ConfigTemplate ctx *interpolate.Context
} }
type CompressPostProcessor struct { type CompressPostProcessor struct {
...@@ -49,24 +51,22 @@ type CompressPostProcessor struct { ...@@ -49,24 +51,22 @@ type CompressPostProcessor struct {
func (p *CompressPostProcessor) Configure(raws ...interface{}) error { func (p *CompressPostProcessor) Configure(raws ...interface{}) error {
p.cfg.Compression = -1 p.cfg.Compression = -1
_, err := common.DecodeConfig(&p.cfg, raws...) err := config.Decode(&p.cfg, &config.DecodeOpts{
if err != nil { Interpolate: true,
return err InterpolateFilter: &interpolate.RenderFilter{
} Exclude: []string{
// TODO figure out if something needs to go here.
},
},
}, raws...)
errs := new(packer.MultiError) errs := new(packer.MultiError)
p.cfg.tpl, err = packer.NewConfigTemplate()
if err != nil {
return err
}
p.cfg.tpl.UserVars = p.cfg.PackerUserVars
if p.cfg.OutputPath == "" { if p.cfg.OutputPath == "" {
p.cfg.OutputPath = "packer_{{.BuildName}}_{{.Provider}}" p.cfg.OutputPath = "packer_{{.BuildName}}_{{.Provider}}"
} }
if err = p.cfg.tpl.Validate(p.cfg.OutputPath); err != nil { if err = interpolate.Validate(p.cfg.OutputPath, p.cfg.ctx); err != nil {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error parsing target template: %s", err)) errs, fmt.Errorf("Error parsing target template: %s", err))
} }
...@@ -94,7 +94,7 @@ func (p *CompressPostProcessor) Configure(raws ...interface{}) error { ...@@ -94,7 +94,7 @@ func (p *CompressPostProcessor) Configure(raws ...interface{}) error {
errs, fmt.Errorf("%s must be set", key)) errs, fmt.Errorf("%s must be set", key))
} }
*ptr, err = p.cfg.tpl.Process(*ptr, nil) *ptr, err = interpolate.Render(p.cfg.OutputPath, p.cfg.ctx)
if err != nil { if err != nil {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing %s: %s", key, err)) errs, fmt.Errorf("Error processing %s: %s", key, 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