solver: split llbbridge to a separate file (TODO: separate pkg)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>docker-18.09
parent
571e14e003
commit
29e5bef684
|
@ -0,0 +1,71 @@
|
|||
package solver
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/moby/buildkit/cache"
|
||||
"github.com/moby/buildkit/executor"
|
||||
"github.com/moby/buildkit/frontend"
|
||||
"github.com/moby/buildkit/worker"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// llbBridge is an helper used by frontends
|
||||
type llbBridge struct {
|
||||
*Solver
|
||||
job *job
|
||||
// this worker is used for running containerized frontend, not vertices
|
||||
worker *worker.Worker
|
||||
}
|
||||
|
||||
type resolveImageConfig interface {
|
||||
ResolveImageConfig(ctx context.Context, ref string) (digest.Digest, []byte, error)
|
||||
}
|
||||
|
||||
func (s *llbBridge) Solve(ctx context.Context, req frontend.SolveRequest) (cache.ImmutableRef, map[string][]byte, error) {
|
||||
var f frontend.Frontend
|
||||
if req.Frontend != "" {
|
||||
var ok bool
|
||||
f, ok = s.frontends[req.Frontend]
|
||||
if !ok {
|
||||
return nil, nil, errors.Errorf("invalid frontend: %s", req.Frontend)
|
||||
}
|
||||
} else {
|
||||
if req.Definition == nil || req.Definition.Def == nil {
|
||||
return nil, nil, nil
|
||||
}
|
||||
}
|
||||
ref, exp, err := s.solve(ctx, s.job, SolveRequest{
|
||||
Definition: req.Definition,
|
||||
Frontend: f,
|
||||
FrontendOpt: req.FrontendOpt,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
immutable, ok := toImmutableRef(ref)
|
||||
if !ok {
|
||||
return nil, nil, errors.Errorf("invalid reference for exporting: %T", ref)
|
||||
}
|
||||
return immutable, exp, nil
|
||||
}
|
||||
|
||||
func (s *llbBridge) ResolveImageConfig(ctx context.Context, ref string) (digest.Digest, []byte, error) {
|
||||
// ImageSource is typically source/containerimage
|
||||
resolveImageConfig, ok := s.worker.ImageSource.(resolveImageConfig)
|
||||
if !ok {
|
||||
return "", nil, errors.Errorf("worker %q does not implement ResolveImageConfig", s.worker.Name)
|
||||
}
|
||||
return resolveImageConfig.ResolveImageConfig(ctx, ref)
|
||||
}
|
||||
|
||||
func (s *llbBridge) Exec(ctx context.Context, meta executor.Meta, rootFS cache.ImmutableRef, stdin io.ReadCloser, stdout, stderr io.WriteCloser) error {
|
||||
active, err := s.worker.CacheManager.New(ctx, rootFS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer active.Release(context.TODO())
|
||||
return s.worker.Executor.Exec(ctx, meta, active, nil, stdin, stdout, stderr)
|
||||
}
|
|
@ -3,7 +3,6 @@ package solver
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -11,7 +10,6 @@ import (
|
|||
"github.com/moby/buildkit/cache/cacheimport"
|
||||
"github.com/moby/buildkit/cache/contenthash"
|
||||
"github.com/moby/buildkit/client"
|
||||
"github.com/moby/buildkit/executor"
|
||||
"github.com/moby/buildkit/exporter"
|
||||
"github.com/moby/buildkit/frontend"
|
||||
"github.com/moby/buildkit/solver/pb"
|
||||
|
@ -786,64 +784,6 @@ type VertexResult struct {
|
|||
Reference Reference
|
||||
}
|
||||
|
||||
// llbBridge is an helper used by frontends
|
||||
type llbBridge struct {
|
||||
*Solver
|
||||
job *job
|
||||
// this worker is used for running containerized frontend, not vertices
|
||||
worker *worker.Worker
|
||||
}
|
||||
|
||||
type resolveImageConfig interface {
|
||||
ResolveImageConfig(ctx context.Context, ref string) (digest.Digest, []byte, error)
|
||||
}
|
||||
|
||||
func (s *llbBridge) Solve(ctx context.Context, req frontend.SolveRequest) (cache.ImmutableRef, map[string][]byte, error) {
|
||||
var f frontend.Frontend
|
||||
if req.Frontend != "" {
|
||||
var ok bool
|
||||
f, ok = s.frontends[req.Frontend]
|
||||
if !ok {
|
||||
return nil, nil, errors.Errorf("invalid frontend: %s", req.Frontend)
|
||||
}
|
||||
} else {
|
||||
if req.Definition == nil || req.Definition.Def == nil {
|
||||
return nil, nil, nil
|
||||
}
|
||||
}
|
||||
ref, exp, err := s.solve(ctx, s.job, SolveRequest{
|
||||
Definition: req.Definition,
|
||||
Frontend: f,
|
||||
FrontendOpt: req.FrontendOpt,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
immutable, ok := toImmutableRef(ref)
|
||||
if !ok {
|
||||
return nil, nil, errors.Errorf("invalid reference for exporting: %T", ref)
|
||||
}
|
||||
return immutable, exp, nil
|
||||
}
|
||||
|
||||
func (s *llbBridge) ResolveImageConfig(ctx context.Context, ref string) (digest.Digest, []byte, error) {
|
||||
// ImageSource is typically source/containerimage
|
||||
resolveImageConfig, ok := s.worker.ImageSource.(resolveImageConfig)
|
||||
if !ok {
|
||||
return "", nil, errors.Errorf("worker %q does not implement ResolveImageConfig", s.worker.Name)
|
||||
}
|
||||
return resolveImageConfig.ResolveImageConfig(ctx, ref)
|
||||
}
|
||||
|
||||
func (s *llbBridge) Exec(ctx context.Context, meta executor.Meta, rootFS cache.ImmutableRef, stdin io.ReadCloser, stdout, stderr io.WriteCloser) error {
|
||||
active, err := s.worker.CacheManager.New(ctx, rootFS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer active.Release(context.TODO())
|
||||
return s.worker.Executor.Exec(ctx, meta, active, nil, stdin, stdout, stderr)
|
||||
}
|
||||
|
||||
func cacheKeyForIndex(dgst digest.Digest, index Index) digest.Digest {
|
||||
return digest.FromBytes([]byte(fmt.Sprintf("%s.%d", dgst, index)))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue