Commit e73c2247 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Build runs the post-processors

parent 75fe58d5
package packer
type TestArtifact struct{}
func (*TestArtifact) BuilderId() string {
return "bid"
}
func (*TestArtifact) Files() []string {
return []string{"a", "b"}
}
func (*TestArtifact) Id() string {
return "id"
}
func (*TestArtifact) String() string {
return "string"
}
package packer package packer
import ( import (
"fmt"
"log" "log"
"sync" "sync"
) )
...@@ -151,9 +152,35 @@ func (b *coreBuild) Run(ui Ui, cache Cache) ([]Artifact, error) { ...@@ -151,9 +152,35 @@ func (b *coreBuild) Run(ui Ui, cache Cache) ([]Artifact, error) {
hook := &DispatchHook{hooks} hook := &DispatchHook{hooks}
artifacts := make([]Artifact, 0, 1) artifacts := make([]Artifact, 0, 1)
artifact, err := b.builder.Run(ui, hook, cache) builderArtifact, err := b.builder.Run(ui, hook, cache)
if artifact != nil { if builderArtifact != nil {
artifacts = append(artifacts, artifact) artifacts = append(artifacts, builderArtifact)
}
if err != nil {
return artifacts, err
}
errors := make([]error, 0)
// Run the post-processors
PostProcessorRunSeqLoop:
for _, ppSeq := range b.postProcessors {
artifact := builderArtifact
for _, corePP := range ppSeq {
var err error
artifact, err = corePP.processor.PostProcess(artifact)
if err != nil {
errors = append(errors, fmt.Errorf("Post-processor failed: %s", err))
continue PostProcessorRunSeqLoop
}
artifacts = append(artifacts, artifact)
}
}
if len(errors) > 0 {
err = &MultiError{errors}
} }
return artifacts, err return artifacts, err
......
...@@ -107,7 +107,9 @@ func TestBuild_Run(t *testing.T) { ...@@ -107,7 +107,9 @@ func TestBuild_Run(t *testing.T) {
build := testBuild() build := testBuild()
build.Prepare() build.Prepare()
build.Run(ui, cache) artifacts, err := build.Run(ui, cache)
assert.Nil(err, "should not error")
assert.Equal(len(artifacts), 2, "should have two artifacts")
coreB := build.(*coreBuild) coreB := build.(*coreBuild)
...@@ -128,6 +130,10 @@ func TestBuild_Run(t *testing.T) { ...@@ -128,6 +130,10 @@ func TestBuild_Run(t *testing.T) {
dispatchHook.Run(HookProvision, nil, nil, 42) dispatchHook.Run(HookProvision, nil, nil, 42)
prov := coreB.provisioners[0].provisioner.(*TestProvisioner) prov := coreB.provisioners[0].provisioner.(*TestProvisioner)
assert.True(prov.provCalled, "provision should be called") assert.True(prov.provCalled, "provision should be called")
// Verify post-processor was run
pp := coreB.postProcessors[0][0].processor.(*TestPostProcessor)
assert.True(pp.ppCalled, "post processor should be called")
} }
func TestBuild_RunBeforePrepare(t *testing.T) { func TestBuild_RunBeforePrepare(t *testing.T) {
......
...@@ -21,7 +21,7 @@ func (tb *TestBuilder) Run(ui Ui, h Hook, c Cache) (Artifact, error) { ...@@ -21,7 +21,7 @@ func (tb *TestBuilder) Run(ui Ui, h Hook, c Cache) (Artifact, error) {
tb.runHook = h tb.runHook = h
tb.runUi = ui tb.runUi = ui
tb.runCache = c tb.runCache = c
return nil, nil return new(TestArtifact), nil
} }
func (tb *TestBuilder) Cancel() { func (tb *TestBuilder) Cancel() {
......
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