2013-11-09 01:00:57 -05:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
2013-11-09 20:21:24 -05:00
|
|
|
"log"
|
2013-11-09 01:00:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type StepPull struct{}
|
|
|
|
|
|
|
|
func (s *StepPull) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
config := state.Get("config").(*Config)
|
2013-11-09 15:12:23 -05:00
|
|
|
driver := state.Get("driver").(Driver)
|
2013-11-09 01:00:57 -05:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
2013-11-09 20:21:24 -05:00
|
|
|
if !config.Pull {
|
|
|
|
log.Println("Pull disabled, won't docker pull")
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-11-09 01:00:57 -05:00
|
|
|
ui.Say(fmt.Sprintf("Pulling Docker image: %s", config.Image))
|
2013-11-09 15:12:23 -05:00
|
|
|
if err := driver.Pull(config.Image); err != nil {
|
2013-11-09 01:00:57 -05:00
|
|
|
err := fmt.Errorf("Error pulling Docker image: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepPull) Cleanup(state multistep.StateBag) {
|
|
|
|
}
|