Skip to content

Commit

Permalink
cache: add fallback for snapshotID
Browse files Browse the repository at this point in the history
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 <tonistiigi@gmail.com>
(cherry picked from commit 2c0c429)
  • Loading branch information
tonistiigi committed Feb 13, 2023
1 parent 95aaabd commit b924f0b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cache/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,13 @@ func (md *cacheMetadata) queueMediaType(str string) error {
}

func (md *cacheMetadata) getSnapshotID() string {
return md.GetString(keySnapshot)
sid := md.GetString(keySnapshot)
// Note that historic buildkit releases did not always set the snapshot ID.
// Fallback to record ID is needed for old build cache compatibility.
if sid == "" {
return md.ID()
}
return sid
}

func (md *cacheMetadata) queueSnapshotID(str string) error {
Expand Down

0 comments on commit b924f0b

Please sign in to comment.