-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathresult.go
72 lines (61 loc) · 1.83 KB
/
result.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package worker
import (
"context"
"github.com/moby/buildkit/cache"
cacheconfig "github.com/moby/buildkit/cache/config"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/solver"
)
func NewWorkerRefResult(ref cache.ImmutableRef, worker Worker) solver.Result {
return &workerRefResult{&WorkerRef{ImmutableRef: ref, Worker: worker}}
}
type WorkerRef struct {
ImmutableRef cache.ImmutableRef
Worker Worker
}
func (wr *WorkerRef) ID() string {
refID := ""
if wr.ImmutableRef != nil {
refID = wr.ImmutableRef.ID()
}
return wr.Worker.ID() + "::" + refID
}
func (wr *WorkerRef) Release(ctx context.Context) error {
if wr.ImmutableRef == nil {
return nil
}
return wr.ImmutableRef.Release(ctx)
}
// GetRemotes method abstracts ImmutableRef's GetRemotes to allow a Worker to override.
// This is needed for moby integration.
// Use this method instead of calling ImmutableRef.GetRemotes() directly.
func (wr *WorkerRef) GetRemotes(ctx context.Context, createIfNeeded bool, refCfg cacheconfig.RefConfig, all bool, g session.Group) ([]*solver.Remote, error) {
if w, ok := wr.Worker.(interface {
GetRemotes(context.Context, cache.ImmutableRef, bool, cacheconfig.RefConfig, bool, session.Group) ([]*solver.Remote, error)
}); ok {
return w.GetRemotes(ctx, wr.ImmutableRef, createIfNeeded, refCfg, all, g)
}
if wr.ImmutableRef == nil {
return nil, nil
}
return wr.ImmutableRef.GetRemotes(ctx, createIfNeeded, refCfg, all, g)
}
type workerRefResult struct {
*WorkerRef
}
func (r *workerRefResult) Release(ctx context.Context) error {
if r.ImmutableRef == nil {
return nil
}
return r.ImmutableRef.Release(ctx)
}
func (r *workerRefResult) Sys() interface{} {
return r.WorkerRef
}
func (r *workerRefResult) Clone() solver.Result {
r2 := *r
if r.ImmutableRef != nil {
r.ImmutableRef = r.ImmutableRef.Clone()
}
return &r2
}