Skip to content

Commit

Permalink
Merge pull request docker#2722 from crazy-max/test-details-link-exp
Browse files Browse the repository at this point in the history
build: fix build details link in experimental mode
  • Loading branch information
tonistiigi authored Oct 28, 2024
2 parents 2bdf451 + eb15c66 commit 202c390
Show file tree
Hide file tree
Showing 14 changed files with 601 additions and 508 deletions.
11 changes: 10 additions & 1 deletion cmd/buildx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/docker/buildx/commands"
controllererrors "github.com/docker/buildx/controller/errdefs"
"github.com/docker/buildx/util/desktop"
"github.com/docker/buildx/version"
"github.com/docker/cli/cli"
Expand All @@ -16,6 +17,7 @@ import (
cliflags "github.com/docker/cli/cli/flags"
"github.com/moby/buildkit/solver/errdefs"
"github.com/moby/buildkit/util/stack"
"github.com/pkg/errors"
"go.opentelemetry.io/otel"

//nolint:staticcheck // vendored dependencies may still use this
Expand Down Expand Up @@ -115,8 +117,15 @@ func main() {
} else {
fmt.Fprintf(cmd.Err(), "ERROR: %v\n", err)
}
if ebr, ok := err.(*desktop.ErrorWithBuildRef); ok {

var ebr *desktop.ErrorWithBuildRef
if errors.As(err, &ebr) {
ebr.Print(cmd.Err())
} else {
var be *controllererrors.BuildError
if errors.As(err, &be) {
be.PrintBuildDetails(cmd.Err())
}
}

os.Exit(1)
Expand Down
18 changes: 16 additions & 2 deletions controller/errdefs/build.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package errdefs

import (
"io"

"github.com/containerd/typeurl/v2"
"github.com/docker/buildx/util/desktop"
"github.com/moby/buildkit/util/grpcerrors"
)

Expand All @@ -22,11 +25,22 @@ func (e *BuildError) ToProto() grpcerrors.TypedErrorProto {
return e.Build
}

func WrapBuild(err error, ref string) error {
func (e *BuildError) PrintBuildDetails(w io.Writer) error {
if e.Ref == "" {
return nil
}
ebr := &desktop.ErrorWithBuildRef{
Ref: e.Ref,
Err: e.error,
}
return ebr.Print(w)
}

func WrapBuild(err error, sessionID string, ref string) error {
if err == nil {
return nil
}
return &BuildError{Build: &Build{Ref: ref}, error: err}
return &BuildError{Build: &Build{SessionID: sessionID, Ref: ref}, error: err}
}

func (b *Build) WrapError(err error) error {
Expand Down
24 changes: 17 additions & 7 deletions controller/errdefs/errdefs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion controller/errdefs/errdefs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ package docker.buildx.errdefs;
option go_package = "github.com/docker/buildx/controller/errdefs";

message Build {
string Ref = 1;
string SessionID = 1;
string Ref = 2;
}
47 changes: 47 additions & 0 deletions controller/errdefs/errdefs_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 23 additions & 17 deletions controller/local/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
controllererrors "github.com/docker/buildx/controller/errdefs"
controllerapi "github.com/docker/buildx/controller/pb"
"github.com/docker/buildx/controller/processes"
"github.com/docker/buildx/util/desktop"
"github.com/docker/buildx/util/ioset"
"github.com/docker/buildx/util/progress"
"github.com/docker/cli/cli/command"
Expand All @@ -21,7 +22,7 @@ import (
func NewLocalBuildxController(ctx context.Context, dockerCli command.Cli, logger progress.SubLogger) control.BuildxController {
return &localController{
dockerCli: dockerCli,
ref: "local",
sessionID: "local",
processes: processes.NewManager(),
}
}
Expand All @@ -35,7 +36,7 @@ type buildConfig struct {

type localController struct {
dockerCli command.Cli
ref string
sessionID string
buildConfig buildConfig
processes *processes.Manager

Expand All @@ -56,25 +57,30 @@ func (b *localController) Build(ctx context.Context, options *controllerapi.Buil
buildOptions: options,
}
if buildErr != nil {
buildErr = controllererrors.WrapBuild(buildErr, b.ref)
var ref string
var ebr *desktop.ErrorWithBuildRef
if errors.As(buildErr, &ebr) {
ref = ebr.Ref
}
buildErr = controllererrors.WrapBuild(buildErr, b.sessionID, ref)
}
}
if buildErr != nil {
return "", nil, nil, buildErr
}
return b.ref, resp, dockerfileMappings, nil
return b.sessionID, resp, dockerfileMappings, nil
}

func (b *localController) ListProcesses(ctx context.Context, ref string) (infos []*controllerapi.ProcessInfo, retErr error) {
if ref != b.ref {
return nil, errors.Errorf("unknown ref %q", ref)
func (b *localController) ListProcesses(ctx context.Context, sessionID string) (infos []*controllerapi.ProcessInfo, retErr error) {
if sessionID != b.sessionID {
return nil, errors.Errorf("unknown session ID %q", sessionID)
}
return b.processes.ListProcesses(), nil
}

func (b *localController) DisconnectProcess(ctx context.Context, ref, pid string) error {
if ref != b.ref {
return errors.Errorf("unknown ref %q", ref)
func (b *localController) DisconnectProcess(ctx context.Context, sessionID, pid string) error {
if sessionID != b.sessionID {
return errors.Errorf("unknown session ID %q", sessionID)
}
return b.processes.DeleteProcess(pid)
}
Expand All @@ -83,9 +89,9 @@ func (b *localController) cancelRunningProcesses() {
b.processes.CancelRunningProcesses()
}

func (b *localController) Invoke(ctx context.Context, ref string, pid string, cfg *controllerapi.InvokeConfig, ioIn io.ReadCloser, ioOut io.WriteCloser, ioErr io.WriteCloser) error {
if ref != b.ref {
return errors.Errorf("unknown ref %q", ref)
func (b *localController) Invoke(ctx context.Context, sessionID string, pid string, cfg *controllerapi.InvokeConfig, ioIn io.ReadCloser, ioOut io.WriteCloser, ioErr io.WriteCloser) error {
if sessionID != b.sessionID {
return errors.Errorf("unknown session ID %q", sessionID)
}

proc, ok := b.processes.Get(pid)
Expand Down Expand Up @@ -130,17 +136,17 @@ func (b *localController) Close() error {
}

func (b *localController) List(ctx context.Context) (res []string, _ error) {
return []string{b.ref}, nil
return []string{b.sessionID}, nil
}

func (b *localController) Disconnect(ctx context.Context, key string) error {
b.Close()
return nil
}

func (b *localController) Inspect(ctx context.Context, ref string) (*controllerapi.InspectResponse, error) {
if ref != b.ref {
return nil, errors.Errorf("unknown ref %q", ref)
func (b *localController) Inspect(ctx context.Context, sessionID string) (*controllerapi.InspectResponse, error) {
if sessionID != b.sessionID {
return nil, errors.Errorf("unknown session ID %q", sessionID)
}
return &controllerapi.InspectResponse{Options: b.buildConfig.buildOptions}, nil
}
Loading

0 comments on commit 202c390

Please sign in to comment.