Skip to content

Commit 6861f17

Browse files
authored
Merge pull request moby#1797 from tiborvass/fix-cache-moby-integration
Allow worker to override GetRemote(), needed in moby integration
2 parents ce283f3 + fad612e commit 6861f17

5 files changed

Lines changed: 20 additions & 3 deletions

File tree

cache/remote.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type Unlazier interface {
2424
Unlazy(ctx context.Context) error
2525
}
2626

27+
// GetRemote gets a *solver.Remote from content store for this ref (potentially pulling lazily).
28+
// Note: Use WorkerRef.GetRemote instead as moby integration requires custom GetRemote implementation.
2729
func (sr *immutableRef) GetRemote(ctx context.Context, createIfNeeded bool, compressionType compression.Type, s session.Group) (*solver.Remote, error) {
2830
ctx, done, err := leaseutil.WithLease(ctx, sr.cm.LeaseManager, leaseutil.MakeTemporary)
2931
if err != nil {

solver/llbsolver/result.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ func workerRefConverter(g session.Group) func(ctx context.Context, res solver.Re
8282
return nil, errors.Errorf("invalid result: %T", res.Sys())
8383
}
8484

85-
return ref.ImmutableRef.GetRemote(ctx, true, compression.Default, g)
85+
return ref.GetRemote(ctx, true, compression.Default, g)
8686
}
8787
}

solver/llbsolver/solver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func inlineCache(ctx context.Context, e remotecache.Exporter, res solver.CachedR
270270
return nil, errors.Errorf("invalid reference: %T", res.Sys())
271271
}
272272

273-
remote, err := workerRef.ImmutableRef.GetRemote(ctx, true, compression.Default, g)
273+
remote, err := workerRef.GetRemote(ctx, true, compression.Default, g)
274274
if err != nil || remote == nil {
275275
return nil, nil
276276
}

worker/cacheresult.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ func (s *cacheResultStorage) LoadRemote(ctx context.Context, res solver.CacheRes
7878
return nil, err
7979
}
8080
defer ref.Release(context.TODO())
81-
remote, err := ref.GetRemote(ctx, false, compression.Default, g)
81+
wref := WorkerRef{ref, w}
82+
remote, err := wref.GetRemote(ctx, false, compression.Default, g)
8283
if err != nil {
8384
return nil, nil // ignore error. loadRemote is best effort
8485
}

worker/result.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"context"
55

66
"github.com/moby/buildkit/cache"
7+
"github.com/moby/buildkit/session"
78
"github.com/moby/buildkit/solver"
9+
"github.com/moby/buildkit/util/compression"
810
)
911

1012
func NewWorkerRefResult(ref cache.ImmutableRef, worker Worker) solver.Result {
@@ -24,6 +26,18 @@ func (wr *WorkerRef) ID() string {
2426
return wr.Worker.ID() + "::" + refID
2527
}
2628

29+
// GetRemote method abstracts ImmutableRef's GetRemote to allow a Worker to override.
30+
// This is needed for moby integration.
31+
// Use this method instead of calling ImmutableRef.GetRemote() directly.
32+
func (wr *WorkerRef) GetRemote(ctx context.Context, createIfNeeded bool, compressionType compression.Type, g session.Group) (*solver.Remote, error) {
33+
if w, ok := wr.Worker.(interface {
34+
GetRemote(context.Context, cache.ImmutableRef, bool, compression.Type, session.Group) (*solver.Remote, error)
35+
}); ok {
36+
return w.GetRemote(ctx, wr.ImmutableRef, createIfNeeded, compressionType, g)
37+
}
38+
return wr.ImmutableRef.GetRemote(ctx, createIfNeeded, compressionType, g)
39+
}
40+
2741
type workerRefResult struct {
2842
*WorkerRef
2943
}

0 commit comments

Comments
 (0)