Add Solve API for performing a build on a build definition
This commit adds Solve API to the controller. This receives a build definition, performs that build using ResultHandler held by that session. After Solve completes, the client can debug the result using other APIs including Invoke. Note that the ResultHandle provided by Solve overwrites the ResultHandle previously stored in that session (possibly generated by the past Build or Solve API call). Using this API, user can perform build-and-debugging loop on the same session. Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/docker/buildx/util/progress"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/moby/buildkit/client"
|
||||
solverpb "github.com/moby/buildkit/solver/pb"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -40,6 +41,8 @@ type localController struct {
|
||||
processes *processes.Manager
|
||||
|
||||
buildOnGoing atomic.Bool
|
||||
|
||||
originalResult *build.ResultHandle
|
||||
}
|
||||
|
||||
func (b *localController) Build(ctx context.Context, options controllerapi.BuildOptions, in io.ReadCloser, progress progress.Writer) (string, *client.SolveResponse, error) {
|
||||
@@ -55,6 +58,7 @@ func (b *localController) Build(ctx context.Context, options controllerapi.Build
|
||||
resultCtx: res,
|
||||
buildOptions: &options,
|
||||
}
|
||||
b.originalResult = res
|
||||
if buildErr != nil {
|
||||
buildErr = controllererrors.WrapBuild(buildErr, b.ref)
|
||||
}
|
||||
@@ -144,3 +148,20 @@ func (b *localController) Inspect(ctx context.Context, ref string) (*controllera
|
||||
}
|
||||
return &controllerapi.InspectResponse{Options: b.buildConfig.buildOptions}, nil
|
||||
}
|
||||
|
||||
func (b *localController) Solve(ctx context.Context, ref string, target *solverpb.Definition, progress progress.Writer) error {
|
||||
if ref != b.ref {
|
||||
return errors.Errorf("unknown ref %q", ref)
|
||||
}
|
||||
if b.originalResult == nil {
|
||||
return errors.Errorf("no build has been called")
|
||||
}
|
||||
res, err := build.SolveWithResultHandler(ctx, "buildx", b.originalResult, target, progress)
|
||||
if err == nil {
|
||||
b.buildConfig.resultCtx = res
|
||||
if se := res.SolveError(); se != nil {
|
||||
err = errors.Errorf("failed solve: %v", se)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user