command/build: Run the builds in parallel

This commit is contained in:
Mitchell Hashimoto 2013-05-10 13:01:54 -07:00
parent 077f15bdfb
commit 185d2765be
2 changed files with 23 additions and 1 deletions

View File

@ -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")
}

View File

@ -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
}