30 lines
690 B
Go
30 lines
690 B
Go
|
package docker
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/mitchellh/multistep"
|
||
|
"github.com/mitchellh/packer/packer"
|
||
|
"os/exec"
|
||
|
)
|
||
|
|
||
|
type StepPull struct{}
|
||
|
|
||
|
func (s *StepPull) Run(state multistep.StateBag) multistep.StepAction {
|
||
|
config := state.Get("config").(*Config)
|
||
|
ui := state.Get("ui").(packer.Ui)
|
||
|
|
||
|
ui.Say(fmt.Sprintf("Pulling Docker image: %s", config.Image))
|
||
|
cmd := exec.Command("docker", "pull", config.Image)
|
||
|
if err := runAndStream(cmd, ui); err != nil {
|
||
|
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) {
|
||
|
}
|