Skip to content

Commit 835e9fd

Browse files
authored
Merge pull request moby#5080 from profnandaa/fix-dot-path-5070
fix: dot and empty paths normalized correctly for COPY to WORKDIR
2 parents 546d95c + c605289 commit 835e9fd

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

frontend/dockerfile/dockerfile2llb/convert.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,9 +1755,6 @@ func pathRelativeToWorkingDir(s llb.State, p string, platform ocispecs.Platform)
17551755
return "", err
17561756
}
17571757

1758-
if len(p) == 0 {
1759-
return dir, nil
1760-
}
17611758
p, err = system.CheckSystemDriveAndRemoveDriveLetter(p, platform.OS)
17621759
if err != nil {
17631760
return "", errors.Wrap(err, "removing drive letter")
@@ -1766,6 +1763,12 @@ func pathRelativeToWorkingDir(s llb.State, p string, platform ocispecs.Platform)
17661763
if system.IsAbs(p, platform.OS) {
17671764
return system.NormalizePath("/", p, platform.OS, true)
17681765
}
1766+
1767+
// add slashes for "" and "." paths
1768+
// "" is treated as current directory and not necessariy root
1769+
if p == "." || p == "" {
1770+
p = "./"
1771+
}
17691772
return system.NormalizePath(dir, p, platform.OS, true)
17701773
}
17711774

frontend/dockerfile/dockerfile_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ var allTests = integration.TestFuncs(
142142
testNamedMultiplatformInputContext,
143143
testNamedFilteredContext,
144144
testEmptyDestDir,
145+
testCopyLinkDotDestDir,
146+
testCopyLinkEmptyDestDir,
145147
testCopyChownCreateDest,
146148
testCopyThroughSymlinkContext,
147149
testCopyThroughSymlinkMultiStage,
@@ -447,6 +449,67 @@ RUN [ "$(cat testfile)" == "contents0" ]
447449
require.NoError(t, err)
448450
}
449451

452+
func testCopyLinkDotDestDir(t *testing.T, sb integration.Sandbox) {
453+
integration.SkipOnPlatform(t, "windows")
454+
f := getFrontend(t, sb)
455+
456+
dockerfile := []byte(`
457+
FROM busybox
458+
WORKDIR /var/www
459+
COPY --link testfile .
460+
RUN [ "$(cat testfile)" == "contents0" ]
461+
`)
462+
463+
dir := integration.Tmpdir(
464+
t,
465+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
466+
fstest.CreateFile("testfile", []byte("contents0"), 0600),
467+
)
468+
469+
c, err := client.New(sb.Context(), sb.Address())
470+
require.NoError(t, err)
471+
defer c.Close()
472+
473+
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
474+
LocalMounts: map[string]fsutil.FS{
475+
dockerui.DefaultLocalNameDockerfile: dir,
476+
dockerui.DefaultLocalNameContext: dir,
477+
},
478+
}, nil)
479+
require.NoError(t, err)
480+
}
481+
482+
func testCopyLinkEmptyDestDir(t *testing.T, sb integration.Sandbox) {
483+
integration.SkipOnPlatform(t, "windows")
484+
f := getFrontend(t, sb)
485+
486+
dockerfile := []byte(`
487+
FROM busybox
488+
WORKDIR /var/www
489+
ENV empty=""
490+
COPY --link testfile $empty
491+
RUN [ "$(cat testfile)" == "contents0" ]
492+
`)
493+
494+
dir := integration.Tmpdir(
495+
t,
496+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
497+
fstest.CreateFile("testfile", []byte("contents0"), 0600),
498+
)
499+
500+
c, err := client.New(sb.Context(), sb.Address())
501+
require.NoError(t, err)
502+
defer c.Close()
503+
504+
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
505+
LocalMounts: map[string]fsutil.FS{
506+
dockerui.DefaultLocalNameDockerfile: dir,
507+
dockerui.DefaultLocalNameContext: dir,
508+
},
509+
}, nil)
510+
require.NoError(t, err)
511+
}
512+
450513
func testExportCacheLoop(t *testing.T, sb integration.Sandbox) {
451514
integration.SkipOnPlatform(t, "windows")
452515
workers.CheckFeatureCompat(t, sb, workers.FeatureCacheExport, workers.FeatureCacheImport, workers.FeatureCacheBackendLocal)

0 commit comments

Comments
 (0)