Make everything support the new builder interface
This commit is contained in:
parent
12cc8e98aa
commit
521b59a6fa
|
@ -100,21 +100,7 @@ func (b *Builder) Prepare(raw interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer.Artifact {
|
||||
// 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")
|
||||
}
|
||||
|
||||
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
||||
region, ok := aws.Regions[b.config.Region]
|
||||
if !ok {
|
||||
panic("region not found")
|
||||
|
@ -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 _, ok := state["amis"]; !ok {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 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() {
|
||||
|
|
|
@ -169,7 +169,7 @@ func (b *Builder) Prepare(raw interface{}) error {
|
|||
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{
|
||||
new(stepDownloadISO),
|
||||
new(stepPrepareOutputDir),
|
||||
|
@ -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.Run(state)
|
||||
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (b *Builder) Cancel() {
|
||||
|
|
|
@ -184,7 +184,7 @@ func (b *Builder) Prepare(raw interface{}) error {
|
|||
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
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
|
||||
|
@ -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 _, ok := state[multistep.StateCancelled]; ok {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if _, ok := state[multistep.StateHalted]; ok {
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Compile the artifact list
|
||||
|
@ -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 {
|
||||
ui.Error(fmt.Sprintf("Error collecting result files: %s", err))
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Artifact{b.config.OutputDir, files}
|
||||
return &Artifact{b.config.OutputDir, files}, nil
|
||||
}
|
||||
|
||||
func (b *Builder) Cancel() {
|
||||
|
|
|
@ -139,10 +139,16 @@ func (c Command) Run(env packer.Environment, args []string) int {
|
|||
go func(b packer.Build) {
|
||||
defer wg.Done()
|
||||
|
||||
var err error
|
||||
log.Printf("Starting build run: %s", b.Name())
|
||||
ui := buildUis[b.Name()]
|
||||
artifacts[b.Name()] = b.Run(ui, env.Cache())
|
||||
artifacts[b.Name()], err = b.Run(ui, env.Cache())
|
||||
|
||||
if err != nil {
|
||||
ui.Error(fmt.Sprintf("Build errored: %s", err))
|
||||
} else {
|
||||
ui.Say("Build finished.")
|
||||
}
|
||||
}(b)
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ func (b *cmdBuilder) Prepare(config interface{}) error {
|
|||
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() {
|
||||
r := recover()
|
||||
b.checkExit(r, nil)
|
||||
|
|
|
@ -12,8 +12,8 @@ func (helperBuilder) Prepare(interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (helperBuilder) Run(packer.Ui, packer.Hook, packer.Cache) packer.Artifact {
|
||||
return nil
|
||||
func (helperBuilder) Run(packer.Ui, packer.Hook, packer.Cache) (packer.Artifact, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (helperBuilder) Cancel() {}
|
||||
|
|
Loading…
Reference in New Issue