Skip to content

Commit 2c0c429

Browse files
committed
cache: add fallback for snapshotID
In older BuildKit versions snapshotID was not always set if record was not created with GetByBlob method. Old code defaulted to cache record ID in that case but that broke with the metadata interface refactor. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 9200883 commit 2c0c429

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cache/metadata.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,13 @@ func (md *cacheMetadata) queueMediaType(str string) error {
251251
}
252252

253253
func (md *cacheMetadata) getSnapshotID() string {
254-
return md.GetString(keySnapshot)
254+
sid := md.GetString(keySnapshot)
255+
// Note that historic buildkit releases did not always set the snapshot ID.
256+
// Fallback to record ID is needed for old build cache compatibility.
257+
if sid == "" {
258+
return md.ID()
259+
}
260+
return sid
255261
}
256262

257263
func (md *cacheMetadata) queueSnapshotID(str string) error {

0 commit comments

Comments
 (0)