Commit 185d2765 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

command/build: Run the builds in parallel

parent 077f15bd
...@@ -38,7 +38,11 @@ func (b *Builder) Prepare(raw interface{}) (err error) { ...@@ -38,7 +38,11 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
} }
log.Printf("Config: %+v\n", b.config) log.Printf("Config: %+v\n", b.config)
// TODO: Validate the configuration
return 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 ( ...@@ -4,6 +4,7 @@ import (
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"io/ioutil" "io/ioutil"
"log" "log"
"sync"
) )
type Command byte type Command byte
...@@ -54,6 +55,23 @@ func (Command) Run(env packer.Environment, args []string) int { ...@@ -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") env.Ui().Say("YAY!\n")
return 0 return 0
} }
......
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