Add hack to preserve Dockerfile RUN cache compatibility after mount cache bugfix

Signed-off-by: Aaron Lehmann <alehmann@netflix.com>
v0.9
Aaron Lehmann 2021-04-14 08:49:02 -07:00
parent 6ab9eeac79
commit 61bb15a47f
1 changed files with 16 additions and 0 deletions

View File

@ -97,6 +97,22 @@ func (e *execOp) CacheMap(ctx context.Context, g session.Group, index int) (*sol
}
}
// Special case for cache compatibility with buggy versions that wrongly
// excluded Exec.Mounts: for the default case of one root mount (i.e. RUN
// inside a Dockerfile), do not include the mount when generating the cache
// map.
if len(op.Mounts) == 1 &&
op.Mounts[0].Dest == "/" &&
op.Mounts[0].Selector == "" &&
!op.Mounts[0].Readonly &&
op.Mounts[0].MountType == pb.MountType_BIND &&
op.Mounts[0].CacheOpt == nil &&
op.Mounts[0].SSHOpt == nil &&
op.Mounts[0].SecretOpt == nil &&
op.Mounts[0].ResultID == "" {
op.Mounts = nil
}
dt, err := json.Marshal(struct {
Type string
Exec *pb.ExecOp