Skip to content

Commit

Permalink
controller: rename ref to sessionID and set buildRef back to ref
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Oct 24, 2024
1 parent 1060328 commit eb15c66
Show file tree
Hide file tree
Showing 11 changed files with 537 additions and 530 deletions.
8 changes: 4 additions & 4 deletions controller/errdefs/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ func (e *BuildError) ToProto() grpcerrors.TypedErrorProto {
}

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

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

func (b *Build) WrapError(err error) error {
Expand Down
27 changes: 14 additions & 13 deletions controller/errdefs/errdefs.pb.go

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

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

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

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

38 changes: 19 additions & 19 deletions controller/local/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,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 @@ -36,7 +36,7 @@ type buildConfig struct {

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

Expand All @@ -57,30 +57,30 @@ func (b *localController) Build(ctx context.Context, options *controllerapi.Buil
buildOptions: options,
}
if buildErr != nil {
var buildRef string
var ref string
var ebr *desktop.ErrorWithBuildRef
if errors.As(buildErr, &ebr) {
buildRef = ebr.Ref
ref = ebr.Ref
}
buildErr = controllererrors.WrapBuild(buildErr, b.ref, buildRef)
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 @@ -89,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 @@ -136,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 eb15c66

Please sign in to comment.