2018-04-13 21:13:48 +00:00
|
|
|
package worker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/moby/buildkit/cache"
|
2020-11-13 11:09:10 +00:00
|
|
|
"github.com/moby/buildkit/session"
|
2018-05-11 05:58:41 +00:00
|
|
|
"github.com/moby/buildkit/solver"
|
2018-04-13 21:13:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
2018-05-22 21:49:21 +00:00
|
|
|
refID := ""
|
|
|
|
if wr.ImmutableRef != nil {
|
|
|
|
refID = wr.ImmutableRef.ID()
|
|
|
|
}
|
|
|
|
return wr.Worker.ID() + "::" + refID
|
2018-04-13 21:13:48 +00:00
|
|
|
}
|
|
|
|
|
2021-10-05 06:43:22 +00:00
|
|
|
// GetRemotes method abstracts ImmutableRef's GetRemotes to allow a Worker to override.
|
2020-11-13 11:09:10 +00:00
|
|
|
// This is needed for moby integration.
|
2021-10-05 06:43:22 +00:00
|
|
|
// Use this method instead of calling ImmutableRef.GetRemotes() directly.
|
|
|
|
func (wr *WorkerRef) GetRemotes(ctx context.Context, createIfNeeded bool, compressionopt solver.CompressionOpt, all bool, g session.Group) ([]*solver.Remote, error) {
|
2020-11-13 11:09:10 +00:00
|
|
|
if w, ok := wr.Worker.(interface {
|
2021-10-05 06:43:22 +00:00
|
|
|
GetRemotes(context.Context, cache.ImmutableRef, bool, solver.CompressionOpt, bool, session.Group) ([]*solver.Remote, error)
|
2020-11-13 11:09:10 +00:00
|
|
|
}); ok {
|
2021-10-05 06:43:22 +00:00
|
|
|
return w.GetRemotes(ctx, wr.ImmutableRef, createIfNeeded, compressionopt, all, g)
|
2020-11-13 11:09:10 +00:00
|
|
|
}
|
2021-10-05 06:43:22 +00:00
|
|
|
return wr.ImmutableRef.GetRemotes(ctx, createIfNeeded, compressionopt, all, g)
|
2020-11-13 11:09:10 +00:00
|
|
|
}
|
|
|
|
|
2018-04-13 21:13:48 +00:00
|
|
|
type workerRefResult struct {
|
|
|
|
*WorkerRef
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *workerRefResult) Release(ctx context.Context) error {
|
2018-05-22 21:49:21 +00:00
|
|
|
if r.ImmutableRef == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-04-13 21:13:48 +00:00
|
|
|
return r.ImmutableRef.Release(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *workerRefResult) Sys() interface{} {
|
|
|
|
return r.WorkerRef
|
|
|
|
}
|
2021-02-03 07:59:02 +00:00
|
|
|
|
|
|
|
func (r *workerRefResult) Clone() solver.Result {
|
|
|
|
r2 := *r
|
|
|
|
if r.ImmutableRef != nil {
|
|
|
|
r.ImmutableRef = r.ImmutableRef.Clone()
|
|
|
|
}
|
|
|
|
return &r2
|
|
|
|
}
|