Skip to content

Request the whole context when BuildKit sends no followpaths - #105

Merged
jglogan merged 1 commit into
apple:mainfrom
jglogan:fix-empty-followpaths
Oct 22, 2026
Merged

jglogan merged 1 commit into
apple:mainfrom
jglogan:fix-empty-followpaths

Conversation

@jglogan

@jglogan jglogan commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
  • Fixes [Bug]: follow-paths set to "" for RUN --mount=type=tmpfs #104
  • BuildKit doesn't apply a followpaths restriction for RUN --mount=type=tmpfs. The shim treated that as "not supplied" and substituted a list built from the Dockerfile, which held only the first source of each COPY. The host then packed too few files and the build failed with a misleading "not found" error.
  • The host reads an empty list as nothing, so send "." for an empty followpaths and remove the Dockerfile-derived fallback.

Important

Currently, tmpfs mounts are broken, and this change fixes that problem. However, it means that if a tmpfs mount appears in the Dockerfile, the entire build context will be sent and not just what would normally result from BuildKit's FollowPaths analysis.

Analysis

  1. When BuildKit creates the LLB from the Dockerfile, it creates the list of context paths to request from the client so that the entire context doesn't need to be dragged across.
  2. When the RUN mounts get analyzed, BuildKit sees a mount source of "" for the tmpfs mount and this gets translated into a "/" that gets added to the context paths, which overrides the fine grained context information.
  3. When BuildKit sees "/" as the context path, no followPaths restriction gets applied.
  4. The shim processes the lack of a restriction as a followPaths value of ""

The challenge here is that the shim cannot distinguish the following cases where followPaths is "":

  • a tmpfs mount, where "/" for context path is overkill
  • COPY . . where "/" is exactly what's needed
  • anything else that adds "/" to the context paths

Because the shim can't distinguish these cases, requesting the whole context is the only always-correct response; narrowing the tmpfs case would have to happen in BuildKit.

Relevant call sites

  1. LLB creation builds the context path list
  1. A tmpfs mount's empty source becomes /
  1. / means no followpaths restriction
  1. The shim sees ""
    These are at the shim's main commit c328f21, before your fix.
  • A missing key joins to "":
    func metadataValue(m metadata.MD, key string) (string, error) {
    values := m[key]
    encoded := false
    if flag := m[key+"-encoded"]; len(flag) > 0 {
    var err error
    if encoded, err = strconv.ParseBool(flag[0]); err != nil {
    return "", fmt.Errorf("invalid %s-encoded metadata: %w", key, err)
    }
    }
    if !encoded {
    return strings.Join(values, ","), nil
    }
  • The old fallback that treated "" as "not supplied":
    followPaths := walkMeta.FollowPaths
    if followPaths == "" {
    followPaths = strings.Join(f.proxy.addedGlobs, ",")
    }

BuildKit omits followpaths when a build step needs the whole context,
for example RUN --mount=type=tmpfs. The shim treated that as "not
supplied" and substituted a list built from the Dockerfile, which held
only the first source of each COPY. The host then packed too few files
and the build failed with a misleading "not found" error.

Send "." for an empty followpaths and remove the Dockerfile-derived
fallback.

Fixes apple#104
@jglogan
jglogan merged commit 13f7add into apple:main Oct 22, 2026
2 checks passed
@jglogan
jglogan deleted the fix-empty-followpaths branch October 22, 2026 20:42
jglogan pushed a commit to apple/container that referenced this pull request Oct 28, 2026
- Resolves #2405 in conjunction with
  apple/container-builder-shim#105 which
  resolves the root cause in the builder shim
  and #2434 which brings in the new shim.
- When BuildKit evaluates instructions requiring
  the full build context (such as steps with tmpfs
  mounts), it emits a Walk request with empty
  or omitted followpaths metadata. BuildFSSync
  previously defaulted missing followpaths to [],
  resulting in no context files being packed into
  the archive.
- This change defaults omitted or empty
  followpaths to ["."], ensuring the entire
  context is served as expected by BuildKit's
  filesync protocol.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: follow-paths set to "" for RUN --mount=type=tmpfs

2 participants