From f76027d44950c4df1716db0cbfa2139269f14f00 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 18 Jun 2013 23:05:02 -0700 Subject: [PATCH] packer: Improved logging around build runs --- packer/build.go | 12 ++++++++++-- packer/build_test.go | 16 ++++++++-------- packer/template.go | 2 ++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/packer/build.go b/packer/build.go index 3576041bc..c0d4b77d0 100644 --- a/packer/build.go +++ b/packer/build.go @@ -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)) } diff --git a/packer/build_test.go b/packer/build_test.go index fc6bea083..3be031ebf 100644 --- a/packer/build_test.go +++ b/packer/build_test.go @@ -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}, }, } diff --git a/packer/template.go b/packer/template.go index de10b437d..fa9a21195 100644 --- a/packer/template.go +++ b/packer/template.go @@ -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,