diff --git a/solver/llbsolver/ops/exec.go b/solver/llbsolver/ops/exec.go index 73666c5a9961..37d64ed0ef93 100644 --- a/solver/llbsolver/ops/exec.go +++ b/solver/llbsolver/ops/exec.go @@ -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