Skip to content

Commit

Permalink
solver: correctly set the content based selector with bind mounts
Browse files Browse the repository at this point in the history
Correctly set the content based selector when multiple bind mounts refer
to the same source. Previously, a selector that referred to the root
filesystem would be ignored. This is because a blank selector refers to
the root filesystem.

When two bind mounts referred to the same dependency, one mount would
add a selector while the other would be skipped. This caused the cache
key to be only computed based on the more narrow filesystem which caused
erroneous cache hits.

Now, the creation of the selector includes the root filesystem for
consideration. It fills in `/` as the selector and then removes it later
so that we don't narrow the selection in an invalid way.
  • Loading branch information
jsternberg committed Sep 22, 2023
1 parent bbe48e7 commit 3b7fc6c
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions solver/llbsolver/ops/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,28 @@ func (e *ExecOp) getMountDeps() ([]dep, error) {
return nil, errors.Errorf("invalid mountinput %v", m)
}

sel := m.Selector
if sel != "" {
sel = path.Join("/", sel)
deps[m.Input].Selectors = append(deps[m.Input].Selectors, sel)
}
// Mark the selector path as used. In this section, we need to
// record root selectors so the selection criteria isn't narrowed
// erroneously.
sel := path.Join("/", m.Selector)
deps[m.Input].Selectors = append(deps[m.Input].Selectors, sel)

if (!m.Readonly || m.Dest == pb.RootMount) && m.Output != -1 { // exclude read-only rootfs && read-write mounts
deps[m.Input].NoContentBasedHash = true
}
}

// Remove extraneous selectors that may have been generated from above.
for i, dep := range deps {
for _, sel := range dep.Selectors {
// If the root path is included in the list of selectors,
// this is the same as if no selector was used. Zero out this field.
if sel == "/" {
deps[i].Selectors = nil
break
}
}
}
return deps, nil
}

Expand Down

0 comments on commit 3b7fc6c

Please sign in to comment.