Merge pull request #15356 from Microsoft/10662-uncpathonbuild
Windows: Allow UNC paths on build
This commit is contained in:
commit
436fca704f
|
@ -307,6 +307,12 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isUNC returns true if the path is UNC (one starting \\). It always returns
|
||||||
|
// false on Linux.
|
||||||
|
func isUNC(path string) bool {
|
||||||
|
return runtime.GOOS == "windows" && strings.HasPrefix(path, `\\`)
|
||||||
|
}
|
||||||
|
|
||||||
// getDockerfileRelPath uses the given context directory for a `docker build`
|
// getDockerfileRelPath uses the given context directory for a `docker build`
|
||||||
// and returns the absolute path to the context directory, the relative path of
|
// and returns the absolute path to the context directory, the relative path of
|
||||||
// the dockerfile in that context directory, and a non-nil error on success.
|
// the dockerfile in that context directory, and a non-nil error on success.
|
||||||
|
@ -317,10 +323,17 @@ func getDockerfileRelPath(givenContextDir, givenDockerfile string) (absContextDi
|
||||||
|
|
||||||
// The context dir might be a symbolic link, so follow it to the actual
|
// The context dir might be a symbolic link, so follow it to the actual
|
||||||
// target directory.
|
// target directory.
|
||||||
|
//
|
||||||
|
// FIXME. We use isUNC (always false on non-Windows platforms) to workaround
|
||||||
|
// an issue in golang. On Windows, EvalSymLinks does not work on UNC file
|
||||||
|
// paths (those starting with \\). This hack means that when using links
|
||||||
|
// on UNC paths, they will not be followed.
|
||||||
|
if !isUNC(absContextDir) {
|
||||||
absContextDir, err = filepath.EvalSymlinks(absContextDir)
|
absContextDir, err = filepath.EvalSymlinks(absContextDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", fmt.Errorf("unable to evaluate symlinks in context path: %v", err)
|
return "", "", fmt.Errorf("unable to evaluate symlinks in context path: %v", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stat, err := os.Lstat(absContextDir)
|
stat, err := os.Lstat(absContextDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -354,10 +367,17 @@ func getDockerfileRelPath(givenContextDir, givenDockerfile string) (absContextDi
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate symlinks in the path to the Dockerfile too.
|
// Evaluate symlinks in the path to the Dockerfile too.
|
||||||
|
//
|
||||||
|
// FIXME. We use isUNC (always false on non-Windows platforms) to workaround
|
||||||
|
// an issue in golang. On Windows, EvalSymLinks does not work on UNC file
|
||||||
|
// paths (those starting with \\). This hack means that when using links
|
||||||
|
// on UNC paths, they will not be followed.
|
||||||
|
if !isUNC(absDockerfile) {
|
||||||
absDockerfile, err = filepath.EvalSymlinks(absDockerfile)
|
absDockerfile, err = filepath.EvalSymlinks(absDockerfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", fmt.Errorf("unable to evaluate symlinks in Dockerfile path: %v", err)
|
return "", "", fmt.Errorf("unable to evaluate symlinks in Dockerfile path: %v", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := os.Lstat(absDockerfile); err != nil {
|
if _, err := os.Lstat(absDockerfile); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
|
Loading…
Reference in New Issue