Commit 67993150 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Improved logging around build runs

parent b243eeda
...@@ -48,6 +48,7 @@ type coreBuild struct { ...@@ -48,6 +48,7 @@ type coreBuild struct {
name string name string
builder Builder builder Builder
builderConfig interface{} builderConfig interface{}
builderType string
hooks map[string][]Hook hooks map[string][]Hook
postProcessors [][]coreBuildPostProcessor postProcessors [][]coreBuildPostProcessor
provisioners []coreBuildProvisioner provisioners []coreBuildProvisioner
...@@ -61,6 +62,7 @@ type coreBuild struct { ...@@ -61,6 +62,7 @@ type coreBuild struct {
// post-processor used within a build. // post-processor used within a build.
type coreBuildPostProcessor struct { type coreBuildPostProcessor struct {
processor PostProcessor processor PostProcessor
processorType string
config interface{} config interface{}
keepInputArtifact bool keepInputArtifact bool
} }
...@@ -153,6 +155,7 @@ func (b *coreBuild) Run(ui Ui, cache Cache) ([]Artifact, error) { ...@@ -153,6 +155,7 @@ 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)
log.Printf("Running builder: %s", b.builderType)
builderArtifact, err := b.builder.Run(ui, hook, cache) builderArtifact, err := b.builder.Run(ui, hook, cache)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -166,6 +169,7 @@ PostProcessorRunSeqLoop: ...@@ -166,6 +169,7 @@ PostProcessorRunSeqLoop:
for _, ppSeq := range b.postProcessors { for _, ppSeq := range b.postProcessors {
priorArtifact := builderArtifact priorArtifact := builderArtifact
for i, corePP := range ppSeq { for i, corePP := range ppSeq {
ui.Say(fmt.Sprintf("Running post-processor: %s", corePP.processorType))
artifact, err := corePP.processor.PostProcess(ui, priorArtifact) artifact, err := corePP.processor.PostProcess(ui, priorArtifact)
if err != nil { if err != nil {
errors = append(errors, fmt.Errorf("Post-processor failed: %s", err)) errors = append(errors, fmt.Errorf("Post-processor failed: %s", err))
...@@ -181,8 +185,11 @@ PostProcessorRunSeqLoop: ...@@ -181,8 +185,11 @@ PostProcessorRunSeqLoop:
// This is the first post-processor. We handle deleting // This is the first post-processor. We handle deleting
// previous artifacts a bit different because multiple // previous artifacts a bit different because multiple
// post-processors may be using the original and need it. // post-processors may be using the original and need it.
if !keepOriginalArtifact { if !keepOriginalArtifact && corePP.keepInputArtifact {
keepOriginalArtifact = corePP.keepInputArtifact log.Printf(
"Flagging to keep original artifact from post-processor '%s'",
corePP.processorType)
keepOriginalArtifact = true
} }
} else { } else {
// We have a prior artifact. If we want to keep it, we append // We have a prior artifact. If we want to keep it, we append
...@@ -190,6 +197,7 @@ PostProcessorRunSeqLoop: ...@@ -190,6 +197,7 @@ PostProcessorRunSeqLoop:
if corePP.keepInputArtifact { if corePP.keepInputArtifact {
artifacts = append(artifacts, priorArtifact) artifacts = append(artifacts, priorArtifact)
} else { } else {
log.Printf("Deleting prior artifact from post-processor '%s'", corePP.processorType)
if err := priorArtifact.Destroy(); err != nil { if err := priorArtifact.Destroy(); err != nil {
errors = append(errors, fmt.Errorf("Failed cleaning up prior artifact: %s", err)) errors = append(errors, fmt.Errorf("Failed cleaning up prior artifact: %s", err))
} }
......
...@@ -19,7 +19,7 @@ func testBuild() *coreBuild { ...@@ -19,7 +19,7 @@ func testBuild() *coreBuild {
}, },
postProcessors: [][]coreBuildPostProcessor{ postProcessors: [][]coreBuildPostProcessor{
[]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) { ...@@ -163,7 +163,7 @@ func TestBuild_Run_Artifacts(t *testing.T) {
build = testBuild() build = testBuild()
build.postProcessors = [][]coreBuildPostProcessor{ build.postProcessors = [][]coreBuildPostProcessor{
[]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) { ...@@ -188,10 +188,10 @@ func TestBuild_Run_Artifacts(t *testing.T) {
build = testBuild() build = testBuild()
build.postProcessors = [][]coreBuildPostProcessor{ build.postProcessors = [][]coreBuildPostProcessor{
[]coreBuildPostProcessor{ []coreBuildPostProcessor{
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp1"}, 42, false}, coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp1"}, "pp", 42, false},
}, },
[]coreBuildPostProcessor{ []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) { ...@@ -216,12 +216,12 @@ func TestBuild_Run_Artifacts(t *testing.T) {
build = testBuild() build = testBuild()
build.postProcessors = [][]coreBuildPostProcessor{ build.postProcessors = [][]coreBuildPostProcessor{
[]coreBuildPostProcessor{ []coreBuildPostProcessor{
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp1a"}, 42, false}, coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp1a"}, "pp", 42, false},
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp1b"}, 42, true}, coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp1b"}, "pp", 42, true},
}, },
[]coreBuildPostProcessor{ []coreBuildPostProcessor{
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp2a"}, 42, false}, coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp2a"}, "pp", 42, false},
coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp2b"}, 42, false}, coreBuildPostProcessor{&TestPostProcessor{artifactId: "pp2b"}, "pp", 42, false},
}, },
} }
......
...@@ -302,6 +302,7 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err ...@@ -302,6 +302,7 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
current[i] = coreBuildPostProcessor{ current[i] = coreBuildPostProcessor{
processor: pp, processor: pp,
processorType: rawPP.Type,
config: rawPP.rawConfig, config: rawPP.rawConfig,
keepInputArtifact: rawPP.KeepInputArtifact, keepInputArtifact: rawPP.KeepInputArtifact,
} }
...@@ -341,6 +342,7 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err ...@@ -341,6 +342,7 @@ func (t *Template) Build(name string, components *ComponentFinder) (b Build, err
name: name, name: name,
builder: builder, builder: builder,
builderConfig: builderConfig.rawConfig, builderConfig: builderConfig.rawConfig,
builderType: builderConfig.Type,
hooks: hooks, hooks: hooks,
postProcessors: postProcessors, postProcessors: postProcessors,
provisioners: provisioners, provisioners: provisioners,
......
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