2017-12-13 05:16:13 +00:00
|
|
|
package solver
|
|
|
|
|
|
|
|
import (
|
2018-01-16 22:30:10 +00:00
|
|
|
"context"
|
2018-01-07 01:17:45 +00:00
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
|
2017-12-13 05:16:13 +00:00
|
|
|
"github.com/moby/buildkit/cache"
|
2018-01-07 01:17:45 +00:00
|
|
|
"github.com/moby/buildkit/executor"
|
2017-12-13 05:16:13 +00:00
|
|
|
"github.com/moby/buildkit/frontend"
|
2018-01-07 01:17:45 +00:00
|
|
|
"github.com/moby/buildkit/util/tracing"
|
2017-12-13 05:16:13 +00:00
|
|
|
"github.com/moby/buildkit/worker"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// llbBridge is an helper used by frontends
|
|
|
|
type llbBridge struct {
|
|
|
|
*Solver
|
|
|
|
job *job
|
|
|
|
// this worker is used for running containerized frontend, not vertices
|
2017-12-15 08:06:54 +00:00
|
|
|
worker.Worker
|
2017-12-13 05:16:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2017-12-15 08:06:54 +00:00
|
|
|
ref, exp, err := s.solve(ctx, s.job, SolveRequest{
|
2017-12-13 05:16:13 +00:00
|
|
|
Definition: req.Definition,
|
|
|
|
Frontend: f,
|
|
|
|
FrontendOpt: req.FrontendOpt,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2017-12-15 08:06:54 +00:00
|
|
|
immutable, ok := ToImmutableRef(ref)
|
2017-12-13 05:16:13 +00:00
|
|
|
if !ok {
|
|
|
|
return nil, nil, errors.Errorf("invalid reference for exporting: %T", ref)
|
|
|
|
}
|
|
|
|
return immutable, exp, nil
|
|
|
|
}
|
2018-01-07 01:17:45 +00:00
|
|
|
|
|
|
|
func (s *llbBridge) Exec(ctx context.Context, meta executor.Meta, root cache.ImmutableRef, stdin io.ReadCloser, stdout, stderr io.WriteCloser) (err error) {
|
|
|
|
span, ctx := tracing.StartSpan(ctx, strings.Join(meta.Args, " "))
|
|
|
|
err = s.Worker.Exec(ctx, meta, root, stdin, stdout, stderr)
|
|
|
|
tracing.FinishWithError(span, err)
|
|
|
|
return err
|
|
|
|
}
|