Skip to content

Commit a352c85

Browse files
committed
controller: remove buildx controller
Removes the buildx controller and all code associated with it including the debug and monitor commands. Some of the controller code is kept around because the generated structs are being used by some of the code, but those will be refactored into normal Go structs in a future change.
1 parent eb74b48 commit a352c85

36 files changed

+2807
-16604
lines changed

build/invoke.go

-138
This file was deleted.

build/result.go

-219
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@ package build
33
import (
44
"context"
55
_ "crypto/sha256" // ensure digests can be computed
6-
"encoding/json"
7-
"io"
86
"sync"
97

10-
controllerapi "github.com/docker/buildx/controller/pb"
118
"github.com/moby/buildkit/client"
12-
"github.com/moby/buildkit/exporter/containerimage/exptypes"
139
gateway "github.com/moby/buildkit/frontend/gateway/client"
1410
"github.com/moby/buildkit/solver/errdefs"
1511
"github.com/moby/buildkit/solver/pb"
1612
"github.com/moby/buildkit/solver/result"
17-
specs "github.com/opencontainers/image-spec/specs-go/v1"
1813
"github.com/pkg/errors"
19-
"github.com/sirupsen/logrus"
2014
"golang.org/x/sync/errgroup"
2115
)
2216

@@ -280,216 +274,3 @@ func (r *ResultHandle) Done() {
280274
<-r.gwCtx.Done()
281275
})
282276
}
283-
284-
func (r *ResultHandle) registerCleanup(f func()) {
285-
r.cleanupsMu.Lock()
286-
r.cleanups = append(r.cleanups, f)
287-
r.cleanupsMu.Unlock()
288-
}
289-
290-
func (r *ResultHandle) build(buildFunc gateway.BuildFunc) (err error) {
291-
_, err = buildFunc(r.gwCtx, r.gwClient)
292-
return err
293-
}
294-
295-
func (r *ResultHandle) getContainerConfig(cfg *controllerapi.InvokeConfig) (containerCfg gateway.NewContainerRequest, _ error) {
296-
if r.res != nil && r.solveErr == nil {
297-
logrus.Debugf("creating container from successful build")
298-
ccfg, err := containerConfigFromResult(r.res, cfg)
299-
if err != nil {
300-
return containerCfg, err
301-
}
302-
containerCfg = *ccfg
303-
} else {
304-
logrus.Debugf("creating container from failed build %+v", cfg)
305-
ccfg, err := containerConfigFromError(r.solveErr, cfg)
306-
if err != nil {
307-
return containerCfg, errors.Wrapf(err, "no result nor error is available")
308-
}
309-
containerCfg = *ccfg
310-
}
311-
return containerCfg, nil
312-
}
313-
314-
func (r *ResultHandle) getProcessConfig(cfg *controllerapi.InvokeConfig, stdin io.ReadCloser, stdout io.WriteCloser, stderr io.WriteCloser) (_ gateway.StartRequest, err error) {
315-
processCfg := newStartRequest(stdin, stdout, stderr)
316-
if r.res != nil && r.solveErr == nil {
317-
logrus.Debugf("creating container from successful build")
318-
if err := populateProcessConfigFromResult(&processCfg, r.res, cfg); err != nil {
319-
return processCfg, err
320-
}
321-
} else {
322-
logrus.Debugf("creating container from failed build %+v", cfg)
323-
if err := populateProcessConfigFromError(&processCfg, r.solveErr, cfg); err != nil {
324-
return processCfg, err
325-
}
326-
}
327-
return processCfg, nil
328-
}
329-
330-
func containerConfigFromResult(res *gateway.Result, cfg *controllerapi.InvokeConfig) (*gateway.NewContainerRequest, error) {
331-
if cfg.Initial {
332-
return nil, errors.Errorf("starting from the container from the initial state of the step is supported only on the failed steps")
333-
}
334-
335-
ps, err := exptypes.ParsePlatforms(res.Metadata)
336-
if err != nil {
337-
return nil, err
338-
}
339-
ref, ok := res.FindRef(ps.Platforms[0].ID)
340-
if !ok {
341-
return nil, errors.Errorf("no reference found")
342-
}
343-
344-
return &gateway.NewContainerRequest{
345-
Mounts: []gateway.Mount{
346-
{
347-
Dest: "/",
348-
MountType: pb.MountType_BIND,
349-
Ref: ref,
350-
},
351-
},
352-
}, nil
353-
}
354-
355-
func populateProcessConfigFromResult(req *gateway.StartRequest, res *gateway.Result, cfg *controllerapi.InvokeConfig) error {
356-
imgData := res.Metadata[exptypes.ExporterImageConfigKey]
357-
var img *specs.Image
358-
if len(imgData) > 0 {
359-
img = &specs.Image{}
360-
if err := json.Unmarshal(imgData, img); err != nil {
361-
return err
362-
}
363-
}
364-
365-
user := ""
366-
if !cfg.NoUser {
367-
user = cfg.User
368-
} else if img != nil {
369-
user = img.Config.User
370-
}
371-
372-
cwd := ""
373-
if !cfg.NoCwd {
374-
cwd = cfg.Cwd
375-
} else if img != nil {
376-
cwd = img.Config.WorkingDir
377-
}
378-
379-
env := []string{}
380-
if img != nil {
381-
env = append(env, img.Config.Env...)
382-
}
383-
env = append(env, cfg.Env...)
384-
385-
args := []string{}
386-
if cfg.Entrypoint != nil {
387-
args = append(args, cfg.Entrypoint...)
388-
} else if img != nil {
389-
args = append(args, img.Config.Entrypoint...)
390-
}
391-
if !cfg.NoCmd {
392-
args = append(args, cfg.Cmd...)
393-
} else if img != nil {
394-
args = append(args, img.Config.Cmd...)
395-
}
396-
397-
req.Args = args
398-
req.Env = env
399-
req.User = user
400-
req.Cwd = cwd
401-
req.Tty = cfg.Tty
402-
403-
return nil
404-
}
405-
406-
func containerConfigFromError(solveErr *errdefs.SolveError, cfg *controllerapi.InvokeConfig) (*gateway.NewContainerRequest, error) {
407-
exec, err := execOpFromError(solveErr)
408-
if err != nil {
409-
return nil, err
410-
}
411-
var mounts []gateway.Mount
412-
for i, mnt := range exec.Mounts {
413-
rid := solveErr.Solve.MountIDs[i]
414-
if cfg.Initial {
415-
rid = solveErr.Solve.InputIDs[i]
416-
}
417-
mounts = append(mounts, gateway.Mount{
418-
Selector: mnt.Selector,
419-
Dest: mnt.Dest,
420-
ResultID: rid,
421-
Readonly: mnt.Readonly,
422-
MountType: mnt.MountType,
423-
CacheOpt: mnt.CacheOpt,
424-
SecretOpt: mnt.SecretOpt,
425-
SSHOpt: mnt.SSHOpt,
426-
})
427-
}
428-
return &gateway.NewContainerRequest{
429-
Mounts: mounts,
430-
NetMode: exec.Network,
431-
}, nil
432-
}
433-
434-
func populateProcessConfigFromError(req *gateway.StartRequest, solveErr *errdefs.SolveError, cfg *controllerapi.InvokeConfig) error {
435-
exec, err := execOpFromError(solveErr)
436-
if err != nil {
437-
return err
438-
}
439-
meta := exec.Meta
440-
user := ""
441-
if !cfg.NoUser {
442-
user = cfg.User
443-
} else {
444-
user = meta.User
445-
}
446-
447-
cwd := ""
448-
if !cfg.NoCwd {
449-
cwd = cfg.Cwd
450-
} else {
451-
cwd = meta.Cwd
452-
}
453-
454-
env := append(meta.Env, cfg.Env...)
455-
456-
args := []string{}
457-
if cfg.Entrypoint != nil {
458-
args = append(args, cfg.Entrypoint...)
459-
}
460-
if cfg.Cmd != nil {
461-
args = append(args, cfg.Cmd...)
462-
}
463-
if len(args) == 0 {
464-
args = meta.Args
465-
}
466-
467-
req.Args = args
468-
req.Env = env
469-
req.User = user
470-
req.Cwd = cwd
471-
req.Tty = cfg.Tty
472-
473-
return nil
474-
}
475-
476-
func execOpFromError(solveErr *errdefs.SolveError) (*pb.ExecOp, error) {
477-
if solveErr == nil {
478-
return nil, errors.Errorf("no error is available")
479-
}
480-
switch op := solveErr.Solve.Op.GetOp().(type) {
481-
case *pb.Op_Exec:
482-
return op.Exec, nil
483-
default:
484-
return nil, errors.Errorf("invoke: unsupported error type")
485-
}
486-
// TODO: support other ops
487-
}
488-
489-
func newStartRequest(stdin io.ReadCloser, stdout io.WriteCloser, stderr io.WriteCloser) gateway.StartRequest {
490-
return gateway.StartRequest{
491-
Stdin: stdin,
492-
Stdout: stdout,
493-
Stderr: stderr,
494-
}
495-
}

cmd/buildx/main.go

-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"path/filepath"
88

99
"github.com/docker/buildx/commands"
10-
controllererrors "github.com/docker/buildx/controller/errdefs"
1110
"github.com/docker/buildx/util/desktop"
1211
"github.com/docker/buildx/version"
1312
"github.com/docker/cli/cli"
@@ -112,11 +111,6 @@ func main() {
112111
var ebr *desktop.ErrorWithBuildRef
113112
if errors.As(err, &ebr) {
114113
ebr.Print(cmd.Err())
115-
} else {
116-
var be *controllererrors.BuildError
117-
if errors.As(err, &be) {
118-
be.PrintBuildDetails(cmd.Err())
119-
}
120114
}
121115

122116
os.Exit(1)

0 commit comments

Comments
 (0)