From ff6a5aa799334a538defbad9560fb2149b25ea35 Mon Sep 17 00:00:00 2001 From: Michal Wieczorek Date: Sun, 19 Jun 2016 22:56:09 +0200 Subject: [PATCH] Volume binds for windows containers --- client/allocdir/alloc_dir_unix.go | 9 +++++++++ client/allocdir/alloc_dir_windows.go | 9 +++++++++ client/driver/docker.go | 8 ++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/client/allocdir/alloc_dir_unix.go b/client/allocdir/alloc_dir_unix.go index b03fd8e9d45..339e59d5d12 100644 --- a/client/allocdir/alloc_dir_unix.go +++ b/client/allocdir/alloc_dir_unix.go @@ -7,11 +7,20 @@ import ( "fmt" "os" "os/user" + "path/filepath" "strconv" "golang.org/x/sys/unix" ) +var ( + //Path inside container for mounted directory shared across tasks in a task group. + SharedAllocContainerPath = filepath.Join("/", SharedAllocName) + + //Path inside container for mounted directory for local storage. + TaskLocalContainerPath = filepath.Join("/", TaskLocal) +) + func (d *AllocDir) linkOrCopy(src, dst string, perm os.FileMode) error { // Attempt to hardlink. if err := os.Link(src, dst); err == nil { diff --git a/client/allocdir/alloc_dir_windows.go b/client/allocdir/alloc_dir_windows.go index 7211125ae86..112fe9b63bd 100644 --- a/client/allocdir/alloc_dir_windows.go +++ b/client/allocdir/alloc_dir_windows.go @@ -3,6 +3,15 @@ package allocdir import ( "errors" "os" + "path/filepath" +) + +var ( + //Path inside container for mounted directory that is shared across tasks in a task group. + SharedAllocContainerPath = filepath.Join("c:\\", SharedAllocName) + + //Path inside container for mounted directory for local storage. + TaskLocalContainerPath = filepath.Join("c:\\", TaskLocal) ) func (d *AllocDir) linkOrCopy(src, dst string, perm os.FileMode) error { diff --git a/client/driver/docker.go b/client/driver/docker.go index c0ef89ca6a9..a39f2351cb7 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -321,8 +321,8 @@ func (d *DockerDriver) containerBinds(alloc *allocdir.AllocDir, task *structs.Ta return nil, fmt.Errorf("Failed to find task local directory: %v", task.Name) } - allocDirBind := fmt.Sprintf("%s:/%s", shared, allocdir.SharedAllocName) - taskLocalBind := fmt.Sprintf("%s:/%s", local, allocdir.TaskLocal) + allocDirBind := fmt.Sprintf("%s:%s", shared, allocdir.SharedAllocContainerPath) + taskLocalBind := fmt.Sprintf("%s:%s", local, allocdir.TaskLocalContainerPath) if selinuxLabel := d.config.Read("docker.volumes.selinuxlabel"); selinuxLabel != "" { allocDirBind = fmt.Sprintf("%s:%s", allocDirBind, selinuxLabel) @@ -351,8 +351,8 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task, } // Set environment variables. - d.taskEnv.SetAllocDir(filepath.Join("/", allocdir.SharedAllocName)) - d.taskEnv.SetTaskLocalDir(filepath.Join("/", allocdir.TaskLocal)) + d.taskEnv.SetAllocDir(allocdir.SharedAllocContainerPath) + d.taskEnv.SetTaskLocalDir(allocdir.TaskLocalContainerPath) config := &docker.Config{ Image: driverConfig.ImageName,