From fd2d8480e1b3c3bed1f6822037e3ecf28c1bd643 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 8 May 2013 16:59:36 -0700 Subject: [PATCH] Lots more logging everywhere --- command/build/command.go | 24 +++++++++++++++++------- packer/environment.go | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/command/build/command.go b/command/build/command.go index 664162be1..7092a6868 100644 --- a/command/build/command.go +++ b/command/build/command.go @@ -3,6 +3,7 @@ package build import ( "github.com/mitchellh/packer/packer" "io/ioutil" + "log" ) type Command byte @@ -14,6 +15,7 @@ func (Command) Run(env packer.Environment, args []string) int { } // Read the file into a byte array so that we can parse the template + log.Printf("Reading template: %s\n", args[0]) tplData, err := ioutil.ReadFile(args[0]) if err != nil { env.Ui().Error("Failed to read template file: %s\n", err.Error()) @@ -21,20 +23,28 @@ func (Command) Run(env packer.Environment, args []string) int { } // Parse the template into a machine-usable format - _, err = packer.ParseTemplate(tplData) + log.Println("Parsing template...") + tpl, err := packer.ParseTemplate(tplData) if err != nil { env.Ui().Error("Failed to parse template: %s\n", err.Error()) return 1 } // Go through each builder and compile the builds that we care about - //builds := make([]Build, 0, len(tpl.Builders)) - //for name, rawConfig := range tpl.Builders { - //builder := env.Builder(name, rawConfig) - //build := env.Build(name, builder) - //builds = append(builds, build) - //} + buildNames := tpl.BuildNames() + builds := make([]packer.Build, 0, len(buildNames)) + for _, buildName := range buildNames { + log.Printf("Creating build: %s\n", buildName) + build, err := tpl.Build(buildName, env.Builder) + if err != nil { + env.Ui().Error("Failed to create build '%s': \n\n%s\n", buildName, err) + return 1 + } + + builds = append(builds, build) + } + env.Ui().Say("YAY!\n") return 0 } diff --git a/packer/environment.go b/packer/environment.go index 4dd3401e0..7838602da 100644 --- a/packer/environment.go +++ b/packer/environment.go @@ -124,6 +124,7 @@ func (e *coreEnvironment) Cli(args []string) (result int, err error) { } } + log.Printf("Executing command: %s\n", args[0]) return command.Run(e, args[1:]), nil }