From 361c2b6aa09888ce5f452b1ba738a87dc5c7c5df Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Wed, 14 Apr 2021 08:49:02 -0700 Subject: [PATCH] Add hack to preserve Dockerfile RUN cache compatibility after mount cache bugfix Signed-off-by: Aaron Lehmann (cherry picked from commit 61bb15a47f42eb1fa9e73dc4e592292db29f7287) --- solver/llbsolver/ops/exec.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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