packer: Improved logging around build runs

This commit is contained in:
Mitchell Hashimoto 2013-06-18 23:05:02 -07:00
parent 360a6939a4
commit f76027d449
3 changed files with 20 additions and 10 deletions

View File

@ -48,6 +48,7 @@ type coreBuild struct {
name string
builder Builder
builderConfig interface{}
builderType string
hooks map[string][]Hook
postProcessors [][]coreBuildPostProcessor
provisioners []coreBuildProvisioner
@ -61,6 +62,7 @@ type coreBuild struct {
// post-processor used within a build.
type coreBuildPostProcessor struct {
processor PostProcessor
processorType string
config interface{}
keepInputArtifact bool
}
@ -153,6 +155,7 @@ func (b *coreBuild) Run(ui Ui, cache Cache) ([]Artifact, error) {
hook := &DispatchHook{hooks}
artifacts := make([]Artifact, 0, 1)
log.Printf("Running builder: %s", b.builderType)
builderArtifact, err := b.builder.Run(ui, hook, cache)
if err != nil {
return nil, err
@ -166,6 +169,7 @@ PostProcessorRunSeqLoop:
for _, ppSeq := range b.postProcessors {
priorArtifact := builderArtifact
for i, corePP := range ppSeq {
ui.Say(fmt.Sprintf("Running post-processor: %s", corePP.processorType))
artifact, err := corePP.processor.PostProcess(ui, priorArtifact)
if err != nil {
errors = append(errors, fmt.Errorf("Post-processor failed: %s", err))
@ -181,8 +185,11 @@ PostProcessorRunSeqLoop:
// This is the first post-processor. We handle deleting
// previous artifacts a bit different because multiple
// post-processors may be using the original and need it.
if !keepOriginalArtifact {
keepOriginalArtifact = corePP.keepInputArtifact
if !keepOriginalArtifact && corePP.keepInputArtifact {
log.Printf(
"Flagging to keep original artifact from post-processor '%s'",
corePP.processorType)
keepOriginalArtifact = true
}
} else {
// We have a prior artifact. If we want to keep it, we append
@ -190,6 +197,7 @@ PostProcessorRunSeqLoop:
if corePP.keepInputArtifact {
artifacts = append(artifacts, priorArtifact)
} else {
log.Printf("Deleting prior artifact from post-processor '%s'", corePP.processorType)
if err := priorArtifact.Destroy(); err != nil {
errors = append(errors, fmt.Errorf("Failed cleaning up prior artifact: %s", err))
}

View File

@ -19,7 +19,7 @@ func testBuild() *coreBuild {
},
postProcessors: [][]coreBuildPostProcessor{
[]coreBuildPostProcessor{
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp"}, 42, true},
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp"}, "testPP", 42, true},
},
},
}
@ -163,7 +163,7 @@ func TestBuild_Run_Artifacts(t *testing.T) {
build = testBuild()
build.postProcessors = [][]coreBuildPostProcessor{
[]coreBuildPostProcessor{
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp"}, 42, false},
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp"}, "pp", 42, false},
},
}
@ -188,10 +188,10 @@ func TestBuild_Run_Artifacts(t *testing.T) {
build = testBuild()
build.postProcessors = [][]coreBuildPostProcessor{
[]coreBuildPostProcessor{
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp1"}, 42, false},
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp1"}, "pp", 42, false},
},
[]coreBuildPostProcessor{
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp2"}, 42, true},
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp2"}, "pp", 42, true},
},
}
@ -216,12 +216,12 @@ func TestBuild_Run_Artifacts(t *testing.T) {
build = testBuild()
build.postProcessors = [][]coreBuildPostProcessor{
[]coreBuildPostProcessor{
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp1a"}, 42, false},
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp1b"}, 42, true},
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp1a"}, "pp", 42, false},
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp1b"}, "pp", 42, true},
},
[]coreBuildPostProcessor{
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp2a"}, 42, false},
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp2b"}, 42, false},
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp2a"}, "pp", 42, false},
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp2b"}, "pp", 42, false},
},
}

View File

@ -302,6 +302,7 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
current[i] = coreBuildPostProcessor{
processor: pp,
processorType: rawPP.Type,
config: rawPP.rawConfig,
keepInputArtifact: rawPP.KeepInputArtifact,
}
@ -341,6 +342,7 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
name: name,
builder: builder,
builderConfig: builderConfig.rawConfig,
builderType: builderConfig.Type,
hooks: hooks,
postProcessors: postProcessors,
provisioners: provisioners,