Skip to content

Commit

Permalink
Merge pull request #1877 from hashicorp/b-expand-docker-vols
Browse files Browse the repository at this point in the history
Expand env vars in docker volume paths
  • Loading branch information
schmichael authored Oct 27, 2016
2 parents 4fc7e30 + 98debf5 commit 01d47a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion client/driver/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,10 @@ func (d *DockerDriver) containerBinds(driverConfig *DockerDriverConfig, alloc *a
binds := []string{allocDirBind, taskLocalBind, secretDirBind}

volumesEnabled := d.config.ReadBoolDefault(dockerVolumesConfigOption, dockerVolumesConfigDefault)
for _, userbind := range driverConfig.Volumes {

// Expand environment variables in volume paths
expandedVols := d.taskEnv.ParseAndReplace(driverConfig.Volumes)
for _, userbind := range expandedVols {
parts := strings.Split(userbind, ":")
if len(parts) < 2 {
return nil, fmt.Errorf("invalid docker volume: %q", userbind)
Expand Down
6 changes: 4 additions & 2 deletions client/driver/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,16 +950,18 @@ func setupDockerVolumes(t *testing.T, cfg *config.Config, hostpath string) (*str

randfn := fmt.Sprintf("test-%d", rand.Int())
hostfile := filepath.Join(hostpath, randfn)
containerFile := filepath.Join("/mnt/vol", randfn)
containerPath := "/mnt/vol"
containerFile := filepath.Join(containerPath, randfn)

task := &structs.Task{
Name: "ls",
Env: map[string]string{"VOL_PATH": containerPath},
Config: map[string]interface{}{
"image": "busybox",
"load": []string{"busybox.tar"},
"command": "touch",
"args": []string{containerFile},
"volumes": []string{fmt.Sprintf("%s:/mnt/vol", hostpath)},
"volumes": []string{fmt.Sprintf("%s:${VOL_PATH}", hostpath)},
},
LogConfig: &structs.LogConfig{
MaxFiles: 10,
Expand Down

0 comments on commit 01d47a8

Please sign in to comment.