Commit 832b4408 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/docker: verify docker is available on path

parent 53c40cdb
......@@ -25,6 +25,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
driver := &DockerDriver{Ui: ui}
if err := driver.Verify(); err != nil {
return nil, err
}
steps := []multistep.Step{
&StepTempDir{},
&StepPull{},
......@@ -40,9 +45,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
state.Put("ui", ui)
// Setup the driver that will talk to Docker
state.Put("driver", &DockerDriver{
Ui: ui,
})
state.Put("driver", driver)
// Run!
if b.config.PackerDebug {
......
......@@ -20,6 +20,9 @@ type Driver interface {
// StopContainer forcibly stops a container.
StopContainer(id string) error
// Verify verifies that the driver can run
Verify() error
}
// ContainerConfig is the configuration used to start a container.
......
......@@ -82,3 +82,11 @@ func (d *DockerDriver) StartContainer(config *ContainerConfig) (string, error) {
func (d *DockerDriver) StopContainer(id string) error {
return exec.Command("docker", "kill", id).Run()
}
func (d *DockerDriver) Verify() error {
if _, err := exec.LookPath("docker"); err != nil {
return err
}
return nil
}
......@@ -12,6 +12,7 @@ type MockDriver struct {
StartID string
StartError error
StopError error
VerifyError error
ExportCalled bool
ExportID string
......@@ -21,6 +22,7 @@ type MockDriver struct {
StartConfig *ContainerConfig
StopCalled bool
StopID string
VerifyCalled bool
}
func (d *MockDriver) Export(id string, dst io.Writer) error {
......@@ -54,3 +56,8 @@ func (d *MockDriver) StopContainer(id string) error {
d.StopID = id
return d.StopError
}
func (d *MockDriver) Verify() error {
d.VerifyCalled = true
return d.VerifyError
}
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