github.com/rothwerx/packer@v0.9.0/builder/docker/step_pull.go (about) 1 package docker 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 "log" 8 ) 9 10 type StepPull struct{} 11 12 func (s *StepPull) Run(state multistep.StateBag) multistep.StepAction { 13 config := state.Get("config").(*Config) 14 driver := state.Get("driver").(Driver) 15 ui := state.Get("ui").(packer.Ui) 16 17 if !config.Pull { 18 log.Println("Pull disabled, won't docker pull") 19 return multistep.ActionContinue 20 } 21 22 ui.Say(fmt.Sprintf("Pulling Docker image: %s", config.Image)) 23 24 if config.Login { 25 ui.Message("Logging in...") 26 err := driver.Login( 27 config.LoginServer, 28 config.LoginEmail, 29 config.LoginUsername, 30 config.LoginPassword) 31 if err != nil { 32 err := fmt.Errorf("Error logging in: %s", err) 33 state.Put("error", err) 34 ui.Error(err.Error()) 35 return multistep.ActionHalt 36 } 37 38 defer func() { 39 ui.Message("Logging out...") 40 if err := driver.Logout(config.LoginServer); err != nil { 41 ui.Error(fmt.Sprintf("Error logging out: %s", err)) 42 } 43 }() 44 } 45 46 if err := driver.Pull(config.Image); err != nil { 47 err := fmt.Errorf("Error pulling Docker image: %s", err) 48 state.Put("error", err) 49 ui.Error(err.Error()) 50 return multistep.ActionHalt 51 } 52 53 return multistep.ActionContinue 54 } 55 56 func (s *StepPull) Cleanup(state multistep.StateBag) { 57 }