From 79f9270a0992407093869174517c1099e98c6742 Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 14 May 2024 14:47:41 -0700 Subject: [PATCH] Don't run cache exporter for all --- cache/refs.go | 2 ++ solver/llbsolver/inline.go | 20 ++++++++++++++++++++ solver/llbsolver/solver.go | 14 ++++++++------ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/cache/refs.go b/cache/refs.go index 0d1f089ce..49d46bf3f 100644 --- a/cache/refs.go +++ b/cache/refs.go @@ -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 } diff --git a/solver/llbsolver/inline.go b/solver/llbsolver/inline.go index ac2cbb4e0..8e75a1d68 100644 --- a/solver/llbsolver/inline.go +++ b/solver/llbsolver/inline.go @@ -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}) } @@ -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 +} diff --git a/solver/llbsolver/solver.go b/solver/llbsolver/solver.go index b92c851fb..70eecba80 100644 --- a/solver/llbsolver/solver.go +++ b/solver/llbsolver/solver.go @@ -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 {