dockerfile: fix copy symlinks on copied dir

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
v0.7
Tonis Tiigi 2019-10-28 22:03:58 -07:00
parent 4f4e030675
commit 9654e5eeda
2 changed files with 45 additions and 22 deletions

View File

@ -1214,31 +1214,13 @@ func normalizeContextPaths(paths map[string]struct{}) []string {
if p == "/" {
return nil
}
pathSlice = append(pathSlice, p)
pathSlice = append(pathSlice, path.Join(".", p))
}
toDelete := map[string]struct{}{}
for i := range pathSlice {
for j := range pathSlice {
if i == j {
continue
}
if strings.HasPrefix(pathSlice[j], pathSlice[i]+"/") {
delete(paths, pathSlice[j])
}
}
}
toSort := make([]string, 0, len(paths))
for p := range paths {
if _, ok := toDelete[p]; !ok {
toSort = append(toSort, path.Join(".", p))
}
}
sort.Slice(toSort, func(i, j int) bool {
return toSort[i] < toSort[j]
sort.Slice(pathSlice, func(i, j int) bool {
return pathSlice[i] < pathSlice[j]
})
return toSort
return pathSlice
}
func proxyEnvFromBuildArgs(args map[string]string) *llb.ProxyEnv {

View File

@ -113,6 +113,7 @@ var fileOpTests = []integration.Test{
testWorkdirUser,
testWorkdirExists,
testWorkdirCopyIgnoreRelative,
testCopyFollowAllSymlinks,
}
// Tests that depend on the `security.*` entitlements
@ -1401,6 +1402,46 @@ COPY foo /
require.Equal(t, len(du), len(du2))
}
// #1197
func testCopyFollowAllSymlinks(t *testing.T, sb integration.Sandbox) {
f := getFrontend(t, sb)
isFileOp := getFileOp(t, sb)
dockerfile := []byte(`
FROM scratch
COPY foo /
COPY foo/sub bar
`)
dir, err := tmpdir(
fstest.CreateFile("Dockerfile", dockerfile, 0600),
fstest.CreateFile("bar", []byte(`bar-contents`), 0600),
fstest.CreateDir("foo", 0700),
fstest.Symlink("../bar", "foo/sub"),
)
require.NoError(t, err)
defer os.RemoveAll(dir)
c, err := client.New(context.TODO(), sb.Address())
require.NoError(t, err)
defer c.Close()
destDir, err := ioutil.TempDir("", "buildkit")
require.NoError(t, err)
defer os.RemoveAll(destDir)
_, err = f.Solve(context.TODO(), c, client.SolveOpt{
FrontendAttrs: map[string]string{
"build-arg:BUILDKIT_DISABLE_FILEOP": strconv.FormatBool(!isFileOp),
},
LocalDirs: map[string]string{
builder.DefaultLocalNameDockerfile: dir,
builder.DefaultLocalNameContext: dir,
},
}, nil)
require.NoError(t, err)
}
func testCopySymlinks(t *testing.T, sb integration.Sandbox) {
f := getFrontend(t, sb)
isFileOp := getFileOp(t, sb)