packer: Build runs the post-processors
This commit is contained in:
parent
75fe58d5f7
commit
e73c224764
|
@ -0,0 +1,19 @@
|
|||
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"
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package packer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
)
|
||||
|
@ -151,9 +152,35 @@ func (b *coreBuild) Run(ui Ui, cache Cache) ([]Artifact, error) {
|
|||
hook := &DispatchHook{hooks}
|
||||
artifacts := make([]Artifact, 0, 1)
|
||||
|
||||
artifact, err := b.builder.Run(ui, hook, cache)
|
||||
if artifact != nil {
|
||||
artifacts = append(artifacts, artifact)
|
||||
builderArtifact, err := b.builder.Run(ui, hook, cache)
|
||||
if builderArtifact != nil {
|
||||
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
|
||||
|
|
|
@ -107,7 +107,9 @@ func TestBuild_Run(t *testing.T) {
|
|||
|
||||
build := testBuild()
|
||||
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)
|
||||
|
||||
|
@ -128,6 +130,10 @@ func TestBuild_Run(t *testing.T) {
|
|||
dispatchHook.Run(HookProvision, nil, nil, 42)
|
||||
prov := coreB.provisioners[0].provisioner.(*TestProvisioner)
|
||||
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) {
|
||||
|
|
|
@ -21,7 +21,7 @@ func (tb *TestBuilder) Run(ui Ui, h Hook, c Cache) (Artifact, error) {
|
|||
tb.runHook = h
|
||||
tb.runUi = ui
|
||||
tb.runCache = c
|
||||
return nil, nil
|
||||
return new(TestArtifact), nil
|
||||
}
|
||||
|
||||
func (tb *TestBuilder) Cancel() {
|
||||
|
|
Loading…
Reference in New Issue