Commit 521b59a6 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Make everything support the new builder interface

parent 12cc8e98
...@@ -100,21 +100,7 @@ func (b *Builder) Prepare(raw interface{}) error { ...@@ -100,21 +100,7 @@ func (b *Builder) Prepare(raw interface{}) error {
return nil return nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer.Artifact { func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
// Basic sanity checks. These are panics now because the Prepare
// method should verify these exist and such.
if b.config.AccessKey == "" {
panic("access key not filled in")
}
if b.config.SecretKey == "" {
panic("secret key not filled in")
}
if b.config.Region == "" {
panic("region not filled in")
}
region, ok := aws.Regions[b.config.Region] region, ok := aws.Regions[b.config.Region]
if !ok { if !ok {
panic("region not found") panic("region not found")
...@@ -147,11 +133,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer ...@@ -147,11 +133,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer
// If there are no AMIs, then jsut return // If there are no AMIs, then jsut return
if _, ok := state["amis"]; !ok { if _, ok := state["amis"]; !ok {
return nil return nil, nil
} }
// Build the artifact and return it // Build the artifact and return it
return &artifact{state["amis"].(map[string]string)} return &artifact{state["amis"].(map[string]string)}, nil
} }
func (b *Builder) Cancel() { func (b *Builder) Cancel() {
......
...@@ -169,7 +169,7 @@ func (b *Builder) Prepare(raw interface{}) error { ...@@ -169,7 +169,7 @@ func (b *Builder) Prepare(raw interface{}) error {
return nil return nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer.Artifact { func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
steps := []multistep.Step{ steps := []multistep.Step{
new(stepDownloadISO), new(stepDownloadISO),
new(stepPrepareOutputDir), new(stepPrepareOutputDir),
...@@ -197,7 +197,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer ...@@ -197,7 +197,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer
b.runner = &multistep.BasicRunner{Steps: steps} b.runner = &multistep.BasicRunner{Steps: steps}
b.runner.Run(state) b.runner.Run(state)
return nil return nil, nil
} }
func (b *Builder) Cancel() { func (b *Builder) Cancel() {
......
...@@ -184,7 +184,7 @@ func (b *Builder) Prepare(raw interface{}) error { ...@@ -184,7 +184,7 @@ func (b *Builder) Prepare(raw interface{}) error {
return nil return nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer.Artifact { func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
// Seed the random number generator // Seed the random number generator
rand.Seed(time.Now().UTC().UnixNano()) rand.Seed(time.Now().UTC().UnixNano())
...@@ -216,11 +216,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer ...@@ -216,11 +216,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer
// If we were interrupted or cancelled, then just exit. // If we were interrupted or cancelled, then just exit.
if _, ok := state[multistep.StateCancelled]; ok { if _, ok := state[multistep.StateCancelled]; ok {
return nil return nil, nil
} }
if _, ok := state[multistep.StateHalted]; ok { if _, ok := state[multistep.StateHalted]; ok {
return nil return nil, nil
} }
// Compile the artifact list // Compile the artifact list
...@@ -231,11 +231,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer ...@@ -231,11 +231,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer
} }
if err := filepath.Walk(b.config.OutputDir, visit); err != nil { if err := filepath.Walk(b.config.OutputDir, visit); err != nil {
ui.Error(fmt.Sprintf("Error collecting result files: %s", err)) return nil, err
return nil
} }
return &Artifact{b.config.OutputDir, files} return &Artifact{b.config.OutputDir, files}, nil
} }
func (b *Builder) Cancel() { func (b *Builder) Cancel() {
......
...@@ -139,10 +139,16 @@ func (c Command) Run(env packer.Environment, args []string) int { ...@@ -139,10 +139,16 @@ func (c Command) Run(env packer.Environment, args []string) int {
go func(b packer.Build) { go func(b packer.Build) {
defer wg.Done() defer wg.Done()
var err error
log.Printf("Starting build run: %s", b.Name()) log.Printf("Starting build run: %s", b.Name())
ui := buildUis[b.Name()] ui := buildUis[b.Name()]
artifacts[b.Name()] = b.Run(ui, env.Cache()) artifacts[b.Name()], err = b.Run(ui, env.Cache())
ui.Say("Build finished.")
if err != nil {
ui.Error(fmt.Sprintf("Build errored: %s", err))
} else {
ui.Say("Build finished.")
}
}(b) }(b)
} }
......
...@@ -19,7 +19,7 @@ func (b *cmdBuilder) Prepare(config interface{}) error { ...@@ -19,7 +19,7 @@ func (b *cmdBuilder) Prepare(config interface{}) error {
return b.builder.Prepare(config) return b.builder.Prepare(config)
} }
func (b *cmdBuilder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer.Artifact { func (b *cmdBuilder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
defer func() { defer func() {
r := recover() r := recover()
b.checkExit(r, nil) b.checkExit(r, nil)
......
...@@ -12,8 +12,8 @@ func (helperBuilder) Prepare(interface{}) error { ...@@ -12,8 +12,8 @@ func (helperBuilder) Prepare(interface{}) error {
return nil return nil
} }
func (helperBuilder) Run(packer.Ui, packer.Hook, packer.Cache) packer.Artifact { func (helperBuilder) Run(packer.Ui, packer.Hook, packer.Cache) (packer.Artifact, error) {
return nil return nil, nil
} }
func (helperBuilder) Cancel() {} func (helperBuilder) Cancel() {}
......
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