dockerfile: fix copy symlinks on copied dir
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>v0.7
parent
4f4e030675
commit
9654e5eeda
|
@ -1214,31 +1214,13 @@ func normalizeContextPaths(paths map[string]struct{}) []string {
|
||||||
if p == "/" {
|
if p == "/" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
pathSlice = append(pathSlice, p)
|
pathSlice = append(pathSlice, path.Join(".", p))
|
||||||
}
|
}
|
||||||
|
|
||||||
toDelete := map[string]struct{}{}
|
sort.Slice(pathSlice, func(i, j int) bool {
|
||||||
for i := range pathSlice {
|
return pathSlice[i] < pathSlice[j]
|
||||||
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]
|
|
||||||
})
|
})
|
||||||
return toSort
|
return pathSlice
|
||||||
}
|
}
|
||||||
|
|
||||||
func proxyEnvFromBuildArgs(args map[string]string) *llb.ProxyEnv {
|
func proxyEnvFromBuildArgs(args map[string]string) *llb.ProxyEnv {
|
||||||
|
|
|
@ -113,6 +113,7 @@ var fileOpTests = []integration.Test{
|
||||||
testWorkdirUser,
|
testWorkdirUser,
|
||||||
testWorkdirExists,
|
testWorkdirExists,
|
||||||
testWorkdirCopyIgnoreRelative,
|
testWorkdirCopyIgnoreRelative,
|
||||||
|
testCopyFollowAllSymlinks,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that depend on the `security.*` entitlements
|
// Tests that depend on the `security.*` entitlements
|
||||||
|
@ -1401,6 +1402,46 @@ COPY foo /
|
||||||
require.Equal(t, len(du), len(du2))
|
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) {
|
func testCopySymlinks(t *testing.T, sb integration.Sandbox) {
|
||||||
f := getFrontend(t, sb)
|
f := getFrontend(t, sb)
|
||||||
isFileOp := getFileOp(t, sb)
|
isFileOp := getFileOp(t, sb)
|
||||||
|
|
Loading…
Reference in New Issue