Skip to content

Commit 1d7cda1

Browse files
committed
controller: remove remaining parts of the controller
Removes all references to the controller and moves the remaining sections of code to other packages. Processes has been moved to monitor where it is used and the data structs have been removed so buildflags is used directly. The controller build function has been moved to the commands package. Signed-off-by: Jonathan A. Sternberg <[email protected]>
1 parent 60b1eda commit 1d7cda1

36 files changed

+659
-1502
lines changed

.github/labeler.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ area/cli:
4848
- cmd/**
4949
- commands/**
5050

51-
# Add 'area/controller' label to changes in the controller
52-
area/controller:
53-
- changed-files:
54-
- any-glob-to-any-file: 'controller/**'
55-
5651
# Add 'area/docs' label to markdown files in the docs folder
5752
area/docs:
5853
- changed-files:

PROJECT.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ Area or component of the project affected. Please note that the table below may
7979
| `area/checks` | Any | `checks` |
8080
| `area/ci` | Any | Project CI |
8181
| `area/cli` | Any | `cli` |
82-
| `area/controller` | Any | `controller` |
8382
| `area/debug` | Any | `debug` |
8483
| `area/dependencies` | Any | Project dependencies |
8584
| `area/dockerfile` | Any | `dockerfile` |

bake/bake.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
composecli "github.com/compose-spec/compose-go/v2/cli"
2020
"github.com/docker/buildx/bake/hclparser"
2121
"github.com/docker/buildx/build"
22-
controllerapi "github.com/docker/buildx/controller/pb"
2322
"github.com/docker/buildx/util/buildflags"
2423
"github.com/docker/buildx/util/platformutil"
2524
"github.com/docker/buildx/util/progress"
@@ -1439,20 +1438,19 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
14391438
})
14401439
}
14411440
}
1442-
secrets = secrets.Normalize()
1443-
bo.SecretSpecs = secrets.ToPB()
1444-
secretAttachment, err := controllerapi.CreateSecrets(bo.SecretSpecs)
1441+
bo.SecretSpecs = secrets.Normalize()
1442+
secretAttachment, err := build.CreateSecrets(bo.SecretSpecs)
14451443
if err != nil {
14461444
return nil, err
14471445
}
14481446
bo.Session = append(bo.Session, secretAttachment)
14491447

1450-
bo.SSHSpecs = t.SSH.ToPB()
1448+
bo.SSHSpecs = t.SSH
14511449
if len(bo.SSHSpecs) == 0 && buildflags.IsGitSSH(bi.ContextPath) || (inp != nil && buildflags.IsGitSSH(inp.URL)) {
1452-
bo.SSHSpecs = []*controllerapi.SSH{{ID: "default"}}
1450+
bo.SSHSpecs = []*buildflags.SSH{{ID: "default"}}
14531451
}
14541452

1455-
sshAttachment, err := controllerapi.CreateSSH(bo.SSHSpecs)
1453+
sshAttachment, err := build.CreateSSH(bo.SSHSpecs)
14561454
if err != nil {
14571455
return nil, err
14581456
}
@@ -1469,13 +1467,13 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
14691467
}
14701468

14711469
if t.CacheFrom != nil {
1472-
bo.CacheFrom = controllerapi.CreateCaches(t.CacheFrom.ToPB())
1470+
bo.CacheFrom = build.CreateCaches(t.CacheFrom)
14731471
}
14741472
if t.CacheTo != nil {
1475-
bo.CacheTo = controllerapi.CreateCaches(t.CacheTo.ToPB())
1473+
bo.CacheTo = build.CreateCaches(t.CacheTo)
14761474
}
14771475

1478-
bo.Exports, bo.ExportsLocalPathsTemporary, err = controllerapi.CreateExports(t.Outputs.ToPB())
1476+
bo.Exports, bo.ExportsLocalPathsTemporary, err = build.CreateExports(t.Outputs)
14791477
if err != nil {
14801478
return nil, err
14811479
}
@@ -1490,7 +1488,7 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
14901488
}
14911489
}
14921490

1493-
bo.Attests = controllerapi.CreateAttestations(t.Attest.ToPB())
1491+
bo.Attests = t.Attest.ToMap()
14941492

14951493
bo.SourcePolicy, err = build.ReadSourcePolicy()
14961494
if err != nil {

bake/entitlements_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"testing"
99

1010
"github.com/docker/buildx/build"
11-
"github.com/docker/buildx/controller/pb"
11+
"github.com/docker/buildx/util/buildflags"
1212
"github.com/docker/buildx/util/osutil"
1313
"github.com/moby/buildkit/client/llb"
1414
"github.com/moby/buildkit/util/entitlements"
@@ -264,7 +264,7 @@ func TestValidateEntitlements(t *testing.T) {
264264
{
265265
name: "SSHMissing",
266266
opt: build.Options{
267-
SSHSpecs: []*pb.SSH{
267+
SSHSpecs: []*buildflags.SSH{
268268
{
269269
ID: "test",
270270
},
@@ -296,7 +296,7 @@ func TestValidateEntitlements(t *testing.T) {
296296
{
297297
name: "SecretFromSubFile",
298298
opt: build.Options{
299-
SecretSpecs: []*pb.Secret{
299+
SecretSpecs: []*buildflags.Secret{
300300
{
301301
FilePath: filepath.Join(dir1, "subfile"),
302302
},
@@ -309,7 +309,7 @@ func TestValidateEntitlements(t *testing.T) {
309309
{
310310
name: "SecretFromEscapeLink",
311311
opt: build.Options{
312-
SecretSpecs: []*pb.Secret{
312+
SecretSpecs: []*buildflags.Secret{
313313
{
314314
FilePath: escapeLink,
315315
},
@@ -325,7 +325,7 @@ func TestValidateEntitlements(t *testing.T) {
325325
{
326326
name: "SecretFromEscapeLinkAllowRoot",
327327
opt: build.Options{
328-
SecretSpecs: []*pb.Secret{
328+
SecretSpecs: []*buildflags.Secret{
329329
{
330330
FilePath: escapeLink,
331331
},
@@ -352,7 +352,7 @@ func TestValidateEntitlements(t *testing.T) {
352352
{
353353
name: "SecretFromEscapeLinkAllowAny",
354354
opt: build.Options{
355-
SecretSpecs: []*pb.Secret{
355+
SecretSpecs: []*buildflags.Secret{
356356
{
357357
FilePath: escapeLink,
358358
},

bake/remote.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"os"
88
"strings"
99

10+
"github.com/docker/buildx/build"
1011
"github.com/docker/buildx/builder"
11-
controllerapi "github.com/docker/buildx/controller/pb"
1212
"github.com/docker/buildx/driver"
13+
"github.com/docker/buildx/util/buildflags"
1314
"github.com/docker/buildx/util/progress"
1415
"github.com/docker/go-units"
1516
"github.com/moby/buildkit/client"
@@ -33,27 +34,27 @@ func ReadRemoteFiles(ctx context.Context, nodes []builder.Node, url string, name
3334

3435
st, ok := dockerui.DetectGitContext(url, false)
3536
if ok {
36-
if ssh, err := controllerapi.CreateSSH([]*controllerapi.SSH{{
37+
if ssh, err := build.CreateSSH([]*buildflags.SSH{{
3738
ID: "default",
3839
Paths: strings.Split(os.Getenv("BUILDX_BAKE_GIT_SSH"), ","),
3940
}}); err == nil {
4041
sessions = append(sessions, ssh)
4142
}
42-
var gitAuthSecrets []*controllerapi.Secret
43+
var gitAuthSecrets []*buildflags.Secret
4344
if _, ok := os.LookupEnv("BUILDX_BAKE_GIT_AUTH_TOKEN"); ok {
44-
gitAuthSecrets = append(gitAuthSecrets, &controllerapi.Secret{
45+
gitAuthSecrets = append(gitAuthSecrets, &buildflags.Secret{
4546
ID: llb.GitAuthTokenKey,
4647
Env: "BUILDX_BAKE_GIT_AUTH_TOKEN",
4748
})
4849
}
4950
if _, ok := os.LookupEnv("BUILDX_BAKE_GIT_AUTH_HEADER"); ok {
50-
gitAuthSecrets = append(gitAuthSecrets, &controllerapi.Secret{
51+
gitAuthSecrets = append(gitAuthSecrets, &buildflags.Secret{
5152
ID: llb.GitAuthHeaderKey,
5253
Env: "BUILDX_BAKE_GIT_AUTH_HEADER",
5354
})
5455
}
5556
if len(gitAuthSecrets) > 0 {
56-
if secrets, err := controllerapi.CreateSecrets(gitAuthSecrets); err == nil {
57+
if secrets, err := build.CreateSecrets(gitAuthSecrets); err == nil {
5758
sessions = append(sessions, secrets)
5859
}
5960
}

build/build.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
"github.com/containerd/containerd/v2/core/images"
2020
"github.com/distribution/reference"
2121
"github.com/docker/buildx/builder"
22-
controllerapi "github.com/docker/buildx/controller/pb"
2322
"github.com/docker/buildx/driver"
23+
"github.com/docker/buildx/util/buildflags"
2424
"github.com/docker/buildx/util/confutil"
2525
"github.com/docker/buildx/util/desktop"
2626
"github.com/docker/buildx/util/dockerutil"
@@ -78,8 +78,8 @@ type Options struct {
7878
NoCacheFilter []string
7979
Platforms []ocispecs.Platform
8080
Pull bool
81-
SecretSpecs []*controllerapi.Secret
82-
SSHSpecs []*controllerapi.SSH
81+
SecretSpecs buildflags.Secrets
82+
SSHSpecs []*buildflags.SSH
8383
ShmSize opts.MemBytes
8484
Tags []string
8585
Target string

build/invoke.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,41 @@ import (
88
"sync/atomic"
99
"syscall"
1010

11-
controllerapi "github.com/docker/buildx/controller/pb"
1211
gateway "github.com/moby/buildkit/frontend/gateway/client"
1312
"github.com/pkg/errors"
1413
"github.com/sirupsen/logrus"
1514
)
1615

16+
type InvokeConfig struct {
17+
Entrypoint []string
18+
Cmd []string
19+
NoCmd bool
20+
Env []string
21+
User string
22+
NoUser bool
23+
Cwd string
24+
NoCwd bool
25+
Tty bool
26+
Rollback bool
27+
Initial bool
28+
SuspendOn SuspendOn
29+
}
30+
31+
func (cfg *InvokeConfig) NeedsDebug(err error) bool {
32+
return cfg.SuspendOn.DebugEnabled(err)
33+
}
34+
35+
type SuspendOn int
36+
37+
const (
38+
SuspendError SuspendOn = iota
39+
SuspendAlways
40+
)
41+
42+
func (s SuspendOn) DebugEnabled(err error) bool {
43+
return err != nil || s == SuspendAlways
44+
}
45+
1746
type Container struct {
1847
cancelOnce sync.Once
1948
containerCancel func(error)
@@ -24,7 +53,7 @@ type Container struct {
2453
resultCtx *ResultHandle
2554
}
2655

27-
func NewContainer(ctx context.Context, resultCtx *ResultHandle, cfg *controllerapi.InvokeConfig) (*Container, error) {
56+
func NewContainer(ctx context.Context, resultCtx *ResultHandle, cfg *InvokeConfig) (*Container, error) {
2857
mainCtx := ctx
2958

3059
ctrCh := make(chan *Container)
@@ -97,7 +126,7 @@ func (c *Container) markUnavailable() {
97126
c.isUnavailable.Store(true)
98127
}
99128

100-
func (c *Container) Exec(ctx context.Context, cfg *controllerapi.InvokeConfig, stdin io.ReadCloser, stdout io.WriteCloser, stderr io.WriteCloser) error {
129+
func (c *Container) Exec(ctx context.Context, cfg *InvokeConfig, stdin io.ReadCloser, stdout io.WriteCloser, stderr io.WriteCloser) error {
101130
if isInit := c.initStarted.CompareAndSwap(false, true); isInit {
102131
defer func() {
103132
// container can't be used after init exits
@@ -112,7 +141,7 @@ func (c *Container) Exec(ctx context.Context, cfg *controllerapi.InvokeConfig, s
112141
return err
113142
}
114143

115-
func exec(ctx context.Context, resultCtx *ResultHandle, cfg *controllerapi.InvokeConfig, ctr gateway.Container, stdin io.ReadCloser, stdout io.WriteCloser, stderr io.WriteCloser) error {
144+
func exec(ctx context.Context, resultCtx *ResultHandle, cfg *InvokeConfig, ctr gateway.Container, stdin io.ReadCloser, stdout io.WriteCloser, stderr io.WriteCloser) error {
116145
processCfg, err := resultCtx.getProcessConfig(cfg, stdin, stdout, stderr)
117146
if err != nil {
118147
return err

0 commit comments

Comments
 (0)