post-processor/vagrant: simplify logic, only send overrides to PP
[GH-413] /cc @jasonberanek
This commit is contained in:
parent
6fc89e9584
commit
aa694072d7
@ -26,13 +26,10 @@ type Config struct {
|
|||||||
type PostProcessor struct {
|
type PostProcessor struct {
|
||||||
config Config
|
config Config
|
||||||
premade map[string]packer.PostProcessor
|
premade map[string]packer.PostProcessor
|
||||||
rawConfigs []interface{}
|
extraConfig map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PostProcessor) Configure(raws ...interface{}) error {
|
func (p *PostProcessor) Configure(raws ...interface{}) error {
|
||||||
// Store the raw configs for usage later
|
|
||||||
p.rawConfigs = raws
|
|
||||||
|
|
||||||
_, err := common.DecodeConfig(&p.config, raws...)
|
_, err := common.DecodeConfig(&p.config, raws...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -57,11 +54,8 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store extra configuration we'll send to each post-processor type
|
// Store extra configuration we'll send to each post-processor type
|
||||||
ppExtraConfig := make(map[string]interface{})
|
p.extraConfig = make(map[string]interface{})
|
||||||
ppExtraConfig["output"] = p.config.OutputPath
|
p.extraConfig["output"] = p.config.OutputPath
|
||||||
|
|
||||||
// Store the extra configuration for post-processors
|
|
||||||
p.rawConfigs = append(p.rawConfigs, ppExtraConfig)
|
|
||||||
|
|
||||||
// TODO(mitchellh): Properly handle multiple raw configs. This isn't
|
// TODO(mitchellh): Properly handle multiple raw configs. This isn't
|
||||||
// very pressing at the moment because at the time of this comment
|
// very pressing at the moment because at the time of this comment
|
||||||
@ -75,18 +69,14 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
|
|||||||
|
|
||||||
p.premade = make(map[string]packer.PostProcessor)
|
p.premade = make(map[string]packer.PostProcessor)
|
||||||
for k, raw := range mapConfig {
|
for k, raw := range mapConfig {
|
||||||
pp := keyToPostProcessor(k)
|
pp, err := p.subPostProcessor(k, raw, p.extraConfig)
|
||||||
if pp == nil {
|
if err != nil {
|
||||||
|
errs = packer.MultiErrorAppend(errs, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the proper list of configurations
|
if pp == nil {
|
||||||
ppConfigs := make([]interface{}, len(p.rawConfigs), len(p.rawConfigs)+1)
|
continue
|
||||||
copy(ppConfigs, p.rawConfigs)
|
|
||||||
ppConfigs = append(ppConfigs, raw)
|
|
||||||
|
|
||||||
if err := pp.Configure(ppConfigs...); err != nil {
|
|
||||||
errs = packer.MultiErrorAppend(errs, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p.premade[k] = pp
|
p.premade[k] = pp
|
||||||
@ -110,13 +100,15 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
|
|||||||
pp, ok := p.premade[ppName]
|
pp, ok := p.premade[ppName]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Printf("Premade post-processor for '%s' not found. Creating.", ppName)
|
log.Printf("Premade post-processor for '%s' not found. Creating.", ppName)
|
||||||
pp = keyToPostProcessor(ppName)
|
|
||||||
if pp == nil {
|
var err error
|
||||||
return nil, false, fmt.Errorf("Vagrant box post-processor not found: %s", ppName)
|
pp, err = p.subPostProcessor(ppName, nil, p.extraConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pp.Configure(p.rawConfigs...); err != nil {
|
if pp == nil {
|
||||||
return nil, false, err
|
return nil, false, fmt.Errorf("Vagrant box post-processor not found: %s", ppName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +116,21 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
|
|||||||
return pp.PostProcess(ui, artifact)
|
return pp.PostProcess(ui, artifact)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PostProcessor) subPostProcessor(key string, specific interface{}, extra map[string]interface{}) (packer.PostProcessor, error) {
|
||||||
|
pp := keyToPostProcessor(key)
|
||||||
|
if pp == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := pp.Configure(extra, specific); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return pp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// keyToPostProcessor maps a configuration key to the actual post-processor
|
||||||
|
// it will be configuring. This returns a new instance of that post-processor.
|
||||||
func keyToPostProcessor(key string) packer.PostProcessor {
|
func keyToPostProcessor(key string) packer.PostProcessor {
|
||||||
switch key {
|
switch key {
|
||||||
case "aws":
|
case "aws":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user