dockerfile: fix default cache IDs
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>docker-19.03
parent
9336f89e1f
commit
6371e4a31f
|
@ -124,6 +124,9 @@ func dispatchRunMounts(d *dispatchState, c *instructions.RunCommand, sources []*
|
|||
if mount.CacheSharing == instructions.MountSharingLocked {
|
||||
sharing = llb.CacheMountLocked
|
||||
}
|
||||
if mount.CacheID == "" {
|
||||
mount.CacheID = path.Clean(mount.Target)
|
||||
}
|
||||
mountOpts = append(mountOpts, llb.AsPersistentCacheDir(opt.cacheIDNamespace+"/"+mount.CacheID, sharing))
|
||||
}
|
||||
target := mount.Target
|
||||
|
|
|
@ -21,6 +21,7 @@ var mountTests = []integration.Test{
|
|||
testMountContext,
|
||||
testMountTmpfs,
|
||||
testMountRWCache,
|
||||
testCacheMountDefaultID,
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -193,3 +194,32 @@ RUN --mount=type=cache,target=/mycache,uid=1001,gid=1002,mode=0751 [ "$(stat -c
|
|||
}, nil)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func testCacheMountDefaultID(t *testing.T, sb integration.Sandbox) {
|
||||
f := getFrontend(t, sb)
|
||||
|
||||
dockerfile := []byte(`
|
||||
FROM busybox
|
||||
RUN --mount=type=cache,target=/mycache touch /mycache/foo
|
||||
RUN --mount=type=cache,target=/mycache2 [ ! -f /mycache2/foo ]
|
||||
RUN --mount=type=cache,target=/mycache [ -f /mycache/foo ]
|
||||
`)
|
||||
|
||||
dir, err := tmpdir(
|
||||
fstest.CreateFile("Dockerfile", dockerfile, 0600),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
c, err := client.New(context.TODO(), sb.Address())
|
||||
require.NoError(t, err)
|
||||
defer c.Close()
|
||||
|
||||
_, err = f.Solve(context.TODO(), c, client.SolveOpt{
|
||||
LocalDirs: map[string]string{
|
||||
builder.DefaultLocalNameDockerfile: dir,
|
||||
builder.DefaultLocalNameContext: dir,
|
||||
},
|
||||
}, nil)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue