Skip to content

Commit 6df3a09

Browse files
authored
Merge pull request #3126 from jsternberg/controller-removal
controller: remove controller grpc service
2 parents e7be640 + 2f1be25 commit 6df3a09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+249
-17753
lines changed

commands/build.go

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@ type buildOptions struct {
104104
exportPush bool
105105
exportLoad bool
106106

107-
control.ControlOptions
108-
109107
invokeConfig *invokeConfig
110108
}
111109

112-
func (o *buildOptions) toControllerOptions() (*controllerapi.BuildOptions, error) {
110+
func (o *buildOptions) toControllerOptions() (*cbuild.Options, error) {
113111
var err error
114112

115113
buildArgs, err := listToMap(o.buildArgs, true)
@@ -122,7 +120,7 @@ func (o *buildOptions) toControllerOptions() (*controllerapi.BuildOptions, error
122120
return nil, err
123121
}
124122

125-
opts := controllerapi.BuildOptions{
123+
opts := cbuild.Options{
126124
Allow: o.allow,
127125
Annotations: o.annotations,
128126
BuildArgs: buildArgs,
@@ -420,23 +418,20 @@ func getImageID(resp map[string]string) string {
420418
return dgst
421419
}
422420

423-
func runBasicBuild(ctx context.Context, dockerCli command.Cli, opts *controllerapi.BuildOptions, printer *progress.Printer) (*client.SolveResponse, *build.Inputs, error) {
421+
func runBasicBuild(ctx context.Context, dockerCli command.Cli, opts *cbuild.Options, printer *progress.Printer) (*client.SolveResponse, *build.Inputs, error) {
424422
resp, res, dfmap, err := cbuild.RunBuild(ctx, dockerCli, opts, dockerCli.In(), printer, false)
425423
if res != nil {
426424
res.Done()
427425
}
428426
return resp, dfmap, err
429427
}
430428

431-
func runControllerBuild(ctx context.Context, dockerCli command.Cli, opts *controllerapi.BuildOptions, options buildOptions, printer *progress.Printer) (*client.SolveResponse, *build.Inputs, error) {
429+
func runControllerBuild(ctx context.Context, dockerCli command.Cli, opts *cbuild.Options, options buildOptions, printer *progress.Printer) (*client.SolveResponse, *build.Inputs, error) {
432430
if options.invokeConfig != nil && (options.dockerfileName == "-" || options.contextPath == "-") {
433431
// stdin must be usable for monitor
434432
return nil, nil, errors.Errorf("Dockerfile or context from stdin is not supported with invoke")
435433
}
436-
c, err := controller.NewController(ctx, options.ControlOptions, dockerCli, printer)
437-
if err != nil {
438-
return nil, nil, err
439-
}
434+
c := controller.NewController(ctx, dockerCli)
440435
defer func() {
441436
if err := c.Close(); err != nil {
442437
logrus.Warnf("failed to close server connection %v", err)
@@ -445,7 +440,7 @@ func runControllerBuild(ctx context.Context, dockerCli command.Cli, opts *contro
445440

446441
// NOTE: buildx server has the current working directory different from the client
447442
// so we need to resolve paths to abosolute ones in the client.
448-
opts, err = controllerapi.ResolveOptionPaths(opts)
443+
opts, err := cbuild.ResolveOptionPaths(opts)
449444
if err != nil {
450445
return nil, nil, err
451446
}
@@ -471,7 +466,7 @@ func runControllerBuild(ctx context.Context, dockerCli command.Cli, opts *contro
471466
})
472467
}
473468

474-
ref, resp, inputs, err = c.Build(ctx, opts, pr, printer)
469+
resp, inputs, err = c.Build(ctx, opts, pr, printer)
475470
if err != nil {
476471
var be *controllererrors.BuildError
477472
if errors.As(err, &be) {
@@ -515,8 +510,8 @@ func runControllerBuild(ctx context.Context, dockerCli command.Cli, opts *contro
515510
resp, retErr = monitorBuildResult.Resp, monitorBuildResult.Err
516511
}
517512
} else {
518-
if err := c.Disconnect(ctx, ref); err != nil {
519-
logrus.Warnf("disconnect error: %v", err)
513+
if err := c.Close(); err != nil {
514+
logrus.Warnf("close error: %v", err)
520515
}
521516
}
522517

@@ -653,14 +648,6 @@ func buildCmd(dockerCli command.Cli, rootOpts *rootOptions, debugConfig *debug.D
653648
flags.StringVar(&options.sbom, "sbom", "", `Shorthand for "--attest=type=sbom"`)
654649
flags.StringVar(&options.provenance, "provenance", "", `Shorthand for "--attest=type=provenance"`)
655650

656-
if confutil.IsExperimental() {
657-
// TODO: move this to debug command if needed
658-
flags.StringVar(&options.Root, "root", "", "Specify root directory of server to connect")
659-
flags.BoolVar(&options.Detach, "detach", false, "Detach buildx server (supported only on linux)")
660-
flags.StringVar(&options.ServerConfig, "server-config", "", "Specify buildx server config file (used only when launching new server)")
661-
cobrautil.MarkFlagsExperimental(flags, "root", "detach", "server-config")
662-
}
663-
664651
flags.StringVar(&options.callFunc, "call", "build", `Set method for evaluating build ("check", "outline", "targets")`)
665652
flags.VarPF(callAlias(&options.callFunc, "check"), "check", "", `Shorthand for "--call=check"`)
666653
flags.Lookup("check").NoOptDefVal = "true"
@@ -1017,12 +1004,12 @@ func (cfg *invokeConfig) needsDebug(retErr error) bool {
10171004
}
10181005
}
10191006

1020-
func (cfg *invokeConfig) runDebug(ctx context.Context, ref string, options *controllerapi.BuildOptions, c control.BuildxController, stdin io.ReadCloser, stdout io.WriteCloser, stderr console.File, progress *progress.Printer) (*monitor.MonitorBuildResult, error) {
1007+
func (cfg *invokeConfig) runDebug(ctx context.Context, ref string, options *cbuild.Options, c control.BuildxController, stdin io.ReadCloser, stdout io.WriteCloser, stderr console.File, progress *progress.Printer) (*monitor.MonitorBuildResult, error) {
10211008
con := console.Current()
10221009
if err := con.SetRaw(); err != nil {
10231010
// TODO: run disconnect in build command (on error case)
1024-
if err := c.Disconnect(ctx, ref); err != nil {
1025-
logrus.Warnf("disconnect error: %v", err)
1011+
if err := c.Close(); err != nil {
1012+
logrus.Warnf("close error: %v", err)
10261013
}
10271014
return nil, errors.Errorf("failed to configure terminal: %v", err)
10281015
}

commands/debug/root.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ package debug
33
import (
44
"context"
55
"os"
6-
"runtime"
76

87
"github.com/containerd/console"
98
"github.com/docker/buildx/controller"
10-
"github.com/docker/buildx/controller/control"
119
controllerapi "github.com/docker/buildx/controller/pb"
1210
"github.com/docker/buildx/monitor"
1311
"github.com/docker/buildx/util/cobrautil"
@@ -35,7 +33,6 @@ type DebuggableCmd interface {
3533
}
3634

3735
func RootCmd(dockerCli command.Cli, children ...DebuggableCmd) *cobra.Command {
38-
var controlOptions control.ControlOptions
3936
var progressMode string
4037
var options DebugConfig
4138

@@ -50,10 +47,7 @@ func RootCmd(dockerCli command.Cli, children ...DebuggableCmd) *cobra.Command {
5047
}
5148

5249
ctx := context.TODO()
53-
c, err := controller.NewController(ctx, controlOptions, dockerCli, printer)
54-
if err != nil {
55-
return err
56-
}
50+
c := controller.NewController(ctx, dockerCli)
5751
defer func() {
5852
if err := c.Close(); err != nil {
5953
logrus.Warnf("failed to close server connection %v", err)
@@ -76,13 +70,9 @@ func RootCmd(dockerCli command.Cli, children ...DebuggableCmd) *cobra.Command {
7670
flags := cmd.Flags()
7771
flags.StringVar(&options.InvokeFlag, "invoke", "", "Launch a monitor with executing specified command")
7872
flags.StringVar(&options.OnFlag, "on", "error", "When to launch the monitor ([always, error])")
79-
80-
flags.StringVar(&controlOptions.Root, "root", "", "Specify root directory of server to connect for the monitor")
81-
flags.BoolVar(&controlOptions.Detach, "detach", runtime.GOOS == "linux", "Detach buildx server for the monitor (supported only on linux)")
82-
flags.StringVar(&controlOptions.ServerConfig, "server-config", "", "Specify buildx server config file for the monitor (used only when launching new server)")
8373
flags.StringVar(&progressMode, "progress", "auto", `Set type of progress output ("auto", "plain", "tty", "rawjson") for the monitor. Use plain to show container output`)
8474

85-
cobrautil.MarkFlagsExperimental(flags, "invoke", "on", "root", "detach", "server-config")
75+
cobrautil.MarkFlagsExperimental(flags, "invoke", "on")
8676

8777
for _, c := range children {
8878
cmd.AddCommand(c.NewDebugger(&options))

commands/root.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
debugcmd "github.com/docker/buildx/commands/debug"
88
historycmd "github.com/docker/buildx/commands/history"
99
imagetoolscmd "github.com/docker/buildx/commands/imagetools"
10-
"github.com/docker/buildx/controller/remote"
1110
"github.com/docker/buildx/util/cobrautil/completion"
1211
"github.com/docker/buildx/util/confutil"
1312
"github.com/docker/buildx/util/logutil"
@@ -124,7 +123,6 @@ func addCommands(cmd *cobra.Command, opts *rootOptions, dockerCli command.Cli) {
124123
cmd.AddCommand(debugcmd.RootCmd(dockerCli,
125124
newDebuggableBuild(dockerCli, opts),
126125
))
127-
remote.AddControllerCommands(cmd, dockerCli)
128126
}
129127

130128
cmd.RegisterFlagCompletionFunc( //nolint:errcheck

controller/build/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const defaultTargetName = "default"
3434
// NOTE: When an error happens during the build and this function acquires the debuggable *build.ResultHandle,
3535
// this function returns it in addition to the error (i.e. it does "return nil, res, err"). The caller can
3636
// inspect the result and debug the cause of that error.
37-
func RunBuild(ctx context.Context, dockerCli command.Cli, in *controllerapi.BuildOptions, inStream io.Reader, progress progress.Writer, generateResult bool) (*client.SolveResponse, *build.ResultHandle, *build.Inputs, error) {
37+
func RunBuild(ctx context.Context, dockerCli command.Cli, in *Options, inStream io.Reader, progress progress.Writer, generateResult bool) (*client.SolveResponse, *build.ResultHandle, *build.Inputs, error) {
3838
if in.NoCache && len(in.NoCacheFilter) > 0 {
3939
return nil, nil, nil, errors.Errorf("--no-cache and --no-cache-filter cannot currently be used together")
4040
}
Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,52 @@
1-
package pb
1+
package build
22

33
import (
44
"path/filepath"
55
"strings"
66

7+
"github.com/docker/buildx/controller/pb"
8+
sourcepolicy "github.com/moby/buildkit/sourcepolicy/pb"
79
"github.com/moby/buildkit/util/gitutil"
810
)
911

12+
type Options struct {
13+
ContextPath string
14+
DockerfileName string
15+
CallFunc *pb.CallFunc
16+
NamedContexts map[string]string
17+
Allow []string
18+
Attests []*pb.Attest
19+
BuildArgs map[string]string
20+
CacheFrom []*pb.CacheOptionsEntry
21+
CacheTo []*pb.CacheOptionsEntry
22+
CgroupParent string
23+
Exports []*pb.ExportEntry
24+
ExtraHosts []string
25+
Labels map[string]string
26+
NetworkMode string
27+
NoCacheFilter []string
28+
Platforms []string
29+
Secrets []*pb.Secret
30+
ShmSize int64
31+
SSH []*pb.SSH
32+
Tags []string
33+
Target string
34+
Ulimits *pb.UlimitOpt
35+
Builder string
36+
NoCache bool
37+
Pull bool
38+
ExportPush bool
39+
ExportLoad bool
40+
SourcePolicy *sourcepolicy.Policy
41+
Ref string
42+
GroupRef string
43+
Annotations []string
44+
ProvenanceResponseMode string
45+
}
46+
1047
// ResolveOptionPaths resolves all paths contained in BuildOptions
1148
// and replaces them to absolute paths.
12-
func ResolveOptionPaths(options *BuildOptions) (_ *BuildOptions, err error) {
49+
func ResolveOptionPaths(options *Options) (_ *Options, err error) {
1350
localContext := false
1451
if options.ContextPath != "" && options.ContextPath != "-" {
1552
if !isRemoteURL(options.ContextPath) {
@@ -56,7 +93,7 @@ func ResolveOptionPaths(options *BuildOptions) (_ *BuildOptions, err error) {
5693
}
5794
options.NamedContexts = contexts
5895

59-
var cacheFrom []*CacheOptionsEntry
96+
var cacheFrom []*pb.CacheOptionsEntry
6097
for _, co := range options.CacheFrom {
6198
switch co.Type {
6299
case "local":
@@ -87,7 +124,7 @@ func ResolveOptionPaths(options *BuildOptions) (_ *BuildOptions, err error) {
87124
}
88125
options.CacheFrom = cacheFrom
89126

90-
var cacheTo []*CacheOptionsEntry
127+
var cacheTo []*pb.CacheOptionsEntry
91128
for _, co := range options.CacheTo {
92129
switch co.Type {
93130
case "local":
@@ -117,7 +154,7 @@ func ResolveOptionPaths(options *BuildOptions) (_ *BuildOptions, err error) {
117154
}
118155
}
119156
options.CacheTo = cacheTo
120-
var exports []*ExportEntry
157+
var exports []*pb.ExportEntry
121158
for _, e := range options.Exports {
122159
if e.Destination != "" && e.Destination != "-" {
123160
e.Destination, err = filepath.Abs(e.Destination)
@@ -129,7 +166,7 @@ func ResolveOptionPaths(options *BuildOptions) (_ *BuildOptions, err error) {
129166
}
130167
options.Exports = exports
131168

132-
var secrets []*Secret
169+
var secrets []*pb.Secret
133170
for _, s := range options.Secrets {
134171
if s.FilePath != "" {
135172
s.FilePath, err = filepath.Abs(s.FilePath)
@@ -141,7 +178,7 @@ func ResolveOptionPaths(options *BuildOptions) (_ *BuildOptions, err error) {
141178
}
142179
options.Secrets = secrets
143180

144-
var ssh []*SSH
181+
var ssh []*pb.SSH
145182
for _, s := range options.SSH {
146183
var ps []string
147184
for _, pt := range s.Paths {

0 commit comments

Comments
 (0)