builder/docker: verify docker is available on path
This commit is contained in:
parent
53c40cdbc5
commit
832b4408a5
@ -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) {
|
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{
|
steps := []multistep.Step{
|
||||||
&StepTempDir{},
|
&StepTempDir{},
|
||||||
&StepPull{},
|
&StepPull{},
|
||||||
@ -40,9 +45,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||||||
state.Put("ui", ui)
|
state.Put("ui", ui)
|
||||||
|
|
||||||
// Setup the driver that will talk to Docker
|
// Setup the driver that will talk to Docker
|
||||||
state.Put("driver", &DockerDriver{
|
state.Put("driver", driver)
|
||||||
Ui: ui,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Run!
|
// Run!
|
||||||
if b.config.PackerDebug {
|
if b.config.PackerDebug {
|
||||||
|
@ -20,6 +20,9 @@ type Driver interface {
|
|||||||
|
|
||||||
// StopContainer forcibly stops a container.
|
// StopContainer forcibly stops a container.
|
||||||
StopContainer(id string) error
|
StopContainer(id string) error
|
||||||
|
|
||||||
|
// Verify verifies that the driver can run
|
||||||
|
Verify() error
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerConfig is the configuration used to start a container.
|
// 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 {
|
func (d *DockerDriver) StopContainer(id string) error {
|
||||||
return exec.Command("docker", "kill", id).Run()
|
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
|
StartID string
|
||||||
StartError error
|
StartError error
|
||||||
StopError error
|
StopError error
|
||||||
|
VerifyError error
|
||||||
|
|
||||||
ExportCalled bool
|
ExportCalled bool
|
||||||
ExportID string
|
ExportID string
|
||||||
@ -21,6 +22,7 @@ type MockDriver struct {
|
|||||||
StartConfig *ContainerConfig
|
StartConfig *ContainerConfig
|
||||||
StopCalled bool
|
StopCalled bool
|
||||||
StopID string
|
StopID string
|
||||||
|
VerifyCalled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *MockDriver) Export(id string, dst io.Writer) error {
|
func (d *MockDriver) Export(id string, dst io.Writer) error {
|
||||||
@ -54,3 +56,8 @@ func (d *MockDriver) StopContainer(id string) error {
|
|||||||
d.StopID = id
|
d.StopID = id
|
||||||
return d.StopError
|
return d.StopError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *MockDriver) Verify() error {
|
||||||
|
d.VerifyCalled = true
|
||||||
|
return d.VerifyError
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user