added check for bind on create to determine local volume driver
Signed-off-by: Clinton Kitson <clintonskitson@gmail.com> Upstream-commit: 6b8129d1fe9b1428833e1c38e463a5a4cc204390 Component: engine
This commit is contained in:
@ -244,3 +244,38 @@ func (s DockerExternalVolumeSuite) TestStartExternalVolumeDriverDeleteContainer(
|
||||
func hostVolumePath(name string) string {
|
||||
return fmt.Sprintf("/var/lib/docker/volumes/%s", name)
|
||||
}
|
||||
|
||||
func (s *DockerExternalVolumeSuite) TestStartExternalNamedVolumeDriverCheckBindLocalVolume(c *check.C) {
|
||||
if err := s.d.StartWithBusybox(); err != nil {
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
expected := s.server.URL
|
||||
|
||||
dockerfile := fmt.Sprintf(`FROM busybox:latest
|
||||
RUN mkdir /nobindthenlocalvol
|
||||
RUN echo %s > /nobindthenlocalvol/test
|
||||
VOLUME ["/nobindthenlocalvol"]`, expected)
|
||||
|
||||
img := "test-checkbindlocalvolume"
|
||||
|
||||
args := []string{"--host", s.d.sock()}
|
||||
buildOut, err := buildImageArgs(args, img, dockerfile, true)
|
||||
fmt.Println(buildOut)
|
||||
|
||||
out, err := s.d.Cmd("run", "--rm", "--name", "test-data-nobind", "-v", "external-volume-test:/tmp/external-volume-test", "--volume-driver", "test-external-volume-driver", img, "cat", "/nobindthenlocalvol/test")
|
||||
if err != nil {
|
||||
fmt.Println(out)
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
if !strings.Contains(out, expected) {
|
||||
c.Fatalf("External volume mount failed. Output: %s\n", out)
|
||||
}
|
||||
|
||||
c.Assert(s.ec.activations, check.Equals, 1)
|
||||
c.Assert(s.ec.creations, check.Equals, 1)
|
||||
c.Assert(s.ec.removals, check.Equals, 1)
|
||||
c.Assert(s.ec.mounts, check.Equals, 1)
|
||||
c.Assert(s.ec.unmounts, check.Equals, 1)
|
||||
}
|
||||
|
||||
@ -1353,3 +1353,33 @@ func createTmpFile(c *check.C, content string) string {
|
||||
|
||||
return filename
|
||||
}
|
||||
|
||||
func buildImageArgs(args []string, name, dockerfile string, useCache bool) (string, error) {
|
||||
id, _, err := buildImageWithOutArgs(args, name, dockerfile, useCache)
|
||||
return id, err
|
||||
}
|
||||
|
||||
func buildImageWithOutArgs(args []string, name, dockerfile string, useCache bool) (string, string, error) {
|
||||
buildCmd := buildImageCmdArgs(args, name, dockerfile, useCache)
|
||||
out, exitCode, err := runCommandWithOutput(buildCmd)
|
||||
if err != nil || exitCode != 0 {
|
||||
return "", out, fmt.Errorf("failed to build the image: %s", out)
|
||||
}
|
||||
id, err := getIDByName(name)
|
||||
if err != nil {
|
||||
return "", out, err
|
||||
}
|
||||
return id, out, nil
|
||||
}
|
||||
|
||||
func buildImageCmdArgs(args []string, name, dockerfile string, useCache bool) *exec.Cmd {
|
||||
args = append(args, []string{"-D", "build", "-t", name}...)
|
||||
if !useCache {
|
||||
args = append(args, "--no-cache")
|
||||
}
|
||||
args = append(args, "-")
|
||||
buildCmd := exec.Command(dockerBinary, args...)
|
||||
buildCmd.Stdin = strings.NewReader(dockerfile)
|
||||
return buildCmd
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user