command/build: Run the builds in parallel

pull/15/head
Mitchell Hashimoto 13 years ago
parent 077f15bdfb
commit 185d2765be

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

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

Loading…
Cancel
Save