Skip to content

Fix #1143: Add content hash to build context metadata to prevent BuildKit from caching stale files#1145

Closed
Ronitsabhaya75 wants to merge 1 commit intoapple:mainfrom
Ronitsabhaya75:buildkit-bug
Closed

Fix #1143: Add content hash to build context metadata to prevent BuildKit from caching stale files#1145
Ronitsabhaya75 wants to merge 1 commit intoapple:mainfrom
Ronitsabhaya75:buildkit-bug

Conversation

@Ronitsabhaya75
Copy link
Contributor

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

Fix #1143

BuildKit container caches build context after the first build and doesn't invalidate when files change, causing subsequent builds to use stale files.

Root Cause: BuildKit's cache key doesn't account for file content changes. BuildFSSync sends updated tar archives, but BuildKit reuses the cached context.

The fix: Add SHA256 hash of build context (file paths + sizes + modTimes) to tar metadata, forcing BuildKit cache invalidation when files change.

let contextHash = try computeContextHash(fileOrder: fileOrder, contextDir: contextDir)
metadata: [
    "os": "linux",
    "stage": "fssync",
    "mode": "tar",
    "context_hash": contextHash,
]

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

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]: buildkit container loose sync when tgz archive

1 participant

Comments