Skip to content

Commit

Permalink
Don't run cache exporter for all
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejholly committed May 14, 2024
1 parent a520cca commit 79f9270
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cache/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ func (sr *immutableRef) ociDesc(ctx context.Context, dhs DescHandlers, preferNon
desc.Annotations["buildkit/createdat"] = string(createdAt)
}

desc.Annotations["earthly/ref"] = sr.ID()

return desc, nil
}

Expand Down
20 changes: 20 additions & 0 deletions solver/llbsolver/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ func earthlyInlineCacheDigests(ctx context.Context, job *solver.Job, exp exporte

cacheItems := []earthlyInlineCacheItem{}

// fmt.Println("inline cache pairs")
// spew.Dump(res.CacheKeys())
// for _, desc := range remote.Descriptors {
// fmt.Println(desc.Digest)
// fmt.Println(desc.Annotations)
// }

// if len(remote.Descriptors) != len(res.CacheKeys()) {
// return nil, errors.New("cache key & descriptor length mismatch")
// }

for i, desc := range remote.Descriptors {
cacheItems = append(cacheItems, earthlyInlineCacheItem{Key: res.CacheKeys()[i].Digest(), Descriptor: desc.Digest})
}
Expand All @@ -82,3 +93,12 @@ func earthlyInlineCacheDigests(ctx context.Context, job *solver.Job, exp exporte

return val, nil
}

func hasInlineCacheExporter(exporters []RemoteCacheExporter) bool {
for _, exp := range exporters {
if _, ok := asInlineCache(exp); ok {
return true
}
}
return false
}
14 changes: 8 additions & 6 deletions solver/llbsolver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,12 +595,14 @@ func (s *Solver) Solve(ctx context.Context, id string, sessionID string, req fro
// inp.AddMeta(k, v)
// }

meta, err := earthlyInlineCache(ctx, j, e, cached)
if err != nil {
return nil, errors.Wrap(err, "failed prepare inline cache")
}
for k, v := range meta {
inp.AddMeta(k, v)
if hasInlineCacheExporter(exp.CacheExporters) {
meta, err := earthlyInlineCache(ctx, j, e, cached)
if err != nil {
return nil, errors.Wrap(err, "failed prepare inline cache")
}
for k, v := range meta {
inp.AddMeta(k, v)
}
}

if err := inBuilderContext(ctx, j, e.Name(), j.SessionID+"-export", func(ctx context.Context, _ session.Group) error {
Expand Down

0 comments on commit 79f9270

Please sign in to comment.