mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #15039 from jlhawn/fix_build_context_is_symlink
[api/client] Fix build when context dir is symlink
This commit is contained in:
commit
bdc55be9b4
2 changed files with 54 additions and 0 deletions
|
@ -302,6 +302,22 @@ func getDockerfileRelPath(givenContextDir, givenDockerfile string) (absContextDi
|
||||||
return "", "", fmt.Errorf("unable to get absolute context directory: %v", err)
|
return "", "", fmt.Errorf("unable to get absolute context directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The context dir might be a symbolic link, so follow it to the actual
|
||||||
|
// target directory.
|
||||||
|
absContextDir, err = filepath.EvalSymlinks(absContextDir)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", fmt.Errorf("unable to evaluate symlinks in context path: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
stat, err := os.Lstat(absContextDir)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", fmt.Errorf("unable to stat context directory %q: %v", absContextDir, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !stat.IsDir() {
|
||||||
|
return "", "", fmt.Errorf("context must be a directory: %s", absContextDir)
|
||||||
|
}
|
||||||
|
|
||||||
absDockerfile := givenDockerfile
|
absDockerfile := givenDockerfile
|
||||||
if absDockerfile == "" {
|
if absDockerfile == "" {
|
||||||
// No -f/--file was specified so use the default relative to the
|
// No -f/--file was specified so use the default relative to the
|
||||||
|
|
|
@ -5394,3 +5394,41 @@ func (s *DockerTrustSuite) TestTrustedBuildUntrustedTag(c *check.C) {
|
||||||
c.Fatalf("Unexpected output on trusted build with untrusted tag:\n%s", out)
|
c.Fatalf("Unexpected output on trusted build with untrusted tag:\n%s", out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerTrustSuite) TestBuildContextDirIsSymlink(c *check.C) {
|
||||||
|
tempDir, err := ioutil.TempDir("", "test-build-dir-is-symlink-")
|
||||||
|
if err != nil {
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
|
||||||
|
// Make a real context directory in this temp directory with a simple
|
||||||
|
// Dockerfile.
|
||||||
|
realContextDirname := filepath.Join(tempDir, "context")
|
||||||
|
if err := os.Mkdir(realContextDirname, os.FileMode(0755)); err != nil {
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = ioutil.WriteFile(
|
||||||
|
filepath.Join(realContextDirname, "Dockerfile"),
|
||||||
|
[]byte(`
|
||||||
|
FROM busybox
|
||||||
|
RUN echo hello world
|
||||||
|
`),
|
||||||
|
os.FileMode(0644),
|
||||||
|
); err != nil {
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make a symlink to the real context directory.
|
||||||
|
contextSymlinkName := filepath.Join(tempDir, "context_link")
|
||||||
|
if err := os.Symlink(realContextDirname, contextSymlinkName); err != nil {
|
||||||
|
c.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Executing the build with the symlink as the specified context should
|
||||||
|
// *not* fail.
|
||||||
|
if out, exitStatus := dockerCmd(c, "build", contextSymlinkName); exitStatus != 0 {
|
||||||
|
c.Fatalf("build failed with exit status %d: %s", exitStatus, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue