From 185d2765befb908467153c3e0ab1a282c07e975e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 10 May 2013 13:01:54 -0700 Subject: [PATCH] command/build: Run the builds in parallel --- builder/amazonebs/builder.go | 6 +++++- command/build/command.go | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/builder/amazonebs/builder.go b/builder/amazonebs/builder.go index c89d906a8..c0ca44868 100644 --- a/builder/amazonebs/builder.go +++ b/builder/amazonebs/builder.go @@ -38,7 +38,11 @@ func (b *Builder) Prepare(raw interface{}) (err error) { } log.Printf("Config: %+v\n", b.config) + + // TODO: Validate the configuration return } -func (*Builder) Run(packer.Build, packer.Ui) {} +func (*Builder) Run(b packer.Build, ui packer.Ui) { + ui.Say("Building an AWS image...\n") +} diff --git a/command/build/command.go b/command/build/command.go index 19ab76e2b..85dcfe399 100644 --- a/command/build/command.go +++ b/command/build/command.go @@ -4,6 +4,7 @@ import ( "github.com/mitchellh/packer/packer" "io/ioutil" "log" + "sync" ) type Command byte @@ -54,6 +55,23 @@ func (Command) Run(env packer.Environment, args []string) int { } } + // Run all the builds in parallel and wait for them to complete + var wg sync.WaitGroup + for _, b := range builds { + log.Printf("Starting build run: %s\n", b.Name()) + + // Increment the waitgroup so we wait for this item to finish properly + wg.Add(1) + + // Run the build in a goroutine + go func() { + defer wg.Done() + b.Run(env.Ui()) + }() + } + + wg.Wait() + env.Ui().Say("YAY!\n") return 0 }