diff --git a/client/driver/docker.go b/client/driver/docker.go index 7571455e2..a3db2d1b5 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -538,7 +538,7 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle } if err := d.createImage(&driverConfig, client, taskDir); err != nil { - return nil, fmt.Errorf("failed to pull image: %v", err) + return nil, fmt.Errorf("failed to create image: %v", err) } // Now that we have the image we can get the image id diff --git a/client/driver/docker_test.go b/client/driver/docker_test.go index 589adf349..26e02febb 100644 --- a/client/driver/docker_test.go +++ b/client/driver/docker_test.go @@ -15,6 +15,7 @@ import ( docker "github.com/fsouza/go-dockerclient" "github.com/hashicorp/go-plugin" + "github.com/hashicorp/nomad/client/allocdir" "github.com/hashicorp/nomad/client/config" "github.com/hashicorp/nomad/client/driver/env" cstructs "github.com/hashicorp/nomad/client/driver/structs" @@ -254,6 +255,68 @@ func TestDockerDriver_Start_Wait(t *testing.T) { } } +func TestDockerDriver_Start_LoadImage(t *testing.T) { + task := &structs.Task{ + Name: "busybox-demo", + Config: map[string]interface{}{ + "image": "busybox", + "load": "busybox.tar", + "command": "/bin/echo", + "args": []string{ + "hello", + }, + }, + LogConfig: &structs.LogConfig{ + MaxFiles: 10, + MaxFileSizeMB: 10, + }, + Resources: &structs.Resources{ + MemoryMB: 256, + CPU: 512, + }, + } + + driverCtx, execCtx := testDriverContexts(task) + defer execCtx.AllocDir.Destroy() + d := NewDockerDriver(driverCtx) + + // Copy the test jar into the task's directory + taskDir, _ := execCtx.AllocDir.TaskDirs[task.Name] + dst := filepath.Join(taskDir, allocdir.TaskLocal, "busybox.tar") + copyFile("./test-resources/docker/busybox.tar", dst, t) + + handle, err := d.Start(execCtx, task) + if err != nil { + t.Fatalf("err: %v", err) + } + if handle == nil { + t.Fatalf("missing handle") + } + defer handle.Kill() + + select { + case res := <-handle.WaitCh(): + if !res.Successful() { + t.Fatalf("err: %v", res) + } + case <-time.After(time.Duration(tu.TestMultiplier()*5) * time.Second): + t.Fatalf("timeout") + } + + // Check that data was written to the shared alloc directory. + outputFile := filepath.Join(execCtx.AllocDir.LogDir(), "busybox-demo.stdout.0") + act, err := ioutil.ReadFile(outputFile) + if err != nil { + t.Fatalf("Couldn't read expected output: %v", err) + } + + exp := "hello" + if strings.TrimSpace(string(act)) != exp { + t.Fatalf("Command outputted %v; want %v", act, exp) + } + +} + func TestDockerDriver_Start_Wait_AllocDir(t *testing.T) { t.Parallel() // This test requires that the alloc dir be mounted into docker as a volume. diff --git a/client/driver/test-resources/docker/busybox.tar b/client/driver/test-resources/docker/busybox.tar new file mode 100644 index 000000000..9025b5f63 --- /dev/null +++ b/client/driver/test-resources/docker/busybox.tar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c159f9e490784831cbacf5816c55b68b230516b5347b0f876a72bbc1564b8e29 +size 1324544